Skip to content

Instantly share code, notes, and snippets.

View dfritschy's full-sized avatar

Donat Fritschy dfritschy

View GitHub Profile
@dfritschy
dfritschy / content.macro.html.twig
Created November 14, 2014 13:55
TWIG macro to check wether a field is empty or not defined
{# check if a field is not defined or empty #}
{% macro is_empty(content, field_name) %}{% spaceless %}
{{ content.fields[field_name] is not defined or ez_is_field_empty(content, field_name) }}
{% endspaceless %}{% endmacro %}
@dfritschy
dfritschy / purge_image_cache.sh
Created June 18, 2015 13:21
Run this script when parameters in image.yml are changed as eZ 2014.11 does not purge invalid variations automatically
#!/bin/sh
# purge image variations
#
# run this script when parameters in image.yml are changed as eZ 2014.11 does not purge invalid
# variations automatically
readonly variations="reference
article_full
article_line
@dfritschy
dfritschy / CrossDomainRouter.php
Last active October 25, 2022 20:52
CrossDomainRouter for eZ PlatformIn a multi-site setup, there are usually different domains mapped to different branches in the content tree. In such a use case you will frequently find the need to share content across different siteaccesses.This is no problem with multiple locations, but when generating an URL Alias to a (main) location in anot…
<?php
namespace Webmanufaktur\MySite\Routing;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use eZ\Publish\Core\MVC\Symfony\Routing\Generator\UrlAliasGenerator;
use eZ\Publish\Core\SignalSlot\Repository;
use Symfony\Cmf\Component\Routing\ChainedRouterInterface;
use Symfony\Component\HttpFoundation\Request;
@dfritschy
dfritschy / eztagscloud.php
Last active May 30, 2016 09:22
q&d fix for eztagscloud returning tags in main language instead of translation
/**
* Returns the tag cloud for specified parameters using eZ Publish database
*
* @param array $params
*
* @return array
*/
private function tagCloud( $params )
{
$parentNodeID = 0;
@dfritschy
dfritschy / DumpRoutes.php
Created December 4, 2018 17:54
Dump Symfony Routes to yaml File
/**
* Dump Routes to YAML File.
*/
public function dumpRoutes()
{
/** @var $router \Symfony\Component\Routing\Router */
$router = $this->container->get('router');
$collection = $router->getRouteCollection();
$allRoutes = $collection->all();
array_multisort($allRoutes);
@dfritschy
dfritschy / jsondate.go
Last active January 28, 2022 14:19
Go time.Time type with custom format for UnmarshalJSON and MarshalJSON
// JsonDate reflects the date format "yyyy-mm-dd" used in the API and the calendar component in the frontend.
type JsonDate time.Time
// UnmarshalJSON parses json dates
func (j *JsonDate) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
t, err := time.Parse("2006-01-02", s)
if err != nil {
return err
}