Skip to content

Instantly share code, notes, and snippets.

View dfritschy's full-sized avatar

Donat Fritschy dfritschy

View GitHub Profile
@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
}
@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 / 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 / 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 / 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 / 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 / SearchController.php
Created November 14, 2014 10:15
Full Text Search in eZ Publish 5 using a legacy closure
$searchText = $request->query->get('SearchText');
$sort = array( 'modified' => 'false' );
$contentTypeIdenfiers = array( 31 );
$searchResult = $this->getLegacyKernel()->runCallback(
function () use ( $searchText, $sort, $contentTypeIdenfiers )
{
// eZFunctionHandler::execute is the equivalent for a legacy template fetch function
// The following is the same than fetch( 'content', 'search', hash(...) )
return eZFunctionHandler::execute(
@dfritschy
dfritschy / DefaultController.php
Created May 28, 2014 12:02
A sample frontpage controller which picks a random banner image from a list of related objects
public function indexAction( $locationId = 2 )
{
$response = new Response;
$response = $this->cacheResponse( $response, $locationId, 10 );
/** @var $repository \eZ\Publish\API\Repository\Repository */
$repository = $this->getRepository();
$contentService = $repository->getContentService();
$locationService = $repository->getLocationService();
@dfritschy
dfritschy / gist:9600062
Created March 17, 2014 14:21
jvEmbed Youtube Custom Tag result
<div class="jvembed jvembed-youtube"><iframe width="560" height="315" src="//www.youtube.com/embed/MfOnq-zXXBw" frameborder="0" allowfullscreen=""></iframe></div>
@dfritschy
dfritschy / anonymous_user.yml
Created March 6, 2014 14:20
eZ Publish Configuration with different Anonymous Users
ezpublish:
...
system:
...
ftswps_user__com:
anonymous_user_id: 503
languages:
- eng-US
ftswps_user__uk:
anonymous_user_id: 504