-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-29301: Provided support for custom classes and data attributes (#39)
* [Symfony] Created SA-aware configuration for custom attributes * [SiteAccess] Mapped configuration for custom attributes * Implemented validation of custom classes and attributes settings * Improved merging custom classes and attributes settings from scopes * Implemented ez_online_editor_attributes translation extractor * Set const visibility in RichText SiteAccess config parser * Changed "multiple" setting for attributes to be false by default * Disabled normalization of attribute names and improved validation * Refactored XSLT for list items to be uniform accross formats Changed the way transformation from DocBook to the other formats is done, to process listitem instead of listitem/para so ezattribute element is a direct child of listitem Formats: * DocBook * XHTML5EDIT * Output * Added custom data attributes support for ezembed(inline) elements * Added custom HTML class support for ezembed(inline) elements
- Loading branch information
Showing
29 changed files
with
699 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
EzSystems\EzPlatformRichText\Translation\Extractor\OnlineEditorCustomAttributesExtractor: | ||
arguments: | ||
$siteAccessList: '%ezpublish.siteaccess.list%' | ||
tags: | ||
- { name: jms_translation.extractor, alias: ez_online_editor_attributes } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/lib/Translation/Extractor/OnlineEditorCustomAttributesExtractor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformRichText\Translation\Extractor; | ||
|
||
use eZ\Publish\Core\MVC\ConfigResolverInterface; | ||
use EzSystems\EzPlatformRichTextBundle\DependencyInjection\Configuration\Parser\FieldType\RichText; | ||
use JMS\TranslationBundle\Model\MessageCatalogue; | ||
use JMS\TranslationBundle\Model\Message\XliffMessage; | ||
use JMS\TranslationBundle\Translation\ExtractorInterface; | ||
|
||
/** | ||
* Generates translation strings for limitation types. | ||
*/ | ||
final class OnlineEditorCustomAttributesExtractor implements ExtractorInterface | ||
{ | ||
private const MESSAGE_DOMAIN = 'online_editor'; | ||
private const ATTRIBUTES_MESSAGE_ID_PREFIX = 'ezrichtext.attributes'; | ||
private const CLASS_LABEL_MESSAGE_ID = 'ezrichtext.classes.class.label'; | ||
|
||
/** | ||
* @var \eZ\Publish\Core\MVC\ConfigResolverInterface | ||
*/ | ||
private $configResolver; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $siteAccessList; | ||
|
||
/** | ||
* @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver | ||
* @param string[] $siteAccessList | ||
*/ | ||
public function __construct(ConfigResolverInterface $configResolver, array $siteAccessList) | ||
{ | ||
$this->configResolver = $configResolver; | ||
$this->siteAccessList = $siteAccessList; | ||
} | ||
|
||
/** | ||
* Iterate over each scope and extract custom attributes label names. | ||
* | ||
* @return \JMS\TranslationBundle\Model\MessageCatalogue | ||
*/ | ||
public function extract(): MessageCatalogue | ||
{ | ||
$catalogue = new MessageCatalogue(); | ||
|
||
$catalogue->add($this->createMessage(self::CLASS_LABEL_MESSAGE_ID, 'Class')); | ||
|
||
foreach ($this->siteAccessList as $scope) { | ||
if (!$this->configResolver->hasParameter(RichText::ATTRIBUTES_SA_SETTINGS_ID)) { | ||
continue; | ||
} | ||
$this->extractMessagesForScope($catalogue, $scope); | ||
} | ||
|
||
return $catalogue; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @param string $desc | ||
* | ||
* @return \JMS\TranslationBundle\Model\Message\XliffMessage | ||
*/ | ||
private function createMessage(string $id, string $desc): XliffMessage | ||
{ | ||
$message = new XliffMessage($id, self::MESSAGE_DOMAIN); | ||
$message->setNew(false); | ||
$message->setMeaning($desc); | ||
$message->setDesc($desc); | ||
$message->setLocaleString($desc); | ||
$message->addNote('key: ' . $id); | ||
|
||
return $message; | ||
} | ||
|
||
/** | ||
* Extract messages from the given scope into the catalogue. | ||
* | ||
* @param \JMS\TranslationBundle\Model\MessageCatalogue $catalogue | ||
* @param string $scope | ||
*/ | ||
private function extractMessagesForScope(MessageCatalogue $catalogue, string $scope): void | ||
{ | ||
$attributes = $this->configResolver->getParameter( | ||
RichText::ATTRIBUTES_SA_SETTINGS_ID, | ||
null, | ||
$scope | ||
); | ||
foreach ($attributes as $elementName => $attributesConfig) { | ||
foreach (array_keys($attributesConfig) as $attributeName) { | ||
$messageId = sprintf( | ||
'%s.%s.%s.label', | ||
self::ATTRIBUTES_MESSAGE_ID_PREFIX, | ||
$elementName, | ||
$attributeName | ||
); | ||
// by default let's use attribute name | ||
$catalogue->add( | ||
$this->createMessage($messageId, $attributeName) | ||
); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.