Skip to content

Instantly share code, notes, and snippets.

View dfritschy's full-sized avatar

Donat Fritschy dfritschy

View GitHub Profile
@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 / 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 / Build download link for a file field
Created November 7, 2013 17:46
This snippet builds the download link for a file field (formerly attribute) of the current content object
@dfritschy
dfritschy / file.html.twig
Created October 18, 2013 14:05
TWIG embed template for files, corresponding override rules
{# Embed File View
{{ ez_render_field( content, 'file') }} would be easier, but renders the file name instead of the object name
#}
<div class="content-view-embed">
{% if content.fields['file'] is defined %}
{% set uri = 'content/download/' ~ content.contentInfo.id ~ '/' ~ content.getField('file').id
~ '/version/' ~ content.contentInfo.currentVersionNo ~ "/file/"
~ content.getField('file').value.fileName|escape( 'url' ) %}
@dfritschy
dfritschy / file.tpl
Created October 18, 2013 09:18
for Jérôme: site_xxx/design/xxx/override/templates/embed
{* File - List embed view *}
<div class="content-view-embed">
<div class="class-file">
{if $object.data_map.file.has_content}
{def $file = $object.data_map.file}
<div class="content-body attribute-{$file.content.mime_type_part}">
<a href={concat("content/download/", $file.contentobject_id, "/", $file.id, "/file/", $file.content.original_filename)|ezurl}>{$object.name|wash("xhtml")}</a> {*$file.content.filesize|si(byte)*}
</div>
{undef $file}
{else}
@dfritschy
dfritschy / override.yml
Created October 18, 2013 09:15
for Jérôme
# We explicitly prepend config for "ezpublish" namespace in service container extension,
# so no need to repeat it here
system:
drucknatuer_user:
location_view:
full:
full_ps_produkt:
template: WebmanufakturSiteDruckformBundle:full:ps_produkt.html.twig
match:
Identifier\ContentType: ps_produkt
@dfritschy
dfritschy / config.yml
Created October 18, 2013 09:14
for Jérôme...
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
esi: ~
translator: { fallback: %locale_fallback% }
# The secret parameter is used to generate CSRF tokens
secret: %secret%
router:
@dfritschy
dfritschy / MyController.php
Created September 17, 2013 14:42
eZ Publish 5: Is this a viable pattern for handling sub-items of a content object, for example children of a folder?
/**
* Renders sub-items of the current location
*
* TODO: add content type filtering, and possibly more
* TODO: add template to be used for rendering
*
* @param int $locationId
* @return \Symfony\Component\HttpFoundation\Response
*/
public function subItemsAction( $locationId )