diff --git a/.travis.yml b/.travis.yml index 5141cf0..eeda722 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,8 @@ language: php matrix: include: - - php: 7.1 - - php: 7.2 - php: 7.3 + - php: 7.4 cache: directories: diff --git a/README.md b/README.md index 427c4c6..64e3e53 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ The behavior of the relation list is completely controlled by the field definiti Refer to [the general information](doc/GENERAL.md) and [usage documentation](doc/USAGE.md) for more information. +:heavy_exclamation_mark: Upgrade in progress! :heavy_exclamation_mark: + ## Installation The installation uses composer and the general concept for adding bundles to a symfony installation. diff --git a/bundle/Core/FieldType/Mapper.php b/bundle/Core/FieldType/Mapper.php index cdf127c..c7dc7ab 100644 --- a/bundle/Core/FieldType/Mapper.php +++ b/bundle/Core/FieldType/Mapper.php @@ -11,10 +11,10 @@ namespace IntProg\EnhancedRelationListBundle\Core\FieldType; use eZ\Publish\API\Repository\ContentTypeService; -use EzSystems\RepositoryForms\Data\Content\FieldData; -use EzSystems\RepositoryForms\Data\FieldDefinitionData; -use EzSystems\RepositoryForms\FieldType\FieldDefinitionFormMapperInterface; -use EzSystems\RepositoryForms\FieldType\FieldValueFormMapperInterface; +use EzSystems\EzPlatformAdminUi\FieldType\FieldDefinitionFormMapperInterface; +use EzSystems\EzPlatformAdminUi\Form\Data\FieldDefinitionData; +use EzSystems\EzPlatformContentForms\Data\Content\FieldData; +use EzSystems\EzPlatformContentForms\FieldType\FieldValueFormMapperInterface; use IntProg\EnhancedRelationListBundle\Form\Type\EnhancedRelationListFieldDefinitionAttributesType; use IntProg\EnhancedRelationListBundle\Form\Type\EnhancedRelationListFieldDefinitionGroupsType; use IntProg\EnhancedRelationListBundle\Form\Type\EnhancedRelationListType; @@ -54,7 +54,7 @@ public function __construct(ContentTypeService $contentTypeService) * * @return void */ - public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data) + public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { $fieldDefinitionForm ->add( @@ -71,7 +71,6 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field ChoiceType::class, [ 'choices' => $this->getContentTypesHash(), - 'choices_as_values' => true, 'expanded' => false, 'multiple' => true, 'required' => false, diff --git a/bundle/Core/FieldType/Storage.php b/bundle/Core/FieldType/Storage.php index 581f979..9bd5a01 100644 --- a/bundle/Core/FieldType/Storage.php +++ b/bundle/Core/FieldType/Storage.php @@ -11,6 +11,7 @@ namespace IntProg\EnhancedRelationListBundle\Core\FieldType; use eZ\Publish\API\Repository\Exceptions\NotFoundException; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use eZ\Publish\SPI\FieldType\GatewayBasedStorage; use eZ\Publish\SPI\Persistence\Content\Field; use eZ\Publish\SPI\Persistence\Content\Type as FieldType; @@ -41,13 +42,17 @@ class Storage extends GatewayBasedStorage * * @param Handler $contentTypeHandler * @param RelationAttributeRepository $repository - * @param array $languages + * @param ConfigResolverInterface $configResolver */ - public function __construct(Handler $contentTypeHandler, RelationAttributeRepository $repository, array $languages) + public function __construct( + Handler $contentTypeHandler, + RelationAttributeRepository $repository, + ConfigResolverInterface $configResolver + ) { $this->contentTypeHandler = $contentTypeHandler; $this->repository = $repository; - $this->languages = $languages; + $this->languages = $configResolver->getParameter('languages'); } /** diff --git a/bundle/Core/FieldType/Type.php b/bundle/Core/FieldType/Type.php index 43532f6..0398517 100644 --- a/bundle/Core/FieldType/Type.php +++ b/bundle/Core/FieldType/Type.php @@ -15,7 +15,6 @@ use eZ\Publish\Core\FieldType\FieldType; use eZ\Publish\Core\FieldType\ValidationError; use eZ\Publish\Core\FieldType\Value as CoreValue; -use eZ\Publish\SPI\FieldType\Nameable; use eZ\Publish\SPI\FieldType\Value as SpiValue; use IntProg\EnhancedRelationListBundle\Core\FieldType\Value\Group; use IntProg\EnhancedRelationListBundle\Core\FieldType\Value\Relation; @@ -28,7 +27,7 @@ * @author Konrad, Steve * @copyright 2018 Intense Programming */ -class Type extends FieldType implements Nameable +class Type extends FieldType { /** @var RelationAttributeRepository $relationAttributeTransformer */ protected $relationAttributeTransformer; @@ -130,11 +129,13 @@ public function getFieldTypeIdentifier() /** * Returns a human readable string representation from the given $value. * - * @param SpiValue $value + * @param SpiValue $value + * @param FieldDefinition $fieldDefinition + * @param string $languageCode * * @return string */ - public function getName(SpiValue $value) + public function getName(SpiValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { return (string) $value; } diff --git a/bundle/Form/Type/EnhancedRelationListFieldDefinitionAttributesType.php b/bundle/Form/Type/EnhancedRelationListFieldDefinitionAttributesType.php index beb96fe..a24ed8b 100644 --- a/bundle/Form/Type/EnhancedRelationListFieldDefinitionAttributesType.php +++ b/bundle/Form/Type/EnhancedRelationListFieldDefinitionAttributesType.php @@ -12,6 +12,7 @@ use eZ\Publish\API\Repository\Exceptions\NotFoundException; use eZ\Publish\API\Repository\LanguageService; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use IntProg\EnhancedRelationListBundle\Core\DataTransformer\FieldDefinitionAttributesTransformer; use IntProg\EnhancedRelationListBundle\Service\RelationAttributeRepository; use Symfony\Component\Form\AbstractType; @@ -35,6 +36,7 @@ class EnhancedRelationListFieldDefinitionAttributesType extends AbstractType /** @var LanguageService $languageService */ protected $languageService; + /** @var array|string[] $languages */ protected $languages; /** @@ -42,17 +44,17 @@ class EnhancedRelationListFieldDefinitionAttributesType extends AbstractType * * @param RelationAttributeRepository $attributeRepository * @param LanguageService $languageService - * @param array $languages + * @param ConfigResolverInterface $configResolver */ public function __construct( RelationAttributeRepository $attributeRepository, LanguageService $languageService, - array $languages + ConfigResolverInterface $configResolver ) { $this->attributeRepository = $attributeRepository; $this->languageService = $languageService; - $this->languages = $languages; + $this->languages = $configResolver->getParameter('languages'); } /** diff --git a/bundle/Form/Type/EnhancedRelationListFieldDefinitionGroupsType.php b/bundle/Form/Type/EnhancedRelationListFieldDefinitionGroupsType.php index 8946cfc..c8d288c 100644 --- a/bundle/Form/Type/EnhancedRelationListFieldDefinitionGroupsType.php +++ b/bundle/Form/Type/EnhancedRelationListFieldDefinitionGroupsType.php @@ -12,6 +12,7 @@ use eZ\Publish\API\Repository\Exceptions\NotFoundException; use eZ\Publish\API\Repository\LanguageService; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use IntProg\EnhancedRelationListBundle\Core\DataTransformer\FieldDefinitionGroupsTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; @@ -28,14 +29,22 @@ */ class EnhancedRelationListFieldDefinitionGroupsType extends AbstractType { + /** @var LanguageService $languageService */ protected $languageService; + /** @var array|string[] $languages */ protected $languages; - public function __construct(LanguageService $languageService, array $languages) + /** + * EnhancedRelationListFieldDefinitionGroupsType constructor. + * + * @param LanguageService $languageService + * @param ConfigResolverInterface $configResolver + */ + public function __construct(LanguageService $languageService, ConfigResolverInterface $configResolver) { $this->languageService = $languageService; - $this->languages = $languages; + $this->languages = $configResolver->getParameter('languages'); } /** diff --git a/bundle/Resources/assets/js/intprogenhancedrelationlist.js b/bundle/Resources/assets/js/intprogenhancedrelationlist.js index 4126487..ebbc070 100644 --- a/bundle/Resources/assets/js/intprogenhancedrelationlist.js +++ b/bundle/Resources/assets/js/intprogenhancedrelationlist.js @@ -51,6 +51,7 @@ document.addEventListener('DOMContentLoaded', function _onLoad() { input: jsonValueInput, value: JSON.parse(jsonValueInput.value), cloneContainer: cloneContainer, + udwConfig: JSON.parse(fieldContainer.querySelector('script[data-udw-config]').innerText), udwContainer: udwContainer, udwModule: global.eZ.modules.UniversalDiscovery, settings: JSON.parse(fieldContainer.querySelector('script[data-settings]').innerText), diff --git a/bundle/Resources/config/ez_field_templates.yml b/bundle/Resources/config/ez_field_templates.yml index 48650d7..ada8576 100644 --- a/bundle/Resources/config/ez_field_templates.yml +++ b/bundle/Resources/config/ez_field_templates.yml @@ -21,8 +21,13 @@ system: content_view: element_simple_link: default: - controller: 'EzPlatformAdminUiBundle:ContentView:locationView' - template: '@ezdesign/enhanced_relation_list/simple_link.html.twig' + controller: 'ez_content:viewAction' + template: '@ezdesign/enhanced_relation_list/view/default/content/simple_link.html.twig' + match: true + element_simple_text: + default: + controller: 'ez_content:viewAction' + template: '@ezdesign/enhanced_relation_list/view/default/content/simple_text.html.twig' match: true fielddefinition_settings_templates: - {template: '@ezdesign/enhanced_relation_list/fielddefinition_settings.html.twig', priority: 0} diff --git a/bundle/Resources/config/fieldtypes.yml b/bundle/Resources/config/fieldtypes.yml index 1288b96..e3e968b 100644 --- a/bundle/Resources/config/fieldtypes.yml +++ b/bundle/Resources/config/fieldtypes.yml @@ -23,8 +23,9 @@ services: IntProg\EnhancedRelationListBundle\Core\FieldType\Storage: arguments: - - '@ezpublish.spi.persistence.content_type_handler' - - '@IntProg\EnhancedRelationListBundle\Service\RelationAttributeRepository' - - '$languages$' + $contentTypeHandler: '@ezpublish.spi.persistence.content_type_handler' + $repository: '@IntProg\EnhancedRelationListBundle\Service\RelationAttributeRepository' + lazy: true + autowire: true tags: - { name: ezpublish.fieldType.externalStorageHandler, alias: intprogenhancedrelationlist } diff --git a/bundle/Resources/config/form.yml b/bundle/Resources/config/form.yml index c63a62a..8bcb99b 100644 --- a/bundle/Resources/config/form.yml +++ b/bundle/Resources/config/form.yml @@ -7,16 +7,15 @@ services: - { name: form.type } IntProg\EnhancedRelationListBundle\Form\Type\EnhancedRelationListFieldDefinitionGroupsType: - arguments: - - '@ezpublish.api.service.language' - - '$languages$' + lazy: true + autowire: true tags: - { name: form.type } IntProg\EnhancedRelationListBundle\Form\Type\EnhancedRelationListFieldDefinitionAttributesType: arguments: - - '@IntProg\EnhancedRelationListBundle\Service\RelationAttributeRepository' - - '@ezpublish.api.service.language' - - '$languages$' + $attributeRepository: '@IntProg\EnhancedRelationListBundle\Service\RelationAttributeRepository' + lazy: true + autowire: true tags: - { name: form.type } diff --git a/bundle/Resources/config/templating.yml b/bundle/Resources/config/templating.yml index b3512b7..ae89674 100644 --- a/bundle/Resources/config/templating.yml +++ b/bundle/Resources/config/templating.yml @@ -3,10 +3,8 @@ services: class: IntProg\EnhancedRelationListBundle\Templating\Twig\AttributeBlockRenderer calls: - [setTwig, ['@twig']] - - [setBaseTemplate, ["$enhanced_relation_list.base_template$"]] - - [setAttributeViewResources, ["$enhanced_relation_list.attribute_templates$"]] - - [setAttributeDefinitionViewResources, ["$enhanced_relation_list.attribute_definition_templates$"]] lazy: true + autowire: true intprog.enhanced-relation-list.templating.attribute_block_renderer: alias: intprog.enhanced-relation-list.templating.attribute_block_renderer.twig diff --git a/bundle/Resources/translations/ezrepoforms_content_type.en.yml b/bundle/Resources/translations/content_type.en.yml similarity index 100% rename from bundle/Resources/translations/ezrepoforms_content_type.en.yml rename to bundle/Resources/translations/content_type.en.yml diff --git a/bundle/Resources/views/enhanced_relation_list/content/content_edit.html.twig b/bundle/Resources/views/enhanced_relation_list/content/content_edit.html.twig index 887a85d..8b0c31b 100644 --- a/bundle/Resources/views/enhanced_relation_list/content/content_edit.html.twig +++ b/bundle/Resources/views/enhanced_relation_list/content/content_edit.html.twig @@ -9,7 +9,16 @@ - + +
diff --git a/bundle/Resources/views/enhanced_relation_list/content_fields.html.twig b/bundle/Resources/views/enhanced_relation_list/content_fields.html.twig index a6d0c97..fbb327b 100644 --- a/bundle/Resources/views/enhanced_relation_list/content_fields.html.twig +++ b/bundle/Resources/views/enhanced_relation_list/content_fields.html.twig @@ -12,7 +12,7 @@ {% macro render_intprogenhancedrelationlist(content, field, fieldSettings) %} {% import _self as erl_table_macros %} - {% include '@ezdesign/parts/table_header.html.twig' with {headerText: 'field.attribute.table.head.relations'|trans} %} + {% include '@ezdesign/ui/table_header.html.twig' with {header_text: 'field.attribute.table.head.relations'|trans} %} {{ erl_table_macros.table_head_macro(fieldSettings, field) }} diff --git a/bundle/Resources/views/enhanced_relation_list/content_type/field_types.html.twig b/bundle/Resources/views/enhanced_relation_list/content_type/field_types.html.twig index 69a64fa..567169d 100644 --- a/bundle/Resources/views/enhanced_relation_list/content_type/field_types.html.twig +++ b/bundle/Resources/views/enhanced_relation_list/content_type/field_types.html.twig @@ -1,5 +1,5 @@ -{% use 'EzPublishCoreBundle::fielddefinition_settings.html.twig' %} +{% use '@ezdesign/fielddefinition_settings.html.twig' %} {% trans_default_domain 'enhancedrelationlist_attribute' %} @@ -11,18 +11,18 @@ {{- form_widget(form.defaultBrowseLocation) -}}
- + >{{"field_definition.ezobjectrelationlist.selection_root_udw_button"|trans({}, "content_type")}}
{% if form.defaultBrowseLocation.vars.value is not empty %} - {{ render( controller( "ez_content:viewLocation", {'locationId': form.defaultBrowseLocation.vars.value, 'viewType': '_platformui_content_name'} ) ) }} + {{ render( controller( "ez_content:viewAction", {'locationId': form.defaultBrowseLocation.vars.value, 'viewType': 'element_simple_text', 'layout': false} ) ) }} {% endif %}
diff --git a/bundle/Resources/views/enhanced_relation_list/simple_link.html.twig b/bundle/Resources/views/enhanced_relation_list/view/default/content/simple_link.html.twig similarity index 76% rename from bundle/Resources/views/enhanced_relation_list/simple_link.html.twig rename to bundle/Resources/views/enhanced_relation_list/view/default/content/simple_link.html.twig index 44ab05a..4379a9a 100644 --- a/bundle/Resources/views/enhanced_relation_list/simple_link.html.twig +++ b/bundle/Resources/views/enhanced_relation_list/view/default/content/simple_link.html.twig @@ -1,5 +1,5 @@ {{ content.getName() }} {% if content.contentInfo.trashed %} diff --git a/bundle/Resources/views/enhanced_relation_list/view/default/content/simple_text.html.twig b/bundle/Resources/views/enhanced_relation_list/view/default/content/simple_text.html.twig new file mode 100644 index 0000000..97b8fa2 --- /dev/null +++ b/bundle/Resources/views/enhanced_relation_list/view/default/content/simple_text.html.twig @@ -0,0 +1 @@ +{{ content.getName() }} diff --git a/bundle/Templating/Twig/AttributeBlockRenderer.php b/bundle/Templating/Twig/AttributeBlockRenderer.php index 6cfc44a..bee09b8 100644 --- a/bundle/Templating/Twig/AttributeBlockRenderer.php +++ b/bundle/Templating/Twig/AttributeBlockRenderer.php @@ -10,6 +10,7 @@ namespace IntProg\EnhancedRelationListBundle\Templating\Twig; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use IntProg\EnhancedRelationListBundle\Core\Exception\MissingAttributeBlockException; use IntProg\EnhancedRelationListBundle\Core\RelationAttributeBase; use Twig\Environment; @@ -45,14 +46,25 @@ class AttributeBlockRenderer * * @var Template[]|array */ - private $attributeViewResources = []; + private $attributeViewResources; /** * Array of Twig template resources for attribute definition view. * * @var Template[]|array */ - private $attributeDefinitionViewResources = []; + private $attributeDefinitionViewResources; + + public function __construct(ConfigResolverInterface $configResolver) + { + $this->baseTemplate = $configResolver->getParameter('enhanced_relation_list.base_template'); + + $this->attributeViewResources = $configResolver->getParameter('enhanced_relation_list.attribute_templates'); + usort($this->attributeViewResources, [$this, 'sortResourcesCallback']); + + $this->attributeDefinitionViewResources = $configResolver->getParameter('enhanced_relation_list.attribute_definition_templates'); + usort($this->attributeDefinitionViewResources, [$this, 'sortResourcesCallback']); + } /** * Setter for the twig environment. @@ -66,32 +78,6 @@ public function setTwig(Environment $environment) $this->twig = $environment; } - /** - * @param string|Template $baseTemplate - */ - public function setBaseTemplate($baseTemplate) - { - $this->baseTemplate = $baseTemplate; - } - - /** - * @param array $attributeViewResources - */ - public function setAttributeViewResources(array $attributeViewResources) - { - $this->attributeViewResources = (array) $attributeViewResources; - usort($this->attributeViewResources, [$this, 'sortResourcesCallback']); - } - - /** - * @param array $attributeDefinitionViewResources - */ - public function setAttributeDefinitionViewResources(array $attributeDefinitionViewResources) - { - $this->attributeDefinitionViewResources = (array) $attributeDefinitionViewResources; - usort($this->attributeDefinitionViewResources, [$this, 'sortResourcesCallback']); - } - /** * @param array $a * @param array $b @@ -136,7 +122,10 @@ public function renderAttributeView( // Getting instance of Twig_Template that will be used to render blocks if (is_string($this->baseTemplate)) { - $this->baseTemplate = $this->twig->loadTemplate($this->baseTemplate); + $this->baseTemplate = $this->twig->loadTemplate( + $this->twig->getTemplateClass($this->baseTemplate), + $this->baseTemplate + ); } $blockName = $this->getRenderAttributeBlockName($attribute->getTypeIdentifier()); @@ -179,7 +168,10 @@ public function renderAttributeDefinitionView( // Getting instance of Twig_Template that will be used to render blocks if (is_string($this->baseTemplate)) { - $this->baseTemplate = $this->twig->loadTemplate($this->baseTemplate); + $this->baseTemplate = $this->twig->loadTemplate( + $this->twig->getTemplateClass($this->baseTemplate), + $this->baseTemplate + ); } $blockName = $this->getRenderAttributeDefinitionBlockName($attributeIdentifier); @@ -231,7 +223,10 @@ private function getBlocksByAttributeIdentifier(string $fieldTypeIdentifier, $lo if ($localTemplate !== null) { // $localTemplate might be a Twig_Template instance already (e.g. using _self Twig keyword) if (!$localTemplate instanceof Template) { - $localTemplate = $this->twig->loadTemplate($localTemplate); + $localTemplate = $this->twig->loadTemplate( + $this->twig->getTemplateClass($localTemplate), + $localTemplate + ); } $block = $this->searchBlock($fieldBlockName, $localTemplate); @@ -261,7 +256,10 @@ private function getBlockByName(string $name, string $resourcesName) foreach ($this->{$resourcesName} as &$template) { if (!$template instanceof Template) { - $template = $this->twig->loadTemplate($template['template']); + $template = $this->twig->loadTemplate( + $this->twig->getTemplateClass($template['template']), + $template['template'] + ); } $tpl = $template; @@ -293,7 +291,10 @@ private function getBlocksByDefinitionIdentifier(string $definitionIdentifier, $ if ($localTemplate !== null) { // $localTemplate might be a Twig_Template instance already (e.g. using _self Twig keyword) if (!$localTemplate instanceof Template) { - $localTemplate = $this->twig->loadTemplate($localTemplate); + $localTemplate = $this->twig->loadTemplate( + $this->twig->getTemplateClass($localTemplate), + $localTemplate + ); } $block = $this->searchBlock($fieldBlockName, $localTemplate); diff --git a/composer.json b/composer.json index c64a34c..6c169e9 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,14 @@ } ], "require": { - "php": "^7.1", + "php": "^7.3", "ext-dom": "*", "ext-json": "*", - "ezsystems/ezpublish-kernel": "~7.5", - "ezsystems/ezplatform-admin-ui": "~1.5" + "ezsystems/ezplatform-kernel": "~1.0", + "ezsystems/ezplatform-admin-ui": "~2.0" }, "require-dev": { - "phpunit/phpunit": "~7.0" + "phpunit/phpunit": "~9.1" }, "autoload": { "psr-4": { @@ -38,8 +38,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.1.x-dev", - "dev-1.0": "1.0.x-dev" + "dev-master": "2.0.x-dev" } } } diff --git a/lib/javascript/components/content-edit.js b/lib/javascript/components/content-edit.js index 207c918..d8d8c27 100644 --- a/lib/javascript/components/content-edit.js +++ b/lib/javascript/components/content-edit.js @@ -164,6 +164,7 @@ export default class ContentEditBase extends Component { toggleRemove={this.toggleRemove} removeRows={this.removeRows} helperContainer={this.props.cloneContainer} + udwConfig={this.props.udwConfig} udwContainer={this.props.udwContainer} udwModule={this.props.udwModule} attributeModules={this.props.attributeModules} @@ -188,6 +189,7 @@ ContentEditBase.propTypes = { languages: PropTypes.arrayOf(PropTypes.string).isRequired, input: PropTypes.instanceOf(Node), cloneContainer: PropTypes.instanceOf(Node), + udwConfig: PropTypes.object.isRequired, udwContainer: PropTypes.instanceOf(Node), udwModule: PropTypes.instanceOf(Component), attributeModules: PropTypes.arrayOf(PropTypes.instanceOf(Component)).isRequired, diff --git a/lib/javascript/components/content-edit/table.js b/lib/javascript/components/content-edit/table.js index cef580d..f251069 100644 --- a/lib/javascript/components/content-edit/table.js +++ b/lib/javascript/components/content-edit/table.js @@ -141,6 +141,7 @@ class TableElement extends Component { } renderUdwPortal() { + const config = this.props.udwConfig; const UniversalDiscoveryModule = this.props.udwModule; let selectedItemsLimit = this.props.settings.selectionLimit; @@ -158,8 +159,8 @@ class TableElement extends Component { multiple={selectedItemsLimit !== 1} selectedItemsLimit={selectedItemsLimit} startingLocationId={startingLocationId} - restInfo={this.props.restInfo} canSelectContent={this.canSelectContent} + {...config} />, this.props.udwContainer ); @@ -294,6 +295,7 @@ TableElement.propTypes = { languages: PropTypes.arrayOf(PropTypes.string).isRequired, input: PropTypes.instanceOf(Node), cloneContainer: PropTypes.instanceOf(Node), + udwConfig: PropTypes.object.isRequired, udwContainer: PropTypes.instanceOf(Node), udwModule: PropTypes.instanceOf(Component), attributeModules: PropTypes.arrayOf(PropTypes.instanceOf(Component)).isRequired, diff --git a/tests/Core/FieldType/MapperTest.php b/tests/Core/FieldType/MapperTest.php index 56bbbf0..92ffeef 100644 --- a/tests/Core/FieldType/MapperTest.php +++ b/tests/Core/FieldType/MapperTest.php @@ -14,8 +14,8 @@ use eZ\Publish\Core\Repository\Values\ContentType\ContentType; use eZ\Publish\Core\Repository\Values\ContentType\ContentTypeGroup; use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; -use EzSystems\RepositoryForms\Data\Content\FieldData; -use EzSystems\RepositoryForms\Data\FieldDefinitionData; +use EzSystems\EzPlatformAdminUi\Form\Data\FieldDefinitionData; +use EzSystems\EzPlatformContentForms\Data\Content\FieldData; use IntProg\EnhancedRelationListBundle\Form\Type\EnhancedRelationListType; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -49,7 +49,6 @@ public function testMapFieldDefinitionForm() 'test b' => 'type_2', 'test c' => 'type_1', ], - 'choices_as_values' => true, 'expanded' => false, 'multiple' => true, 'required' => false, diff --git a/tests/Core/FieldType/StorageTest.php b/tests/Core/FieldType/StorageTest.php index d3b8f0a..cfd7260 100644 --- a/tests/Core/FieldType/StorageTest.php +++ b/tests/Core/FieldType/StorageTest.php @@ -10,6 +10,7 @@ namespace IntProg\EnhancedRelationListBundle\Core\FieldType; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use eZ\Publish\SPI\Persistence\Content\Field; use eZ\Publish\SPI\Persistence\Content\FieldTypeConstraints; use eZ\Publish\SPI\Persistence\Content\Type as FieldType; @@ -25,11 +26,13 @@ class StorageTest extends TestCase { public function testNotUsedMethods() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn([]); + $contentTypeHandler = $this->createMock(Handler::class); $transformer = new RelationAttributeRepository([]); - $languages = []; - $storage = new Storage($contentTypeHandler, $transformer, $languages); + $storage = new Storage($contentTypeHandler, $transformer, $configResolver); $this->assertNull($storage->storeFieldData(new VersionInfo(), new Field(), []), 'Should do nothing'); $this->assertNull($storage->deleteFieldData(new VersionInfo(), [], []), 'Should do nothing'); @@ -91,10 +94,12 @@ public function testGetFieldData() 'selection' => new AttributeConverter\Selection(), 'string' => new AttributeConverter\TextLine(), ]); - $languages = ['eng-GB']; + + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); $type = new Type($transformer); - $storage = new Storage($contentTypeHandler, $transformer, $languages); + $storage = new Storage($contentTypeHandler, $transformer, $configResolver); $field = new Field([ 'fieldDefinitionId' => 222, diff --git a/tests/Core/FieldType/TypeTest.php b/tests/Core/FieldType/TypeTest.php index 23aae0f..b1ea113 100644 --- a/tests/Core/FieldType/TypeTest.php +++ b/tests/Core/FieldType/TypeTest.php @@ -41,7 +41,7 @@ public function testGetName() $transformer = $this->getTransformer(); $type = new Type($transformer); - $this->assertEquals('123, 312, 987', $type->getName($this->getSampleValue()), 'Name should be correctly generated.'); + $this->assertEquals('123, 312, 987', $type->getName($this->getSampleValue(), new FieldDefinition(), 'eng-GB'), 'Name should be correctly generated.'); } public function testFromHash() diff --git a/tests/Form/Type/EnhancedRelationListFieldDefinitionAttributesTypeTest.php b/tests/Form/Type/EnhancedRelationListFieldDefinitionAttributesTypeTest.php index ccb07a1..deebfdf 100644 --- a/tests/Form/Type/EnhancedRelationListFieldDefinitionAttributesTypeTest.php +++ b/tests/Form/Type/EnhancedRelationListFieldDefinitionAttributesTypeTest.php @@ -13,6 +13,7 @@ use eZ\Publish\API\Repository\LanguageService; use eZ\Publish\API\Repository\Values\Content\Language; use eZ\Publish\Core\Base\Exceptions\NotFoundException; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use IntProg\EnhancedRelationListBundle\Core\DataTransformer\FieldDefinitionAttributesTransformer; use IntProg\EnhancedRelationListBundle\Service\AttributeConverter; use IntProg\EnhancedRelationListBundle\Service\RelationAttributeRepository; @@ -27,18 +28,22 @@ class EnhancedRelationListFieldDefinitionAttributesTypeTest extends TestCase private function getLanguageServiceMock() { $mock = $this->createMock(LanguageService::class); - $mock->expects($this->any())->method('loadLanguage')->will($this->returnCallback(function($languageCode) { + $mock->method('loadLanguage')->willReturnCallback(static function($languageCode) { return new Language(['languageCode' => $languageCode, 'name' => 'stub']); - })); + }); + return $mock; } public function testGetName() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + $type = new EnhancedRelationListFieldDefinitionAttributesType( $this->getTransformer(), $this->getLanguageServiceMock(), - ['eng-GB'] + $configResolver ); $this->assertEquals('intprogenhancedrelationlist_definition_attributes', $type->getName()); @@ -46,10 +51,13 @@ public function testGetName() public function testGetParent() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + $type = new EnhancedRelationListFieldDefinitionAttributesType( $this->getTransformer(), $this->getLanguageServiceMock(), - ['eng-GB'] + $configResolver ); $this->assertEquals(HiddenType::class, $type->getParent()); @@ -57,10 +65,13 @@ public function testGetParent() public function testGetBlockPrefix() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + $type = new EnhancedRelationListFieldDefinitionAttributesType( $this->getTransformer(), $this->getLanguageServiceMock(), - ['eng-GB'] + $configResolver ); $this->assertEquals('intprogenhancedrelationlist_definition_attributes', $type->getBlockPrefix()); @@ -68,10 +79,13 @@ public function testGetBlockPrefix() public function testBuildForm() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + $type = new EnhancedRelationListFieldDefinitionAttributesType( $this->getTransformer(), $this->getLanguageServiceMock(), - ['eng-GB'] + $configResolver ); $builder = $this->createMock(FormBuilder::class); $builder->expects($this->once())->method('addModelTransformer')->with(new FieldDefinitionAttributesTransformer()); @@ -81,11 +95,14 @@ public function testBuildForm() public function testMissingButConfiguredLanguage() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB', 'fre-FR']); + $languageService = $this->createMock(LanguageService::class); - $languageService->expects($this->at(0))->method('loadLanguage')->will( - $this->returnCallback(function($languageCode) { + $languageService->expects($this->at(0))->method('loadLanguage')->willReturnCallback( + static function($languageCode) { return new Language(['languageCode' => $languageCode, 'name' => 'stub']); - }) + } ); $languageService->expects($this->at(1))->method('loadLanguage')->will( $this->throwException(new NotFoundException('language not found', 'fre-FR')) @@ -95,7 +112,7 @@ public function testMissingButConfiguredLanguage() $type = new EnhancedRelationListFieldDefinitionAttributesType( $this->getTransformer(), $languageService, - ['eng-GB', 'fre-FR'] + $configResolver ); $form = $this->createMock(Form::class); $form->expects($this->once())->method('getData')->willReturn('data sample'); @@ -121,11 +138,14 @@ public function testMissingButConfiguredLanguage() public function testBuildView() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + $view = new FormView(); $type = new EnhancedRelationListFieldDefinitionAttributesType( $this->getTransformer(), $this->getLanguageServiceMock(), - ['eng-GB'] + $configResolver ); $form = $this->createMock(Form::class); $form->expects($this->once())->method('getData')->willReturn('data sample'); diff --git a/tests/Form/Type/EnhancedRelationListFieldDefinitionGroupsTypeTest.php b/tests/Form/Type/EnhancedRelationListFieldDefinitionGroupsTypeTest.php index ea19887..f3cbfd2 100644 --- a/tests/Form/Type/EnhancedRelationListFieldDefinitionGroupsTypeTest.php +++ b/tests/Form/Type/EnhancedRelationListFieldDefinitionGroupsTypeTest.php @@ -13,6 +13,7 @@ use eZ\Publish\API\Repository\LanguageService; use eZ\Publish\API\Repository\Values\Content\Language; use eZ\Publish\Core\Base\Exceptions\NotFoundException; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use IntProg\EnhancedRelationListBundle\Core\DataTransformer\FieldDefinitionGroupsTransformer; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\Extension\Core\Type\HiddenType; @@ -26,9 +27,9 @@ protected function getLanguageServiceMock() { $builder = $this->createMock(LanguageService::class); - $builder->expects($this->any())->method('loadLanguage')->willReturnCallback( - function ($languageCode) { - if ($languageCode != 'eng-GB') { + $builder->method('loadLanguage')->willReturnCallback( + static function ($languageCode) { + if ($languageCode !== 'eng-GB') { throw new NotFoundException('not found', $languageCode); } @@ -46,28 +47,40 @@ function ($languageCode) { public function testGetName() { - $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), ['eng-GB']); + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + + $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), $configResolver); $this->assertEquals('intprogenhancedrelationlist_definition_groups', $type->getName()); } public function testGetParent() { - $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), ['eng-GB']); + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + + $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), $configResolver); $this->assertEquals(HiddenType::class, $type->getParent()); } public function testGetBlockPrefix() { - $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), ['eng-GB']); + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + + $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), $configResolver); $this->assertEquals('intprogenhancedrelationlist_definition_groups', $type->getBlockPrefix()); } public function testBuildForm() { - $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), ['eng-GB']); + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB']); + + $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), $configResolver); $builder = $this->createMock(FormBuilder::class); $builder->expects($this->once())->method('addModelTransformer')->with(new FieldDefinitionGroupsTransformer()); @@ -76,8 +89,11 @@ public function testBuildForm() public function testFinishView() { + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturn(['eng-GB', 'fre-FR']); + $view = new FormView(); - $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), ['eng-GB', 'ger-DE']); + $type = new EnhancedRelationListFieldDefinitionGroupsType($this->getLanguageServiceMock(), $configResolver); $form = $this->createMock(Form::class); $normData = ['some', 'array']; $form->expects($this->once())->method('getNormData')->willReturn(json_encode($normData)); diff --git a/tests/Form/Type/EnhancedRelationListTypeTest.php b/tests/Form/Type/EnhancedRelationListTypeTest.php index 5ec0b82..3d1ee34 100644 --- a/tests/Form/Type/EnhancedRelationListTypeTest.php +++ b/tests/Form/Type/EnhancedRelationListTypeTest.php @@ -12,6 +12,7 @@ use eZ\Publish\Core\FieldType\ValidationError; use eZ\Publish\Core\Repository\ContentService; +use eZ\Publish\Core\Repository\Values\Content\Content; use IntProg\EnhancedRelationListBundle\Core\DataTransformer\FieldValueTransformer; use IntProg\EnhancedRelationListBundle\Core\FieldType\Value; use IntProg\EnhancedRelationListBundle\Service\RelationAttributeRepository; @@ -56,8 +57,9 @@ public function testFinishView() ])); $form->expects($this->once())->method('getData')->willReturn(new Value([])); + $content = new Content(); $contentService = $this->createMock(ContentService::class); - $contentService->expects($this->once())->method('loadContent')->with(12)->willReturn('content target'); + $contentService->expects($this->once())->method('loadContent')->with(12)->willReturn($content); $type = new EnhancedRelationListType( $contentService, @@ -85,7 +87,7 @@ public function testFinishView() [ 'contentId' => 12, 'vars' => [ - 'content' => 'content target', + 'content' => $content, ], ], [ @@ -115,8 +117,9 @@ public function testFinishViewWithCustomErrors() $form->expects($this->once())->method('getData')->willReturn($value); + $content = new Content(); $contentService = $this->createMock(ContentService::class); - $contentService->expects($this->once())->method('loadContent')->with(12)->willReturn('content target'); + $contentService->expects($this->once())->method('loadContent')->with(12)->willReturn($content); $type = new EnhancedRelationListType( $contentService, @@ -144,7 +147,7 @@ public function testFinishViewWithCustomErrors() [ 'contentId' => 12, 'vars' => [ - 'content' => 'content target', + 'content' => $content, ], ], [ diff --git a/tests/Templating/Twig/AttributeBlockRendererTest.php b/tests/Templating/Twig/AttributeBlockRendererTest.php index ed6edcf..fe4b3ff 100644 --- a/tests/Templating/Twig/AttributeBlockRendererTest.php +++ b/tests/Templating/Twig/AttributeBlockRendererTest.php @@ -10,6 +10,7 @@ namespace IntProg\EnhancedRelationListBundle\Templating\Twig; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use IntProg\EnhancedRelationListBundle\Core\FieldType\Attribute\Boolean; use IntProg\EnhancedRelationListBundle\Core\FieldType\Attribute\Integer; use IntProg\EnhancedRelationListBundle\Core\FieldType\Attribute\TextLine; @@ -56,7 +57,7 @@ public function testRenderAttributeView() $booleanParams = ['some_parameter' => 'boolean']; $environment->method('loadTemplate')->willReturnCallback( - function ($templateName) use ($templateList) { + function ($ignored, $templateName) use ($templateList) { return $templateList[$templateName]; } ); @@ -81,14 +82,26 @@ function ($blockName, $context, $blocks) { } ); - $renderer = new AttributeBlockRenderer(); - $renderer->setTwig($environment); - $renderer->setBaseTemplate('the_base_template'); - $renderer->setAttributeViewResources([ + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturnCallback(static function ($parameter) { + switch ($parameter) { + case 'enhanced_relation_list.base_template': + return 'the_base_template'; + case 'enhanced_relation_list.attribute_templates': + return [ ['template' => 'template_1', 'priority' => 1], ['template' => 'template_2', 'priority' => 3], ['template' => 'template_3', 'priority' => 2], - ]); + ]; + case 'enhanced_relation_list.attribute_definition_templates': + return []; + } + + return null; + }); + + $renderer = new AttributeBlockRenderer($configResolver); + $renderer->setTwig($environment); $this->assertEquals($integerBlock, $renderer->renderAttributeView($integerAttribute, $integerDefinition, $integerParams)); $this->assertEquals($stringBlock, $renderer->renderAttributeView($stringAttribute, $stringDefinition, $stringParams)); @@ -125,7 +138,7 @@ public function testRenderAttributeDefinitionView() $booleanParams = ['some_parameter' => 'boolean']; $environment->method('loadTemplate')->willReturnCallback( - function ($templateName) use ($templateList) { + function ($ignored, $templateName) use ($templateList) { return $templateList[$templateName]; } ); @@ -150,14 +163,26 @@ function ($blockName, $context, $blocks) { } ); - $renderer = new AttributeBlockRenderer(); + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturnCallback(static function ($parameter) { + switch ($parameter) { + case 'enhanced_relation_list.base_template': + return 'the_base_template'; + case 'enhanced_relation_list.attribute_templates': + return []; + case 'enhanced_relation_list.attribute_definition_templates': + return [ + ['template' => 'template_1', 'priority' => 1], + ['template' => 'template_2', 'priority' => 3], + ['template' => 'template_3', 'priority' => 2], + ]; + } + + return null; + }); + + $renderer = new AttributeBlockRenderer($configResolver); $renderer->setTwig($environment); - $renderer->setBaseTemplate('the_base_template'); - $renderer->setAttributeDefinitionViewResources([ - ['template' => 'template_1', 'priority' => 1], - ['template' => 'template_2', 'priority' => 3], - ['template' => 'template_3', 'priority' => 2], - ]); $this->assertEquals($integerBlock, $renderer->renderAttributeDefinitionView('integer', $integerDefinition, $integerParams)); $this->assertEquals($stringBlock, $renderer->renderAttributeDefinitionView('string', $stringDefinition, $stringParams)); @@ -181,16 +206,33 @@ public function testLocalTemplates() $attributeBlock = ['integer block']; $definitionBlock = ['integer block']; - $renderer = new AttributeBlockRenderer(); + $configResolver = $this->createMock(ConfigResolverInterface::class); + $configResolver->method('getParameter')->willReturnCallback(static function ($parameter) { + switch ($parameter) { + case 'enhanced_relation_list.base_template': + return 'the_base_template'; + case 'enhanced_relation_list.attribute_templates': + return []; + case 'enhanced_relation_list.attribute_definition_templates': + return [ + ['template' => 'template_1', 'priority' => 1], + ['template' => 'template_2', 'priority' => 3], + ['template' => 'template_3', 'priority' => 2], + ]; + } + + return null; + }); + + $renderer = new AttributeBlockRenderer($configResolver); $renderer->setTwig($environment); - $renderer->setBaseTemplate('the_base_template'); $integerAttribute = new Integer(['value' => 312]); $integerDefinition = ['attribute_definition']; $integerParams = ['some_parameter' => 'integer']; $environment->method('loadTemplate')->willReturnCallback( - function ($templateName) use ($templateList) { + function ($ignored, $templateName) use ($templateList) { return $templateList[$templateName]; } ); diff --git a/tests/Templating/Twig/Extension/RelationAttributeExtensionTest.php b/tests/Templating/Twig/Extension/RelationAttributeExtensionTest.php index 20668c1..a35a36d 100644 --- a/tests/Templating/Twig/Extension/RelationAttributeExtensionTest.php +++ b/tests/Templating/Twig/Extension/RelationAttributeExtensionTest.php @@ -18,6 +18,7 @@ use eZ\Publish\Core\Repository\Values\Content\Content; use eZ\Publish\Core\Repository\Values\ContentType\ContentType; use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; +use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinitionCollection; use eZ\Publish\SPI\Persistence\Content\ContentInfo; use eZ\Publish\SPI\Persistence\Content\VersionInfo; use IntProg\EnhancedRelationListBundle\Core\FieldType\Attribute\Integer; @@ -73,7 +74,7 @@ public function testRenderAttribute() ]), ]), 'contentType' => new ContentType([ - 'fieldDefinitions' => [ + 'fieldDefinitions' => new FieldDefinitionCollection([ new FieldDefinition([ 'identifier' => 'relation_field', 'fieldSettings' => [ @@ -82,7 +83,7 @@ public function testRenderAttribute() ], ], ]), - ], + ]), ]), ]); $attribute1 = new Integer(['value' => 123]); @@ -177,7 +178,7 @@ public function testRenderRelationAttribute() ]), ]), 'contentType' => new ContentType([ - 'fieldDefinitions' => [ + 'fieldDefinitions' => new FieldDefinitionCollection([ new FieldDefinition([ 'identifier' => 'relation_field', 'fieldSettings' => [ @@ -186,7 +187,7 @@ public function testRenderRelationAttribute() ], ], ]), - ], + ]), ]), ]); $attribute = new Integer(['value' => 123]);