Skip to content

Commit

Permalink
Merge pull request ezsystems#1104 from ezsystems/fix-EZP-23513-richte…
Browse files Browse the repository at this point in the history
…xt-linked-embeds-2

Fix EZP-23513: embed rendering (RichText)
  • Loading branch information
andrerom committed Dec 16, 2014
2 parents 0762a75 + fe7d930 commit ef3e033
Show file tree
Hide file tree
Showing 68 changed files with 2,046 additions and 306 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* File containing the RichTextEzxmlInputConverterPass class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/

namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Compiler pass for the RichText EZXML input Aggregate converter tags.
* @see \eZ\Publish\Core\FieldType\RichText\Converter\Aggregate
*/
class RichTextEzxmlInputConverterPass implements CompilerPassInterface
{
public function process( ContainerBuilder $container )
{
if ( !$container->hasDefinition( 'ezpublish.fieldType.ezrichtext.converter.input.ezxml' ) )
{
return;
}

$ezxmlInputConverterDefinition = $container->getDefinition( 'ezpublish.fieldType.ezrichtext.converter.input.ezxml' );
$taggedServiceIds = $container->findTaggedServiceIds( 'ezpublish.ezrichtext.converter.input.ezxml' );

$convertersByPriority = array();
foreach ( $taggedServiceIds as $id => $tags )
{
foreach ( $tags as $tag )
{
$priority = isset( $tag['priority'] ) ? (int)$tag['priority'] : 0;
$convertersByPriority[$priority][] = new Reference( $id );
}
}

if ( count( $convertersByPriority ) > 0 )
{
$ezxmlInputConverterDefinition->setArguments(
array(
$this->sortConverters( $convertersByPriority ),
)
);
}
}

/**
* Transforms a two-dimensional array of converters, indexed by priority,
* into a flat array of Reference objects.
*
* @param array $convertersByPriority
*
* @return \Symfony\Component\DependencyInjection\Reference[]
*/
protected function sortConverters( array $convertersByPriority )
{
ksort( $convertersByPriority );

return call_user_func_array( 'array_merge', $convertersByPriority );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ parameters:
ezpublish.fieldType.ezrichtext.converter.aggregate.class: eZ\Publish\Core\FieldType\RichText\Converter\Aggregate
ezpublish.fieldType.ezrichtext.converter.output.html5.class: eZ\Bundle\EzPublishCoreBundle\FieldType\RichText\Converter\Html5
ezpublish.fieldType.ezrichtext.converter.edit.html5.class: eZ\Bundle\EzPublishCoreBundle\FieldType\RichText\Converter\Html5Edit
ezpublish.fieldType.ezrichtext.converter.input.ezxml.normalize.class: eZ\Bundle\EzPublishCoreBundle\FieldType\RichText\Converter\Ezxml\ToRichTextPreNormalize
ezpublish.fieldType.ezrichtext.converter.input.html5.class: eZ\Bundle\EzPublishCoreBundle\FieldType\RichText\Converter\Html5Input
ezpublish.fieldType.ezrichtext.converter.link.class: eZ\Publish\Core\FieldType\RichText\Converter\Link
ezpublish.fieldType.ezrichtext.converter.embed.class: eZ\Publish\Core\FieldType\RichText\Converter\Render\Embed
Expand Down Expand Up @@ -136,9 +137,25 @@ services:
- { name: ezpublish.ezxml.converter, priority: 8 }

# RichText
# Aggregate converter for EZXML input that other converters register to
# through service tags.
ezpublish.fieldType.ezrichtext.converter.input.ezxml:
class: %ezpublish.fieldType.ezrichtext.converter.aggregate.class%

# Input normalizing converter should typically be the first one to execute
ezpublish.fieldType.ezrichtext.converter.input.ezxml.normalize:
class: %ezpublish.fieldType.ezrichtext.converter.input.ezxml.normalize.class%
arguments:
- @ezpublish.fieldType.ezxmltext.converter.expanding
- @ezpublish.fieldType.ezxmltext.converter.embedLinking
tags:
- {name: ezpublish.ezrichtext.converter.input.ezxml, priority: 0}

ezpublish.fieldType.ezrichtext.converter.input.ezxml.core:
class: %ezpublish.fieldType.ezrichtext.converter.xslt.class%
arguments: [%ezpublish.fieldType.ezrichtext.converter.input.ezxml.resources%]
tags:
- {name: ezpublish.ezrichtext.converter.input.ezxml, priority: 100}

ezpublish.fieldType.ezrichtext.converter.input.xhtml5:
class: %ezpublish.fieldType.ezrichtext.converter.input.html5.class%
Expand Down Expand Up @@ -176,15 +193,15 @@ services:
arguments:
- @ezpublish.fieldType.ezrichtext.renderer
tags:
- {name: ezpublish.ezrichtext.converter.output.xhtml5, priority: 0}
- {name: ezpublish.ezrichtext.converter.output.xhtml5, priority: 10}

ezpublish.fieldType.ezrichtext.converter.embed:
class: %ezpublish.fieldType.ezrichtext.converter.embed.class%
arguments:
- @ezpublish.fieldType.ezrichtext.renderer
- @?logger
tags:
- {name: ezpublish.ezrichtext.converter.output.xhtml5, priority: 0}
- {name: ezpublish.ezrichtext.converter.output.xhtml5, priority: 10}

ezpublish.fieldType.ezrichtext.converter.output.xhtml5.core:
class: %ezpublish.fieldType.ezrichtext.converter.output.html5.class%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<div class="{% if align is defined %}align-{{ align }}{% endif %}{% if class is defined %} {{ class }}{% endif %}">
{{
render(
controller(
"ez_content:embedContent",
{
"contentId": id,
"viewType": view,
"params": params
}
{% set params = { "objectParameters": {} } %}
{% if embedParams.config is defined %}
{% set params = params|merge( { "objectParameters": embedParams.config } ) %}
{% endif %}
{% if embedParams.link is defined %}
{% set params = params|merge( { "linkParameters": embedParams.link } ) %}
{% endif %}
<div class="{% if embedParams.align is defined %}align-{{ embedParams.align }}{% endif %}{% if embedParams.class is defined %} {{ embedParams.class }}{% endif %}">
{{
render(
controller(
"ez_content:embedContent",
{
"contentId": embedParams.id,
"viewType": embedParams.viewType,
"params": params
}
)
)
)
}}
}}
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="{% if align is defined %}align-{{ align }}{% endif %}{% if class is defined %} {{ class }}{% endif %}">
Content #{{ id }}: You do not have permission to view this Content
<div class="{% if embedParams.align is defined %}align-{{ embedParams.align }}{% endif %}{% if embedParams.class is defined %} {{ embedParams.class }}{% endif %}">
Content #{{ embedParams.id }}: You do not have permission to view this Content
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{% set params = { "objectParameters": {} } %}
{% if embedParams.config is defined %}
{% set params = params|merge( { "objectParameters": embedParams.config } ) %}
{% endif %}
{% if embedParams.link is defined %}
{% set params = params|merge( { "linkParameters": embedParams.link } ) %}
{% endif %}
{{
render(
controller(
"ez_content:viewContent",
{
"locationId": id,
"viewType": view,
"locationId": embedParams.id,
"viewType": embedParams.viewType,
"params": params
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[[ Content #{{ id }}: You do not have permission to view this Content ]]
[[ Content #{{ embedParams.id }}: You do not have permission to view this Content ]]
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<div class="{% if align is defined %}align-{{ align }}{% endif %}{% if class is defined %} {{ class }}{% endif %}">
{{
render(
controller(
"ez_content:viewLocation",
{
"locationId": id,
"viewType": view,
"params": params
}
{% set params = { "objectParameters": {} } %}
{% if embedParams.config is defined %}
{% set params = params|merge( { "objectParameters": embedParams.config } ) %}
{% endif %}
{% if embedParams.link is defined %}
{% set params = params|merge( { "linkParameters": embedParams.link } ) %}
{% endif %}
<div class="{% if embedParams.align is defined %}align-{{ embedParams.align }}{% endif %}{% if embedParams.class is defined %} {{ embedParams.class }}{% endif %}">
{{
render(
controller(
"ez_content:viewLocation",
{
"locationId": embedParams.id,
"viewType": embedParams.viewType,
"params": params
}
)
)
)
}}
}}
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="{% if align is defined %}align-{{ align }}{% endif %}{% if class is defined %} {{ class }}{% endif %}">
Location #{{ id }}: You do not have permission to view this Location
<div class="{% if embedParams.align is defined %}align-{{ embedParams.align }}{% endif %}{% if embedParams.class is defined %} {{ embedParams.class }}{% endif %}">
Location #{{ embedParams.id }}: You do not have permission to view this Location
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{% set params = { "objectParameters": {} } %}
{% if embedParams.config is defined %}
{% set params = params|merge( { "objectParameters": embedParams.config } ) %}
{% endif %}
{% if embedParams.link is defined %}
{% set params = params|merge( { "linkParameters": embedParams.link } ) %}
{% endif %}
{{
render(
controller(
"ez_content:viewLocation",
{
"locationId": id,
"viewType": view,
"locationId": embedParams.id,
"viewType": embedParams.viewType,
"params": params
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[[ Location #{{ id }}: You do not have permission to view this Location ]]
[[ Location #{{ embedParams.id }}: You do not have permission to view this Location ]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* File containing the eZ\Publish\Core\FieldType\RichText\Converter\Ezxml\ToRichTextPreNormalize class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/

namespace eZ\Publish\Core\FieldType\RichText\Converter\Ezxml;

use eZ\Publish\Core\FieldType\XmlText\Converter\EmbedLinking;
use eZ\Publish\Core\FieldType\XmlText\Converter\Expanding;
use eZ\Publish\Core\FieldType\RichText\Converter;
use DOMDocument;

/**
* Expands paragraphs and links embeds of a XML document in legacy ezxml format.
*
* Relies on XmlText's Expanding and EmbedLinking converters implementation.
*/
class ToRichTextPreNormalize implements Converter
{
/**
* @var \eZ\Publish\Core\FieldType\XmlText\Converter\Expanding
*/
protected $expandingConverter;

/**
* @var \eZ\Publish\Core\FieldType\XmlText\Converter\EmbedLinking
*/
protected $embedLinkingConverter;

/**
* Construct from XmlText converters implementation.
*
* @param \eZ\Publish\Core\FieldType\XmlText\Converter\Expanding $expandingConverter
* @param \eZ\Publish\Core\FieldType\XmlText\Converter\EmbedLinking $embedLinkingConverter
*/
public function __construct( Expanding $expandingConverter, EmbedLinking $embedLinkingConverter )
{
$this->expandingConverter = $expandingConverter;
$this->embedLinkingConverter = $embedLinkingConverter;
}

/**
* Converts given $document into another \DOMDocument object
*
* @param \DOMDocument $document
*
* @return \DOMDocument
*/
public function convert( DOMDocument $document )
{
// First
$this->expandingConverter->convert( $document );
// Second
$this->embedLinkingConverter->convert( $document );

return $document;
}
}
32 changes: 25 additions & 7 deletions eZ/Publish/Core/FieldType/RichText/Converter/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use eZ\Publish\Core\FieldType\RichText\Converter;
use eZ\Publish\Core\MVC\Symfony\Routing\UrlAliasRouter;
use Psr\Log\LoggerInterface;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Exceptions\NotFoundException as APINotFoundException;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException as APIUnauthorizedException;
use DOMDocument;
Expand Down Expand Up @@ -61,21 +62,26 @@ public function convert( DOMDocument $document )
$document = clone $document;
$xpath = new DOMXPath( $document );
$xpath->registerNamespace( "docbook", "http://docbook.org/ns/docbook" );
$xpathExpression = "//docbook:link[starts-with( @xlink:href, 'ezlocation://' ) or starts-with( @xlink:href, 'ezcontent://' )]";
$linkAttributeExpression = "starts-with( @xlink:href, 'ezlocation://' ) or starts-with( @xlink:href, 'ezcontent://' )";
$xpathExpression = "//docbook:link[{$linkAttributeExpression}]|//docbook:ezlink";

/** @var \DOMElement $link */
foreach ( $xpath->query( $xpathExpression ) as $link )
{
// Set resolved href to number character as a default if it can't be resolved
$hrefResolved = "#";
$href = $link->getAttribute( "xlink:href" );
$location = null;
preg_match( "~^(.+)://([^#]*)?(#.*|\\s*)?$~", $link->getAttribute( "xlink:href" ), $matches );
preg_match( "~^(.+://)?([^#]*)?(#.*|\\s*)?$~", $href, $matches );
list( , $scheme, $id, $fragment ) = $matches;

if ( $scheme === "ezcontent" )
if ( $scheme === "ezcontent://" )
{
try
{
$contentInfo = $this->contentService->loadContentInfo( $id );
$location = $this->locationService->loadLocation( $contentInfo->mainLocationId );
$hrefResolved = $this->urlAliasRouter->generate( $location ) . $fragment;
}
catch ( APINotFoundException $e )
{
Expand All @@ -98,12 +104,12 @@ public function convert( DOMDocument $document )
}
}
}

if ( $scheme === "ezlocation" )
else if ( $scheme === "ezlocation://" )
{
try
{
$location = $this->locationService->loadLocation( $id );
$hrefResolved = $this->urlAliasRouter->generate( $location ) . $fragment;
}
catch ( APINotFoundException $e )
{
Expand All @@ -126,11 +132,23 @@ public function convert( DOMDocument $document )
}
}
}
else
{
$hrefResolved = $href;
}

if ( $location !== null )
$hrefAttributeName = "xlink:href";

// For embeds set the resolved href to the separate attribute
// Original href needs to be preserved in order to generate link parameters
// This will need to change with introduction of UrlService and removal of URL link
// resolving in external storage
if ( $link->localName === "ezlink" )
{
$link->setAttribute( 'xlink:href', $this->urlAliasRouter->generate( $location ) . $fragment );
$hrefAttributeName = "href_resolved";
}

$link->setAttribute( $hrefAttributeName, $hrefResolved );
}

return $document;
Expand Down

0 comments on commit ef3e033

Please sign in to comment.