From a77a9ddacc741f60800412d85d0fe7c41f53ab78 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 24 Mar 2021 19:18:24 +0200 Subject: [PATCH 001/147] EWPP-854: Add oe_theme_inpage_navigation submodule. --- .../oe_theme_inpage_navigation.info.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml diff --git a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml new file mode 100644 index 000000000..e97406d96 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml @@ -0,0 +1,7 @@ +name: 'OpenEuropa Theme Inpage Navigation' +type: module +description: 'Module for inpage navigation functionality' +package: OpenEuropa +core: 8.x +dependencies: + - emr_node:emr_node From 5e36eceb5c8b43db962aeea7391798c330b8acde Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 24 Mar 2021 19:21:24 +0200 Subject: [PATCH 002/147] EWPP-854: Add inpage_navigation plugin with config. --- composer.json | 1 + ...y_meta_type.oe_theme_inpage_navigation.yml | 5 + ..._navigation.oe_theme_inpage_navigation.yml | 23 +++++ ...entity_meta.oe_theme_inpage_navigation.yml | 17 ++++ .../src/InPageNavigationHelper.php | 54 ++++++++++ .../src/InPageNavigationWrapper.php | 34 +++++++ .../EntityMetaRelation/InPageNavigation.php | 99 +++++++++++++++++++ 7 files changed, 233 insertions(+) create mode 100644 modules/oe_theme_inpage_navigation/config/install/emr.entity_meta_type.oe_theme_inpage_navigation.yml create mode 100644 modules/oe_theme_inpage_navigation/config/install/field.field.entity_meta.oe_theme_inpage_navigation.oe_theme_inpage_navigation.yml create mode 100644 modules/oe_theme_inpage_navigation/config/install/field.storage.entity_meta.oe_theme_inpage_navigation.yml create mode 100644 modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php create mode 100644 modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php create mode 100644 modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php diff --git a/composer.json b/composer.json index c8ff6727e..d82464bd4 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "drupal/description_list_field": "~1.0.x-dev", "drupal/drupal-driver": "~2.0.0-alpha6", "drupal/drupal-extension": "~4.0", + "drupal/emr": "~1.0-beta9", "drupal/entity_reference_revisions": "~1.3", "drupal/entity_browser": "^2.5", "drupal/extra_field": "^1.1", diff --git a/modules/oe_theme_inpage_navigation/config/install/emr.entity_meta_type.oe_theme_inpage_navigation.yml b/modules/oe_theme_inpage_navigation/config/install/emr.entity_meta_type.oe_theme_inpage_navigation.yml new file mode 100644 index 000000000..b9ed175a3 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/config/install/emr.entity_meta_type.oe_theme_inpage_navigation.yml @@ -0,0 +1,5 @@ +langcode: en +status: true +dependencies: { } +id: oe_theme_inpage_navigation +label: 'Inpage navigation' diff --git a/modules/oe_theme_inpage_navigation/config/install/field.field.entity_meta.oe_theme_inpage_navigation.oe_theme_inpage_navigation.yml b/modules/oe_theme_inpage_navigation/config/install/field.field.entity_meta.oe_theme_inpage_navigation.oe_theme_inpage_navigation.yml new file mode 100644 index 000000000..bd99f8cf7 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/config/install/field.field.entity_meta.oe_theme_inpage_navigation.oe_theme_inpage_navigation.yml @@ -0,0 +1,23 @@ +langcode: en +status: true +dependencies: + config: + - emr.entity_meta_type.oe_theme_inpage_navigation + - field.storage.entity_meta.oe_theme_inpage_navigation +third_party_settings: { } +id: entity_meta.oe_theme_inpage_navigation.oe_theme_inpage_navigation +field_name: oe_theme_inpage_navigation +entity_type: entity_meta +bundle: oe_theme_inpage_navigation +label: 'Inpage navigation' +description: '' +required: false +translatable: false +default_value: + - + value: 0 +default_value_callback: '' +settings: + on_label: 'Yes' + off_label: 'No' +field_type: boolean diff --git a/modules/oe_theme_inpage_navigation/config/install/field.storage.entity_meta.oe_theme_inpage_navigation.yml b/modules/oe_theme_inpage_navigation/config/install/field.storage.entity_meta.oe_theme_inpage_navigation.yml new file mode 100644 index 000000000..7d7a2185f --- /dev/null +++ b/modules/oe_theme_inpage_navigation/config/install/field.storage.entity_meta.oe_theme_inpage_navigation.yml @@ -0,0 +1,17 @@ +langcode: en +status: true +dependencies: + module: + - emr +id: entity_meta.oe_theme_inpage_navigation +field_name: oe_theme_inpage_navigation +entity_type: entity_meta +type: boolean +settings: { } +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php b/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php new file mode 100644 index 000000000..0bb0fafcb --- /dev/null +++ b/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php @@ -0,0 +1,54 @@ +get('emr_entity_metas'); + + /** @var \Drupal\emr\Entity\EntityMetaInterface $entity_meta */ + $entity_meta = $entity_meta_list->getEntityMeta('oe_theme_inpage_navigation'); + + /** @var \Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper $entity_meta_wrapper */ + $entity_meta_wrapper = $entity_meta->getWrapper(); + return $entity_meta_wrapper->isInPageNavigation(); + } + + /** + * Sets a node with inpage navigation. + * + * @param \Drupal\node\NodeInterface $node + * The node. + */ + public static function setInPageNavigation(NodeInterface $node): void { + /** @var \Drupal\emr\Field\EntityMetaItemListInterface $entity_meta_list */ + $entity_meta_list = $node->get('emr_entity_metas'); + + /** @var \Drupal\emr\Entity\EntityMetaInterface $entity_meta */ + $entity_meta = $entity_meta_list->getEntityMeta('oe_theme_inpage_navigation'); + + /** @var \Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper $entity_meta_wrapper */ + $entity_meta_wrapper = $entity_meta->getWrapper(); + $entity_meta_wrapper->setInPageNavigation(TRUE); + $entity_meta_list->attach($entity_meta); + } + +} diff --git a/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php b/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php new file mode 100644 index 000000000..a2438cb1b --- /dev/null +++ b/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php @@ -0,0 +1,34 @@ +entityMeta->get('oe_theme_inpage_navigation')->value; + } + + /** + * Sets whether the content with inpage navigation or not. + * + * @param bool $value + * Whether it is content with inpage navigation or not. + */ + public function setInPageNavigation(bool $value): void { + $this->entityMeta->set('oe_theme_inpage_navigation', $value); + } + +} diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php b/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php new file mode 100644 index 000000000..3745b0bc8 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php @@ -0,0 +1,99 @@ +getFormKey(); + $this->buildFormContainer($form, $form_state, $key); + + $entity_meta_bundle = $this->getPluginDefinition()['entity_meta_bundle']; + + /** @var \Drupal\emr\Field\EntityMetaItemListInterface $entity_meta_list */ + $entity_meta_list = $entity->get('emr_entity_metas'); + /** @var \Drupal\emr\Entity\EntityMetaInterface $entity_meta */ + $entity_meta = $entity_meta_list->getEntityMeta($entity_meta_bundle); + /** @var \Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper $entity_meta_wrapper */ + $entity_meta_wrapper = $entity_meta->getWrapper(); + + $form[$key]['inpage_navigation'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Enable Inpage navigation'), + '#description' => $this->t('Show this content with vertical menu containing (anchored) links to H2-headings on long content pages.'), + '#default_value' => $entity_meta_wrapper->isInPageNavigation(), + ]; + + // Set the entity meta so we use it in the submit handler. + $form_state->set($entity_meta_bundle . '_entity_meta', $entity_meta); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, FormStateInterface $form_state): void { + /** @var \Drupal\Core\Entity\ContentEntityInterface $host_entity */ + $host_entity = $form_state->getFormObject()->getEntity(); + $entity_meta_bundle = $this->getPluginDefinition()['entity_meta_bundle']; + + /** @var \Drupal\emr\Entity\EntityMetaInterface $entity_meta */ + $entity_meta = $form_state->get($entity_meta_bundle . '_entity_meta'); + /** @var \Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper $entity_meta_wrapper */ + $entity_meta_wrapper = $entity_meta->getWrapper(); + + $inpage_navigation = (bool) $form_state->getValue('inpage_navigation'); + // If the entity meta is new, it means we only want to set and save the + // meta if the form was checked. + if ($entity_meta->isNew() && $inpage_navigation) { + $entity_meta_wrapper->setInPageNavigation(TRUE); + // Attach it to the host entity since the checkbox was checked for the + // first time. + $host_entity->get('emr_entity_metas')->attach($entity_meta); + return; + } + + // If the entity meta is not new, we set the value regardless of checkbox + // choice. + if (!$entity_meta->isNew()) { + $entity_meta_wrapper->setInPageNavigation($inpage_navigation); + $host_entity->get('emr_entity_metas')->attach($entity_meta); + } + } + + /** + * {@inheritdoc} + */ + public function fillDefaultEntityMetaValues(EntityMetaInterface $entity_meta): void { + // We don't want the meta to be created/filled in by default. + } + +} From 772df196a5a8afa882e82340ee1aac26978090ea Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 24 Mar 2021 19:23:59 +0200 Subject: [PATCH 003/147] EWPP-854: Add tests for inpage_navigation plugin. --- .../oe_theme_inpage_navigation.info.yml | 3 +- .../InPageNavigationTest.php | 94 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php diff --git a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml index e97406d96..0652e28d3 100644 --- a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml +++ b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml @@ -4,4 +4,5 @@ description: 'Module for inpage navigation functionality' package: OpenEuropa core: 8.x dependencies: - - emr_node:emr_node + - drupal:node + - entity_meta_relation:emr_node diff --git a/modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php b/modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php new file mode 100644 index 000000000..4f0796ce5 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php @@ -0,0 +1,94 @@ +type = 'test_content_type'; + $this->drupalCreateContentType(['name' => 'Test node type', 'type' => $this->type]); + + /** @var \Drupal\emr\EntityMetaRelationInstaller $installer */ + $installer = \Drupal::service('emr.installer'); + $installer->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', [$this->type]); + + } + + /** + * Test form of inpage navigation entity meta relation plugin. + */ + public function testInPageNavigationForm(): void { + $entity_meta_storage = \Drupal::entityTypeManager()->getStorage('entity_meta'); + + // Assert we have no entity metas with the inpage navigation plugin. + $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + + $this->drupalLogin($this->rootUser); + $this->drupalGet('/node/add/' . $this->type); + $this->assertElementPresent('.form-item-inpage-navigation input#edit-inpage-navigation'); + $this->assertSession()->checkboxNotChecked('Enable Inpage navigation'); + $this->assertSession()->pageTextContainsOnce('Show this content with vertical menu containing (anchored) links to H2-headings on long content pages.'); + + // Create the node, without enabled the inpage navigation. + $this->getSession()->getPage()->fillField('Title', 'The title of the page'); + $this->getSession()->getPage()->pressButton('Save'); + $this->assertSession()->pageTextContainsOnce('Test node type The title of the page has been created.'); + + $node = $this->getNodeByTitle('The title of the page'); + + // Assert we still have no entity metas with the inpage_navigation plugin. + $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertFalse(InPageNavigationHelper::isInPageNavigation($node)); + + $this->drupalGet($node->toUrl('edit-form')); + $this->getSession()->getPage()->checkField('Enable Inpage navigation'); + $this->getSession()->getPage()->pressButton('Save'); + + // Assert we now have one entity metas with the inpage_navigation plugin. + $node = $this->getNodeByTitle('The title of the page', TRUE); + $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertTrue(InPageNavigationHelper::isInPageNavigation($node)); + + $this->drupalGet($node->toUrl('edit-form')); + $this->getSession()->getPage()->uncheckField('Enable Inpage navigation'); + $this->getSession()->getPage()->pressButton('Save'); + + // We still have one entity meta with the inpage_navigation plugin, as a new + // revision got created. + $node = $this->getNodeByTitle('The title of the page', TRUE); + $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertFalse(InPageNavigationHelper::isInPageNavigation($node)); + } + +} From bb4b1ed2851be72257d10dbf03b9521ba358a602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A2ni=20Borges=20de=20Freitas?= Date: Tue, 30 Mar 2021 17:33:36 +0100 Subject: [PATCH 004/147] EWPP-854: Alter the UI and logic used to rely by default on 3rd party settings. --- .../oe_theme_inpage_navigation.schema.yml | 8 + .../oe_theme_inpage_navigation.info.yml | 4 +- .../src/InPageNavigationHelper.php | 24 ++- .../src/InPageNavigationWrapper.php | 8 +- .../EntityMetaRelation/InPageNavigation.php | 39 ++-- .../InPageNavigationTest.php | 94 ---------- .../InPageNavigationTest.php | 168 ++++++++++++++++++ 7 files changed, 226 insertions(+), 119 deletions(-) create mode 100644 modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml delete mode 100644 modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php create mode 100644 modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/Plugin/EntityMetaRelation/InPageNavigationTest.php diff --git a/modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml b/modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml new file mode 100644 index 000000000..398bb1d6b --- /dev/null +++ b/modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml @@ -0,0 +1,8 @@ +node.type.*.third_party.oe_theme_inpage_navigation: + type: mapping + label: 'Navigation block settings' + mapping: + enabled: + type: boolean + label: 'Whether to enable in-page navigation for this content type.' + diff --git a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml index 0652e28d3..be2378a5f 100644 --- a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml +++ b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.info.yml @@ -1,6 +1,6 @@ -name: 'OpenEuropa Theme Inpage Navigation' +name: 'OpenEuropa Theme In-page Navigation' type: module -description: 'Module for inpage navigation functionality' +description: 'Module for in-page navigation functionality' package: OpenEuropa core: 8.x dependencies: diff --git a/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php b/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php index 0bb0fafcb..3bd138201 100644 --- a/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php +++ b/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php @@ -12,7 +12,17 @@ class InPageNavigationHelper { /** - * Returns if a given node with inpage navigation. + * Returns default setting for inpage nav for the node bundle. + * + * @param \Drupal\node\NodeInterface $node + * The node. + */ + public static function getDefaultInPageNavigationSettings(NodeInterface $node): bool { + return $node->type->entity->getThirdPartySetting('oe_theme_inpage_navigation', 'enabled', FALSE); + } + + /** + * Returns whether a given node has in-page navigation enabled. * * @param \Drupal\node\NodeInterface $node * The node. @@ -20,7 +30,7 @@ class InPageNavigationHelper { * @return bool * Whether it's content with inpage navigation. */ - public static function isInPageNavigation(NodeInterface $node): bool { + public static function isInPageNavigationEnabled(NodeInterface $node): bool { /** @var \Drupal\emr\Field\EntityMetaItemListInterface $entity_meta_list */ $entity_meta_list = $node->get('emr_entity_metas'); @@ -29,11 +39,17 @@ public static function isInPageNavigation(NodeInterface $node): bool { /** @var \Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper $entity_meta_wrapper */ $entity_meta_wrapper = $entity_meta->getWrapper(); - return $entity_meta_wrapper->isInPageNavigation(); + + if ($entity_meta->isNew()) { + return self::getDefaultInPageNavigationSettings($entity_meta->getHostEntity()); + } + else { + return $entity_meta_wrapper->isInPageNavigationEnabled(); + } } /** - * Sets a node with inpage navigation. + * Enables in-page navigation on a given node. * * @param \Drupal\node\NodeInterface $node * The node. diff --git a/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php b/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php index a2438cb1b..39c3c4c69 100644 --- a/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php +++ b/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php @@ -15,17 +15,17 @@ class InPageNavigationWrapper extends EntityMetaWrapper { * Checks whether the content is configured to be with inpage navigation. * * @return bool - * Whether it shows the children. + * Whether it has in-page navigation enabled. */ - public function isInPageNavigation(): bool { + public function isInPageNavigationEnabled(): bool { return (bool) $this->entityMeta->get('oe_theme_inpage_navigation')->value; } /** - * Sets whether the content with inpage navigation or not. + * Sets in-page navigation setting for the node. * * @param bool $value - * Whether it is content with inpage navigation or not. + * Whether it has in-page navigation enabled. */ public function setInPageNavigation(bool $value): void { $this->entityMeta->set('oe_theme_inpage_navigation', $value); diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php b/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php index 3745b0bc8..4ebe18242 100644 --- a/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php +++ b/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php @@ -10,16 +10,17 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\emr\Entity\EntityMetaInterface; use Drupal\emr\Plugin\EntityMetaRelationContentFormPluginBase; +use Drupal\oe_theme_inpage_navigation\InPageNavigationHelper; /** * Provides an entity meta plugin to store if a node with inpage navigation. * * @EntityMetaRelation( * id = "inpage_navigation", - * label = @Translation("Inpage Navigation"), + * label = @Translation("In-page Navigation"), * entity_meta_bundle = "oe_theme_inpage_navigation", * content_form = TRUE, - * description = @Translation("Allows to configure a node with inpage navigation."), + * description = @Translation("Allows to configure a node with in-page navigation."), * entity_meta_wrapper_class = "\Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper", * ) */ @@ -44,11 +45,22 @@ public function build(array $form, FormStateInterface $form_state, ContentEntity /** @var \Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper $entity_meta_wrapper */ $entity_meta_wrapper = $entity_meta->getWrapper(); + $form[$key]['override_inpage_navigation'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Override default settings'), + '#description' => InPageNavigationHelper::getDefaultInPageNavigationSettings($entity) ? $this->t('Enabled by default.') : $this->t('Disabled by default.'), + '#default_value' => !$entity_meta->isNew(), + ]; + $form[$key]['inpage_navigation'] = [ '#type' => 'checkbox', - '#title' => $this->t('Enable Inpage navigation'), - '#description' => $this->t('Show this content with vertical menu containing (anchored) links to H2-headings on long content pages.'), - '#default_value' => $entity_meta_wrapper->isInPageNavigation(), + '#title' => $this->t('Enable in-page navigation on this page'), + '#default_value' => $entity_meta_wrapper->isInPageNavigationEnabled(), + '#states' => [ + 'visible' => [ + ':input[name="override_inpage_navigation"]' => ['checked' => TRUE], + ], + ], ]; // Set the entity meta so we use it in the submit handler. @@ -70,22 +82,19 @@ public function submit(array $form, FormStateInterface $form_state): void { /** @var \Drupal\oe_theme_inpage_navigation\InPageNavigationWrapper $entity_meta_wrapper */ $entity_meta_wrapper = $entity_meta->getWrapper(); + $override_inpage_navigation = (bool) $form_state->getValue('override_inpage_navigation'); $inpage_navigation = (bool) $form_state->getValue('inpage_navigation'); - // If the entity meta is new, it means we only want to set and save the - // meta if the form was checked. - if ($entity_meta->isNew() && $inpage_navigation) { - $entity_meta_wrapper->setInPageNavigation(TRUE); + // Set the value in case the override checkbox has been checked. + if ($override_inpage_navigation) { + $entity_meta_wrapper->setInPageNavigation($inpage_navigation); // Attach it to the host entity since the checkbox was checked for the // first time. $host_entity->get('emr_entity_metas')->attach($entity_meta); return; } - - // If the entity meta is not new, we set the value regardless of checkbox - // choice. - if (!$entity_meta->isNew()) { - $entity_meta_wrapper->setInPageNavigation($inpage_navigation); - $host_entity->get('emr_entity_metas')->attach($entity_meta); + elseif (!$entity_meta->isNew() && !$override_inpage_navigation) { + $host_entity->get('emr_entity_metas')->detach($entity_meta); + return; } } diff --git a/modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php b/modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php deleted file mode 100644 index 4f0796ce5..000000000 --- a/modules/oe_theme_inpage_navigation/tests/src/Functional/Plugin/EntityMetaRelation/InPageNavigationTest.php +++ /dev/null @@ -1,94 +0,0 @@ -type = 'test_content_type'; - $this->drupalCreateContentType(['name' => 'Test node type', 'type' => $this->type]); - - /** @var \Drupal\emr\EntityMetaRelationInstaller $installer */ - $installer = \Drupal::service('emr.installer'); - $installer->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', [$this->type]); - - } - - /** - * Test form of inpage navigation entity meta relation plugin. - */ - public function testInPageNavigationForm(): void { - $entity_meta_storage = \Drupal::entityTypeManager()->getStorage('entity_meta'); - - // Assert we have no entity metas with the inpage navigation plugin. - $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - - $this->drupalLogin($this->rootUser); - $this->drupalGet('/node/add/' . $this->type); - $this->assertElementPresent('.form-item-inpage-navigation input#edit-inpage-navigation'); - $this->assertSession()->checkboxNotChecked('Enable Inpage navigation'); - $this->assertSession()->pageTextContainsOnce('Show this content with vertical menu containing (anchored) links to H2-headings on long content pages.'); - - // Create the node, without enabled the inpage navigation. - $this->getSession()->getPage()->fillField('Title', 'The title of the page'); - $this->getSession()->getPage()->pressButton('Save'); - $this->assertSession()->pageTextContainsOnce('Test node type The title of the page has been created.'); - - $node = $this->getNodeByTitle('The title of the page'); - - // Assert we still have no entity metas with the inpage_navigation plugin. - $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->assertFalse(InPageNavigationHelper::isInPageNavigation($node)); - - $this->drupalGet($node->toUrl('edit-form')); - $this->getSession()->getPage()->checkField('Enable Inpage navigation'); - $this->getSession()->getPage()->pressButton('Save'); - - // Assert we now have one entity metas with the inpage_navigation plugin. - $node = $this->getNodeByTitle('The title of the page', TRUE); - $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->assertTrue(InPageNavigationHelper::isInPageNavigation($node)); - - $this->drupalGet($node->toUrl('edit-form')); - $this->getSession()->getPage()->uncheckField('Enable Inpage navigation'); - $this->getSession()->getPage()->pressButton('Save'); - - // We still have one entity meta with the inpage_navigation plugin, as a new - // revision got created. - $node = $this->getNodeByTitle('The title of the page', TRUE); - $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->assertFalse(InPageNavigationHelper::isInPageNavigation($node)); - } - -} diff --git a/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/Plugin/EntityMetaRelation/InPageNavigationTest.php b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/Plugin/EntityMetaRelation/InPageNavigationTest.php new file mode 100644 index 000000000..278d46d9e --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/Plugin/EntityMetaRelation/InPageNavigationTest.php @@ -0,0 +1,168 @@ +typeWithoutInpageNav = 'test_content_type_without_inpage'; + $this->drupalCreateContentType(['name' => 'Test node type', 'type' => $this->typeWithoutInpageNav]); + + // Create content type with in-page navigation. + $this->typeWithInpageNav = 'test_content_type_with_inpage'; + $ct_with = $this->drupalCreateContentType(['name' => 'Test node type', 'type' => $this->typeWithInpageNav]); + $ct_with->setThirdPartySetting('oe_theme_inpage_navigation', 'enabled', TRUE); + $ct_with->save(); + + /** @var \Drupal\emr\EntityMetaRelationInstaller $installer */ + $installer = \Drupal::service('emr.installer'); + $installer->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', [$this->typeWithInpageNav, $this->typeWithoutInpageNav]); + } + + /** + * Test form of inpage navigation entity meta relation plugin. + */ + public function testInPageNavigationForm(): void { + $entity_meta_storage = \Drupal::entityTypeManager()->getStorage('entity_meta'); + $node_storage = \Drupal::entityTypeManager()->getStorage('node'); + + // Assert we have no entity metas with the inpage navigation plugin. + $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + + $this->drupalLogin($this->rootUser); + $this->drupalGet('/node/add/' . $this->typeWithoutInpageNav); + $this->assertElementPresent('.form-item-inpage-navigation input#edit-inpage-navigation'); + $this->clickLink('In-page Navigation'); + $this->assertSession()->checkboxNotChecked('Override default settings'); + $this->assertSession()->pageTextContains('Disabled by default'); + $this->assertFalse($this->getSession()->getPage()->findField('Enable in-page navigation on this page')->isVisible()); + $this->assertSession()->checkboxNotChecked('Enable in-page navigation on this page'); + + // Create the node, without enabling the inpage navigation. + $this->getSession()->getPage()->fillField('Title', 'The title of the page'); + $this->getSession()->getPage()->pressButton('Save'); + $this->assertSession()->pageTextContainsOnce('Test node type The title of the page has been created.'); + + $node = $this->getNodeByTitle('The title of the page'); + + // Assert we still have no entity metas with the inpage_navigation plugin. + $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node)); + + $this->drupalGet($node->toUrl('edit-form')); + $this->clickLink('In-page Navigation'); + $this->getSession()->getPage()->checkField('Override default settings'); + $this->getSession()->getPage()->checkField('Enable in-page navigation on this page'); + $this->getSession()->getPage()->pressButton('Save'); + + // Assert we now have one entity metas with the inpage_navigation plugin. + $node = $this->getNodeByTitle('The title of the page', TRUE); + $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node)); + + $this->drupalGet($node->toUrl('edit-form')); + $this->clickLink('In-page Navigation'); + $this->assertTrue($this->getSession()->getPage()->findField('Enable in-page navigation on this page')->isVisible()); + $this->getSession()->getPage()->uncheckField('Enable in-page navigation on this page'); + $this->getSession()->getPage()->pressButton('Save'); + + // We still have one entity meta with the inpage_navigation plugin, as a new + // revision got created. + $node = $this->getNodeByTitle('The title of the page', TRUE); + $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node)); + + // Test the other content type. + $this->drupalGet('/node/add/' . $this->typeWithInpageNav); + $this->assertElementPresent('.form-item-inpage-navigation input#edit-inpage-navigation'); + $this->clickLink('In-page Navigation'); + $this->assertSession()->checkboxNotChecked('Override default settings'); + $this->assertSession()->pageTextContains('Enabled by default'); + $this->assertSession()->checkboxNotChecked('Enable in-page navigation on this page'); + + // Create the node, with the inpage navigation enabled by default. + $this->getSession()->getPage()->fillField('Title', 'The title of the page with in-page navigation'); + $this->getSession()->getPage()->pressButton('Save'); + $this->assertSession()->pageTextContainsOnce('Test node type The title of the page with in-page navigation has been created.'); + + $node_with_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); + + // Assert we keep having same number of entity metas, none was created. + $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_with_navbar)); + + $this->drupalGet($node_with_navbar->toUrl('edit-form')); + $this->clickLink('In-page Navigation'); + $this->getSession()->getPage()->checkField('Override default settings'); + $this->getSession()->getPage()->uncheckField('Enable in-page navigation on this page'); + $this->getSession()->getPage()->pressButton('Save'); + + $node_storage->resetCache([$node_with_navbar->id()]); + $node_without_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); + $this->assertCount(2, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node_without_navbar)); + + // Edit again and enable in-page navigation. + $this->drupalGet($node_with_navbar->toUrl('edit-form')); + $this->clickLink('In-page Navigation'); + $this->getSession()->getPage()->checkField('Override default settings'); + $this->getSession()->getPage()->checkField('Enable in-page navigation on this page'); + $this->getSession()->getPage()->pressButton('Save'); + + $node_storage->resetCache([$node_with_navbar->id()]); + $node_without_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); + $this->assertCount(2, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_without_navbar)); + + // Edit again and disable override, should be still visible. + $this->drupalGet($node_with_navbar->toUrl('edit-form')); + $this->clickLink('In-page Navigation'); + $this->getSession()->getPage()->uncheckField('Override default settings'); + $this->assertFalse($this->getSession()->getPage()->findField('Enable in-page navigation on this page')->isVisible()); + $this->getSession()->getPage()->pressButton('Save'); + + $node_storage->resetCache([$node_with_navbar->id()]); + $node_without_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); + $this->assertCount(2, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); + $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_without_navbar)); + } + +} From 6bd9f5f7bba50557edb9101ff3cf4d3883a935d0 Mon Sep 17 00:00:00 2001 From: upchuk Date: Wed, 31 Mar 2021 15:49:03 +0300 Subject: [PATCH 005/147] EWPP-854: Code cleanup and readme. --- modules/oe_theme_inpage_navigation/README.md | 23 +++++++++ .../src/InPageNavigationHelper.php | 22 +++++---- .../src/InPageNavigationWrapper.php | 4 +- .../EntityMetaRelation/InPageNavigation.php | 9 ++-- .../InPageNavigationTest.php | 49 ++++++++++--------- 5 files changed, 66 insertions(+), 41 deletions(-) create mode 100644 modules/oe_theme_inpage_navigation/README.md rename modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/{Plugin/EntityMetaRelation => }/InPageNavigationTest.php (84%) diff --git a/modules/oe_theme_inpage_navigation/README.md b/modules/oe_theme_inpage_navigation/README.md new file mode 100644 index 000000000..674cacd05 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/README.md @@ -0,0 +1,23 @@ +# OpenEuropa Theme In-Page Naviation + +This module provides In-page navigation capability to your content types. + +## Installation + +To install the in-page navigation plugin on a given content type, you need to +run once the following: + +``` +$bundle = 'your_content_type'; +/** @var \Drupal\emr\EntityMetaRelationInstaller $installer */ +$installer = \Drupal::service('emr.installer'); +$installer->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', [$bundle]); +``` + +## Requirements + +This module requires Entity Meta Relation which you can install like so: + +```bash +$ composer require drupal/emr +``` diff --git a/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php b/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php index 3bd138201..2d1842c40 100644 --- a/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php +++ b/modules/oe_theme_inpage_navigation/src/InPageNavigationHelper.php @@ -7,18 +7,21 @@ use Drupal\node\NodeInterface; /** - * Helper class for the inpage navigation functionality. + * Helper class for the in-page navigation functionality. */ class InPageNavigationHelper { /** - * Returns default setting for inpage nav for the node bundle. + * Returns default setting for in-page nav for the node bundle. * * @param \Drupal\node\NodeInterface $node * The node. + * + * @return bool + * Whether the in-page nav is enabled in a node by default. */ - public static function getDefaultInPageNavigationSettings(NodeInterface $node): bool { - return $node->type->entity->getThirdPartySetting('oe_theme_inpage_navigation', 'enabled', FALSE); + public static function isInPageNavigationEnabledByDefault(NodeInterface $node): bool { + return $node->get('type')->entity->getThirdPartySetting('oe_theme_inpage_navigation', 'enabled', FALSE); } /** @@ -28,7 +31,7 @@ public static function getDefaultInPageNavigationSettings(NodeInterface $node): * The node. * * @return bool - * Whether it's content with inpage navigation. + * Whether in-page navigation is enabled or not. */ public static function isInPageNavigationEnabled(NodeInterface $node): bool { /** @var \Drupal\emr\Field\EntityMetaItemListInterface $entity_meta_list */ @@ -41,11 +44,10 @@ public static function isInPageNavigationEnabled(NodeInterface $node): bool { $entity_meta_wrapper = $entity_meta->getWrapper(); if ($entity_meta->isNew()) { - return self::getDefaultInPageNavigationSettings($entity_meta->getHostEntity()); - } - else { - return $entity_meta_wrapper->isInPageNavigationEnabled(); + return self::isInPageNavigationEnabledByDefault($entity_meta->getHostEntity()); } + + return $entity_meta_wrapper->isInPageNavigationEnabled(); } /** @@ -54,7 +56,7 @@ public static function isInPageNavigationEnabled(NodeInterface $node): bool { * @param \Drupal\node\NodeInterface $node * The node. */ - public static function setInPageNavigation(NodeInterface $node): void { + public static function enableInPageNavigation(NodeInterface $node): void { /** @var \Drupal\emr\Field\EntityMetaItemListInterface $entity_meta_list */ $entity_meta_list = $node->get('emr_entity_metas'); diff --git a/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php b/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php index 39c3c4c69..9d845ea61 100644 --- a/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php +++ b/modules/oe_theme_inpage_navigation/src/InPageNavigationWrapper.php @@ -7,7 +7,7 @@ use Drupal\emr\EntityMetaWrapper; /** - * Wrapper for the inpage navigation plugins. + * Wrapper for the in-page navigation plugin. */ class InPageNavigationWrapper extends EntityMetaWrapper { @@ -25,7 +25,7 @@ public function isInPageNavigationEnabled(): bool { * Sets in-page navigation setting for the node. * * @param bool $value - * Whether it has in-page navigation enabled. + * Whether to have in-page navigation enabled. */ public function setInPageNavigation(bool $value): void { $this->entityMeta->set('oe_theme_inpage_navigation', $value); diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php b/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php index 4ebe18242..7b3124264 100644 --- a/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php +++ b/modules/oe_theme_inpage_navigation/src/Plugin/EntityMetaRelation/InPageNavigation.php @@ -13,7 +13,7 @@ use Drupal\oe_theme_inpage_navigation\InPageNavigationHelper; /** - * Provides an entity meta plugin to store if a node with inpage navigation. + * Provides an entity meta plugin to store if a node has in-page navigation. * * @EntityMetaRelation( * id = "inpage_navigation", @@ -48,7 +48,7 @@ public function build(array $form, FormStateInterface $form_state, ContentEntity $form[$key]['override_inpage_navigation'] = [ '#type' => 'checkbox', '#title' => $this->t('Override default settings'), - '#description' => InPageNavigationHelper::getDefaultInPageNavigationSettings($entity) ? $this->t('Enabled by default.') : $this->t('Disabled by default.'), + '#description' => InPageNavigationHelper::isInPageNavigationEnabledByDefault($entity) ? $this->t('Enabled by default.') : $this->t('Disabled by default.'), '#default_value' => !$entity_meta->isNew(), ]; @@ -87,12 +87,11 @@ public function submit(array $form, FormStateInterface $form_state): void { // Set the value in case the override checkbox has been checked. if ($override_inpage_navigation) { $entity_meta_wrapper->setInPageNavigation($inpage_navigation); - // Attach it to the host entity since the checkbox was checked for the - // first time. $host_entity->get('emr_entity_metas')->attach($entity_meta); return; } - elseif (!$entity_meta->isNew() && !$override_inpage_navigation) { + + if (!$entity_meta->isNew() && !$override_inpage_navigation) { $host_entity->get('emr_entity_metas')->detach($entity_meta); return; } diff --git a/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/Plugin/EntityMetaRelation/InPageNavigationTest.php b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationTest.php similarity index 84% rename from modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/Plugin/EntityMetaRelation/InPageNavigationTest.php rename to modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationTest.php index 278d46d9e..4a84b37bc 100644 --- a/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/Plugin/EntityMetaRelation/InPageNavigationTest.php +++ b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationTest.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace Drupal\Tests\oe_theme_inpage_navigation\FunctionalJavascript\Plugin\EntityMetaRelation; +namespace Drupal\Tests\oe_theme_inpage_navigation\FunctionalJavascript; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\oe_theme_inpage_navigation\InPageNavigationHelper; @@ -16,14 +16,14 @@ class InPageNavigationTest extends WebDriverTestBase { use NodeCreationTrait; /** - * The node type id for ct with in-page nav. + * The node type id for a CT with in-page nav set by default. * * @var string */ protected $typeWithInpageNav; /** - * The node type id for ct without in-page nav. + * The node type id for a CT without in-page nav. * * @var string */ @@ -58,7 +58,7 @@ public function setUp() { } /** - * Test form of inpage navigation entity meta relation plugin. + * Test in-page entity meta relation plugin. */ public function testInPageNavigationForm(): void { $entity_meta_storage = \Drupal::entityTypeManager()->getStorage('entity_meta'); @@ -67,7 +67,8 @@ public function testInPageNavigationForm(): void { // Assert we have no entity metas with the inpage navigation plugin. $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->drupalLogin($this->rootUser); + $user = $this->createUser([], '', TRUE); + $this->drupalLogin($user); $this->drupalGet('/node/add/' . $this->typeWithoutInpageNav); $this->assertElementPresent('.form-item-inpage-navigation input#edit-inpage-navigation'); $this->clickLink('In-page Navigation'); @@ -81,24 +82,24 @@ public function testInPageNavigationForm(): void { $this->getSession()->getPage()->pressButton('Save'); $this->assertSession()->pageTextContainsOnce('Test node type The title of the page has been created.'); - $node = $this->getNodeByTitle('The title of the page'); + $node_one = $this->getNodeByTitle('The title of the page'); // Assert we still have no entity metas with the inpage_navigation plugin. $this->assertCount(0, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node)); + $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node_one)); - $this->drupalGet($node->toUrl('edit-form')); + $this->drupalGet($node_one->toUrl('edit-form')); $this->clickLink('In-page Navigation'); $this->getSession()->getPage()->checkField('Override default settings'); $this->getSession()->getPage()->checkField('Enable in-page navigation on this page'); $this->getSession()->getPage()->pressButton('Save'); - // Assert we now have one entity metas with the inpage_navigation plugin. - $node = $this->getNodeByTitle('The title of the page', TRUE); + // Assert we now have one entity meta with the inpage_navigation plugin. + $node_one = $this->getNodeByTitle('The title of the page', TRUE); $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node)); + $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_one)); - $this->drupalGet($node->toUrl('edit-form')); + $this->drupalGet($node_one->toUrl('edit-form')); $this->clickLink('In-page Navigation'); $this->assertTrue($this->getSession()->getPage()->findField('Enable in-page navigation on this page')->isVisible()); $this->getSession()->getPage()->uncheckField('Enable in-page navigation on this page'); @@ -106,9 +107,9 @@ public function testInPageNavigationForm(): void { // We still have one entity meta with the inpage_navigation plugin, as a new // revision got created. - $node = $this->getNodeByTitle('The title of the page', TRUE); + $node_one = $this->getNodeByTitle('The title of the page', TRUE); $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node)); + $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node_one)); // Test the other content type. $this->drupalGet('/node/add/' . $this->typeWithInpageNav); @@ -123,43 +124,43 @@ public function testInPageNavigationForm(): void { $this->getSession()->getPage()->pressButton('Save'); $this->assertSession()->pageTextContainsOnce('Test node type The title of the page with in-page navigation has been created.'); - $node_with_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); + $node_two = $this->getNodeByTitle('The title of the page with in-page navigation'); - // Assert we keep having same number of entity metas, none was created. + // Assert we have the same number of entity metas, none was created. $this->assertCount(1, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); - $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_with_navbar)); + $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_two)); - $this->drupalGet($node_with_navbar->toUrl('edit-form')); + $this->drupalGet($node_two->toUrl('edit-form')); $this->clickLink('In-page Navigation'); $this->getSession()->getPage()->checkField('Override default settings'); - $this->getSession()->getPage()->uncheckField('Enable in-page navigation on this page'); + // The checkbox is not checked so it should save with inpage nav disabled. $this->getSession()->getPage()->pressButton('Save'); - $node_storage->resetCache([$node_with_navbar->id()]); + $node_storage->resetCache([$node_two->id()]); $node_without_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); $this->assertCount(2, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); $this->assertFalse(InPageNavigationHelper::isInPageNavigationEnabled($node_without_navbar)); // Edit again and enable in-page navigation. - $this->drupalGet($node_with_navbar->toUrl('edit-form')); + $this->drupalGet($node_two->toUrl('edit-form')); $this->clickLink('In-page Navigation'); $this->getSession()->getPage()->checkField('Override default settings'); $this->getSession()->getPage()->checkField('Enable in-page navigation on this page'); $this->getSession()->getPage()->pressButton('Save'); - $node_storage->resetCache([$node_with_navbar->id()]); + $node_storage->resetCache([$node_two->id()]); $node_without_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); $this->assertCount(2, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_without_navbar)); // Edit again and disable override, should be still visible. - $this->drupalGet($node_with_navbar->toUrl('edit-form')); + $this->drupalGet($node_two->toUrl('edit-form')); $this->clickLink('In-page Navigation'); $this->getSession()->getPage()->uncheckField('Override default settings'); $this->assertFalse($this->getSession()->getPage()->findField('Enable in-page navigation on this page')->isVisible()); $this->getSession()->getPage()->pressButton('Save'); - $node_storage->resetCache([$node_with_navbar->id()]); + $node_storage->resetCache([$node_two->id()]); $node_without_navbar = $this->getNodeByTitle('The title of the page with in-page navigation'); $this->assertCount(2, $entity_meta_storage->loadByProperties(['bundle' => 'oe_theme_inpage_navigation'])); $this->assertTrue(InPageNavigationHelper::isInPageNavigationEnabled($node_without_navbar)); From 5a562951be3db343a7c37c65e6e43d5cd59f31f8 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Fri, 26 Mar 2021 14:01:19 +0200 Subject: [PATCH 006/147] EWPP-855: Add condition plugin for block with inpage navigation. --- .../Condition/InPageNavigationState.php | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php new file mode 100644 index 000000000..0c8819e75 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php @@ -0,0 +1,101 @@ + NULL, + ] + parent::defaultConfiguration(); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form['inpage_navigation_state'] = [ + '#type' => 'radios', + '#title' => $this->t('Inpage navigation'), + '#default_value' => $this->configuration['inpage_navigation_state'], + '#options' => [$this->t('Disabled'), $this->t('Enabled')], + '#description' => $this->t('Choose with which inpage navigation state this condition should be met.'), + ]; + return parent::buildConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + if ($form_state->hasValue('inpage_navigation_state')) { + $this->configuration['inpage_navigation_state'] = $form_state->getValue('inpage_navigation_state'); + } + parent::submitConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function evaluate() { + $node = $this->getContextValue('node'); + if ($this->configuration['inpage_navigation_state'] === NULL || !$node instanceof NodeInterface) { + return TRUE; + } + + return InPageNavigationHelper::isInPageNavigation($node) === $this->configuration['inpage_navigation_state']; + } + + /** + * {@inheritdoc} + */ + public function summary() { + if (is_null($this->configuration['inpage_navigation_state'])) { + return $this->t('Any inpage navigation state'); + } + + $state = $this->configuration['inpage_navigation_state'] ? $this->t('enabled') : $this->t('disabled'); + if ($this->isNegated()) { + return $this->t('The inpage navigation should not be @state', ['@state' => $state]); + } + + return $this->t('The inpage navigation should be @state', ['@state' => $state]); + } + +} From 25204937373620a91b2e38511cd06e8de6fc8a09 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Fri, 26 Mar 2021 14:05:34 +0200 Subject: [PATCH 007/147] EWPP-855: Add Kernel test for conditional plugin. --- .../Condition/InPageNavigationStateTest.php | 283 ++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php diff --git a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php new file mode 100644 index 000000000..836312334 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php @@ -0,0 +1,283 @@ +installEntitySchema('node'); + $this->installEntitySchema('entity_meta'); + $this->installEntitySchema('entity_meta_relation'); + $this->installSchema('node', ['node_access']); + + $this->installConfig([ + 'emr', + 'emr_node', + 'oe_theme_inpage_navigation', + ]); + } + + /** + * Tests the inpage navigation state condition. + * + * @param bool|null $inpage_navigation_condition + * Inpage navigation state condition. + * @param bool|null $inpage_navigation_condition_negate + * Is negate. + * @param array|null $inpage_navigation_node_state + * Inpage navigation state in node. + * @param array $expected + * Array with expected values of 'summary' and 'result'. + * + * @dataProvider providerTestCondition + */ + public function testCondition(?bool $inpage_navigation_condition, ?bool $inpage_navigation_condition_negate, ?array $inpage_navigation_node_state, array $expected): void { + $manager = \Drupal::service('plugin.manager.condition'); + $condition = $manager->createInstance('oe_theme_inpage_navigation_state'); + $condition->setConfiguration(['inpage_navigation_state' => $inpage_navigation_condition, 'negate' => $inpage_navigation_condition_negate]); + + if ($inpage_navigation_node_state) { + $condition->setContextMapping([ + 'node' => 'node', + ]); + NodeType::create(['type' => 'example', 'name' => 'Example'])->save(); + \Drupal::service('emr.installer')->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['example']); + $node = Node::create(['type' => 'example', 'title' => 'some title']); + $node->save(); + if ($inpage_navigation_node_state['inpage_navigation']) { + InPageNavigationHelper::setInPageNavigation($node); + } + $contexts['node'] = EntityContext::fromEntity($node); + \Drupal::service('context.handler')->applyContextMapping($condition, $contexts); + } + + $this->assertEqual($condition->summary(), new FormattableMarkup($expected['summary'][0], $expected['summary'][1] ?? [])); + $this->assertEqual($condition->execute(), $expected['result']); + } + + /** + * Data provider for testCondition(). + * + * @return array[] + * The test data. + */ + public function providerTestCondition(): array { + return [ + 'empty condition, node w/ active inpage navigation' => [ + 'inpage_navigation_condition' => NULL, + 'inpage_navigation_condition_negate' => NULL, + 'node' => [ + 'inpage_navigation' => TRUE, + ], + 'expected' => [ + 'summary' => ['Any inpage navigation state'], + 'result' => TRUE, + ], + ], + 'empty condition, negative, node w/ active inpage navigation' => [ + 'inpage_navigation_condition' => NULL, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => [ + 'inpage_navigation' => TRUE, + ], + 'expected' => [ + 'summary' => ['Any inpage navigation state'], + 'result' => FALSE, + ], + ], + 'empty condition, node w/o active inpage navigation' => [ + 'inpage_navigation_condition' => NULL, + 'inpage_navigation_condition_negate' => NULL, + 'node' => [ + 'inpage_navigation' => FALSE, + ], + 'expected' => [ + 'summary' => ['Any inpage navigation state'], + 'result' => TRUE, + ], + ], + 'empty condition, negative, node w/o active inpage navigation' => [ + 'inpage_navigation_condition' => NULL, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => [ + 'inpage_navigation' => FALSE, + ], + 'expected' => [ + 'summary' => ['Any inpage navigation state'], + 'result' => FALSE, + ], + ], + 'empty condition, no node' => [ + 'inpage_navigation_condition' => NULL, + 'inpage_navigation_condition_negate' => NULL, + 'node' => NULL, + 'expected' => [ + 'summary' => ['Any inpage navigation state'], + 'result' => TRUE, + ], + ], + 'empty condition, negative, no node' => [ + 'inpage_navigation_condition' => NULL, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => NULL, + 'expected' => [ + 'summary' => ['Any inpage navigation state'], + 'result' => FALSE, + ], + ], + 'enabled inpage navigation, node w/ active inpage navigation' => [ + 'inpage_navigation_condition' => TRUE, + 'inpage_navigation_condition_negate' => NULL, + 'node' => [ + 'inpage_navigation' => TRUE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should be @state', ['@state' => 'enabled']], + 'result' => TRUE, + ], + ], + 'enabled inpage navigation, negative, node w/ active inpage navigation' => [ + 'inpage_navigation_condition' => TRUE, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => [ + 'inpage_navigation' => TRUE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should not be @state', ['@state' => 'enabled']], + 'result' => FALSE, + ], + ], + 'enabled inpage navigation, node w/o active inpage navigation' => [ + 'inpage_navigation_condition' => TRUE, + 'inpage_navigation_condition_negate' => NULL, + 'node' => [ + 'inpage_navigation' => FALSE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should be @state', ['@state' => 'enabled']], + 'result' => FALSE, + ], + ], + 'enabled inpage navigation, negative, node w/o active inpage navigation' => [ + 'inpage_navigation_condition' => TRUE, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => [ + 'inpage_navigation' => FALSE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should not be @state', ['@state' => 'enabled']], + 'result' => TRUE, + ], + ], + 'enabled inpage navigation, no node' => [ + 'inpage_navigation_condition' => TRUE, + 'inpage_navigation_condition_negate' => NULL, + 'node' => NULL, + 'expected' => [ + 'summary' => ['The inpage navigation should be enabled'], + 'result' => TRUE, + ], + ], + 'enabled inpage navigation, negative, no node' => [ + 'inpage_navigation_condition' => TRUE, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => NULL, + 'expected' => [ + 'summary' => ['The inpage navigation should not be enabled'], + 'result' => FALSE, + ], + ], + 'disabled inpage navigation, node w/ active inpage navigation' => [ + 'inpage_navigation_condition' => FALSE, + 'inpage_navigation_condition_negate' => NULL, + 'node' => [ + 'inpage_navigation' => TRUE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should be disabled'], + 'result' => FALSE, + ], + ], + 'disabled inpage navigation, negative, node w/ active inpage navigation' => [ + 'inpage_navigation_condition' => FALSE, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => [ + 'inpage_navigation' => TRUE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should not be disabled'], + 'result' => TRUE, + ], + ], + 'disabled inpage navigation, node w/o active inpage navigation' => [ + 'inpage_navigation_condition' => FALSE, + 'inpage_navigation_condition_negate' => NULL, + 'node' => [ + 'inpage_navigation' => FALSE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should be disabled'], + 'result' => TRUE, + ], + ], + 'disabled inpage navigation, negative, node w/o active inpage navigation' => [ + 'inpage_navigation_condition' => FALSE, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => [ + 'inpage_navigation' => FALSE, + ], + 'expected' => [ + 'summary' => ['The inpage navigation should not be disabled'], + 'result' => FALSE, + ], + ], + 'disabled inpage navigation, no node' => [ + 'inpage_navigation_condition' => FALSE, + 'inpage_navigation_condition_negate' => NULL, + 'node' => NULL, + 'expected' => [ + 'summary' => ['The inpage navigation should be disabled'], + 'result' => TRUE, + ], + ], + 'disabled inpage navigation, negative, no node' => [ + 'inpage_navigation_condition' => FALSE, + 'inpage_navigation_condition_negate' => TRUE, + 'node' => NULL, + 'expected' => [ + 'summary' => ['The inpage navigation should not be disabled'], + 'result' => FALSE, + ], + ], + ]; + } + +} From 44acafff09f4bdc0d4264427df54b91edc18e579 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Tue, 30 Mar 2021 23:13:22 +0300 Subject: [PATCH 008/147] EWPP-855: Update tests and fix evaluation of condition plugin. --- .../Condition/InPageNavigationState.php | 7 ++++- .../Condition/InPageNavigationStateTest.php | 29 +++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php index 0c8819e75..1f2734efd 100644 --- a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php +++ b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php @@ -75,7 +75,12 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function evaluate() { $node = $this->getContextValue('node'); - if ($this->configuration['inpage_navigation_state'] === NULL || !$node instanceof NodeInterface) { + + if (!$node instanceof NodeInterface) { + return $this->isNegated(); + } + + if ($this->configuration['inpage_navigation_state'] === NULL) { return TRUE; } diff --git a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php index 836312334..a55d891f9 100644 --- a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php +++ b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php @@ -6,9 +6,9 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Plugin\Context\EntityContext; -use Drupal\node\Entity\Node; -use Drupal\node\Entity\NodeType; use Drupal\oe_theme_inpage_navigation\InPageNavigationHelper; +use Drupal\Tests\node\Traits\ContentTypeCreationTrait; +use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase; /** @@ -16,10 +16,15 @@ */ class InPageNavigationStateTest extends AbstractKernelTestBase { + use ContentTypeCreationTrait; + use NodeCreationTrait; + /** * {@inheritdoc} */ public static $modules = [ + 'filter', + 'text', 'emr', 'emr_node', 'node', @@ -39,10 +44,14 @@ protected function setUp() { $this->installSchema('node', ['node_access']); $this->installConfig([ + 'node', + 'filter', 'emr', 'emr_node', 'oe_theme_inpage_navigation', ]); + $this->createContentType(['type' => 'example', 'name' => 'Example']); + $this->container->get('emr.installer')->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['example']); } /** @@ -60,23 +69,19 @@ protected function setUp() { * @dataProvider providerTestCondition */ public function testCondition(?bool $inpage_navigation_condition, ?bool $inpage_navigation_condition_negate, ?array $inpage_navigation_node_state, array $expected): void { - $manager = \Drupal::service('plugin.manager.condition'); - $condition = $manager->createInstance('oe_theme_inpage_navigation_state'); + $condition = $this->container->get('plugin.manager.condition')->createInstance('oe_theme_inpage_navigation_state'); $condition->setConfiguration(['inpage_navigation_state' => $inpage_navigation_condition, 'negate' => $inpage_navigation_condition_negate]); if ($inpage_navigation_node_state) { $condition->setContextMapping([ 'node' => 'node', ]); - NodeType::create(['type' => 'example', 'name' => 'Example'])->save(); - \Drupal::service('emr.installer')->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['example']); - $node = Node::create(['type' => 'example', 'title' => 'some title']); - $node->save(); + $node = $this->createNode(['type' => 'example', 'title' => 'some title']); if ($inpage_navigation_node_state['inpage_navigation']) { InPageNavigationHelper::setInPageNavigation($node); } $contexts['node'] = EntityContext::fromEntity($node); - \Drupal::service('context.handler')->applyContextMapping($condition, $contexts); + $this->container->get('context.handler')->applyContextMapping($condition, $contexts); } $this->assertEqual($condition->summary(), new FormattableMarkup($expected['summary'][0], $expected['summary'][1] ?? [])); @@ -141,7 +146,7 @@ public function providerTestCondition(): array { 'node' => NULL, 'expected' => [ 'summary' => ['Any inpage navigation state'], - 'result' => TRUE, + 'result' => FALSE, ], ], 'empty condition, negative, no node' => [ @@ -203,7 +208,7 @@ public function providerTestCondition(): array { 'node' => NULL, 'expected' => [ 'summary' => ['The inpage navigation should be enabled'], - 'result' => TRUE, + 'result' => FALSE, ], ], 'enabled inpage navigation, negative, no node' => [ @@ -265,7 +270,7 @@ public function providerTestCondition(): array { 'node' => NULL, 'expected' => [ 'summary' => ['The inpage navigation should be disabled'], - 'result' => TRUE, + 'result' => FALSE, ], ], 'disabled inpage navigation, negative, no node' => [ From 12752bc0318683b918f3ad291d1153dd1fb85093 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 31 Mar 2021 11:18:54 +0300 Subject: [PATCH 009/147] EWPP-855: Adjust changes after updates in entity_meta_relation plugin. --- .../src/Plugin/Condition/InPageNavigationState.php | 2 +- .../src/Kernel/Plugin/Condition/InPageNavigationStateTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php index 1f2734efd..788128210 100644 --- a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php +++ b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php @@ -84,7 +84,7 @@ public function evaluate() { return TRUE; } - return InPageNavigationHelper::isInPageNavigation($node) === $this->configuration['inpage_navigation_state']; + return InPageNavigationHelper::isInPageNavigationEnabled($node) === $this->configuration['inpage_navigation_state']; } /** diff --git a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php index a55d891f9..27e799d7e 100644 --- a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php +++ b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php @@ -78,7 +78,8 @@ public function testCondition(?bool $inpage_navigation_condition, ?bool $inpage_ ]); $node = $this->createNode(['type' => 'example', 'title' => 'some title']); if ($inpage_navigation_node_state['inpage_navigation']) { - InPageNavigationHelper::setInPageNavigation($node); + InPageNavigationHelper::enableInPageNavigation($node); + $node->save(); } $contexts['node'] = EntityContext::fromEntity($node); $this->container->get('context.handler')->applyContextMapping($condition, $contexts); From 3397ae31c5acfe3f586389bc58790ceefed04b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A2ni=20Borges=20de=20Freitas?= Date: Wed, 7 Apr 2021 16:42:04 +0100 Subject: [PATCH 010/147] EWPP-855: Change the default state of the plugin. --- .../Condition/InPageNavigationState.php | 20 +--- .../Condition/InPageNavigationStateTest.php | 110 ++++-------------- 2 files changed, 30 insertions(+), 100 deletions(-) diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php index 788128210..5447ffa93 100644 --- a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php +++ b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php @@ -12,13 +12,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Provides a configurable 'Inpage Navigation State' condition. + * Provides a configurable 'In-page Navigation State' condition. * - * This condition checks if the inpage navigation for node is enabled. + * This condition checks if the in-page navigation is enabled for the node. * * @Condition( * id = "oe_theme_inpage_navigation_state", - * label = @Translation("Inpage navigation"), + * label = @Translation("In-page navigation"), * context_definitions = { * "node" = @ContextDefinition("entity:node", required = FALSE) * } @@ -42,7 +42,7 @@ public static function create(ContainerInterface $container, array $configuratio */ public function defaultConfiguration() { return [ - 'inpage_navigation_state' => NULL, + 'inpage_navigation_state' => FALSE, ] + parent::defaultConfiguration(); } @@ -80,10 +80,6 @@ public function evaluate() { return $this->isNegated(); } - if ($this->configuration['inpage_navigation_state'] === NULL) { - return TRUE; - } - return InPageNavigationHelper::isInPageNavigationEnabled($node) === $this->configuration['inpage_navigation_state']; } @@ -91,16 +87,12 @@ public function evaluate() { * {@inheritdoc} */ public function summary() { - if (is_null($this->configuration['inpage_navigation_state'])) { - return $this->t('Any inpage navigation state'); - } - $state = $this->configuration['inpage_navigation_state'] ? $this->t('enabled') : $this->t('disabled'); if ($this->isNegated()) { - return $this->t('The inpage navigation should not be @state', ['@state' => $state]); + return $this->t('The in-page navigation should not be @state', ['@state' => $state]); } - return $this->t('The inpage navigation should be @state', ['@state' => $state]); + return $this->t('The in-page navigation should be @state', ['@state' => $state]); } } diff --git a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php index 27e799d7e..7dbbe953d 100644 --- a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php +++ b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php @@ -97,189 +97,127 @@ public function testCondition(?bool $inpage_navigation_condition, ?bool $inpage_ */ public function providerTestCondition(): array { return [ - 'empty condition, node w/ active inpage navigation' => [ - 'inpage_navigation_condition' => NULL, - 'inpage_navigation_condition_negate' => NULL, - 'node' => [ - 'inpage_navigation' => TRUE, - ], - 'expected' => [ - 'summary' => ['Any inpage navigation state'], - 'result' => TRUE, - ], - ], - 'empty condition, negative, node w/ active inpage navigation' => [ - 'inpage_navigation_condition' => NULL, - 'inpage_navigation_condition_negate' => TRUE, - 'node' => [ - 'inpage_navigation' => TRUE, - ], - 'expected' => [ - 'summary' => ['Any inpage navigation state'], - 'result' => FALSE, - ], - ], - 'empty condition, node w/o active inpage navigation' => [ - 'inpage_navigation_condition' => NULL, - 'inpage_navigation_condition_negate' => NULL, - 'node' => [ - 'inpage_navigation' => FALSE, - ], - 'expected' => [ - 'summary' => ['Any inpage navigation state'], - 'result' => TRUE, - ], - ], - 'empty condition, negative, node w/o active inpage navigation' => [ - 'inpage_navigation_condition' => NULL, - 'inpage_navigation_condition_negate' => TRUE, - 'node' => [ - 'inpage_navigation' => FALSE, - ], - 'expected' => [ - 'summary' => ['Any inpage navigation state'], - 'result' => FALSE, - ], - ], - 'empty condition, no node' => [ - 'inpage_navigation_condition' => NULL, - 'inpage_navigation_condition_negate' => NULL, - 'node' => NULL, - 'expected' => [ - 'summary' => ['Any inpage navigation state'], - 'result' => FALSE, - ], - ], - 'empty condition, negative, no node' => [ - 'inpage_navigation_condition' => NULL, - 'inpage_navigation_condition_negate' => TRUE, - 'node' => NULL, - 'expected' => [ - 'summary' => ['Any inpage navigation state'], - 'result' => FALSE, - ], - ], - 'enabled inpage navigation, node w/ active inpage navigation' => [ + 'enabled in-page navigation, node w/ active inpage navigation' => [ 'inpage_navigation_condition' => TRUE, 'inpage_navigation_condition_negate' => NULL, 'node' => [ 'inpage_navigation' => TRUE, ], 'expected' => [ - 'summary' => ['The inpage navigation should be @state', ['@state' => 'enabled']], + 'summary' => ['The in-page navigation should be @state', ['@state' => 'enabled']], 'result' => TRUE, ], ], - 'enabled inpage navigation, negative, node w/ active inpage navigation' => [ + 'enabled in-page navigation, negative, node w/ active inpage navigation' => [ 'inpage_navigation_condition' => TRUE, 'inpage_navigation_condition_negate' => TRUE, 'node' => [ 'inpage_navigation' => TRUE, ], 'expected' => [ - 'summary' => ['The inpage navigation should not be @state', ['@state' => 'enabled']], + 'summary' => ['The in-page navigation should not be @state', ['@state' => 'enabled']], 'result' => FALSE, ], ], - 'enabled inpage navigation, node w/o active inpage navigation' => [ + 'enabled in-page navigation, node w/o active inpage navigation' => [ 'inpage_navigation_condition' => TRUE, 'inpage_navigation_condition_negate' => NULL, 'node' => [ 'inpage_navigation' => FALSE, ], 'expected' => [ - 'summary' => ['The inpage navigation should be @state', ['@state' => 'enabled']], + 'summary' => ['The in-page navigation should be @state', ['@state' => 'enabled']], 'result' => FALSE, ], ], - 'enabled inpage navigation, negative, node w/o active inpage navigation' => [ + 'enabled in-page navigation, negative, node w/o active inpage navigation' => [ 'inpage_navigation_condition' => TRUE, 'inpage_navigation_condition_negate' => TRUE, 'node' => [ 'inpage_navigation' => FALSE, ], 'expected' => [ - 'summary' => ['The inpage navigation should not be @state', ['@state' => 'enabled']], + 'summary' => ['The in-page navigation should not be @state', ['@state' => 'enabled']], 'result' => TRUE, ], ], - 'enabled inpage navigation, no node' => [ + 'enabled in-page navigation, no node' => [ 'inpage_navigation_condition' => TRUE, 'inpage_navigation_condition_negate' => NULL, 'node' => NULL, 'expected' => [ - 'summary' => ['The inpage navigation should be enabled'], + 'summary' => ['The in-page navigation should be enabled'], 'result' => FALSE, ], ], - 'enabled inpage navigation, negative, no node' => [ + 'enabled in-page navigation, negative, no node' => [ 'inpage_navigation_condition' => TRUE, 'inpage_navigation_condition_negate' => TRUE, 'node' => NULL, 'expected' => [ - 'summary' => ['The inpage navigation should not be enabled'], + 'summary' => ['The in-page navigation should not be enabled'], 'result' => FALSE, ], ], - 'disabled inpage navigation, node w/ active inpage navigation' => [ + 'disabled in-page navigation, node w/ active inpage navigation' => [ 'inpage_navigation_condition' => FALSE, 'inpage_navigation_condition_negate' => NULL, 'node' => [ 'inpage_navigation' => TRUE, ], 'expected' => [ - 'summary' => ['The inpage navigation should be disabled'], + 'summary' => ['The in-page navigation should be disabled'], 'result' => FALSE, ], ], - 'disabled inpage navigation, negative, node w/ active inpage navigation' => [ + 'disabled in-page navigation, negative, node w/ active inpage navigation' => [ 'inpage_navigation_condition' => FALSE, 'inpage_navigation_condition_negate' => TRUE, 'node' => [ 'inpage_navigation' => TRUE, ], 'expected' => [ - 'summary' => ['The inpage navigation should not be disabled'], + 'summary' => ['The in-page navigation should not be disabled'], 'result' => TRUE, ], ], - 'disabled inpage navigation, node w/o active inpage navigation' => [ + 'disabled in-page navigation, node w/o active inpage navigation' => [ 'inpage_navigation_condition' => FALSE, 'inpage_navigation_condition_negate' => NULL, 'node' => [ 'inpage_navigation' => FALSE, ], 'expected' => [ - 'summary' => ['The inpage navigation should be disabled'], + 'summary' => ['The in-page navigation should be disabled'], 'result' => TRUE, ], ], - 'disabled inpage navigation, negative, node w/o active inpage navigation' => [ + 'disabled in-page navigation, negative, node w/o active inpage navigation' => [ 'inpage_navigation_condition' => FALSE, 'inpage_navigation_condition_negate' => TRUE, 'node' => [ 'inpage_navigation' => FALSE, ], 'expected' => [ - 'summary' => ['The inpage navigation should not be disabled'], + 'summary' => ['The in-page navigation should not be disabled'], 'result' => FALSE, ], ], - 'disabled inpage navigation, no node' => [ + 'disabled in-page navigation, no node' => [ 'inpage_navigation_condition' => FALSE, 'inpage_navigation_condition_negate' => NULL, 'node' => NULL, 'expected' => [ - 'summary' => ['The inpage navigation should be disabled'], + 'summary' => ['The in-page navigation should be disabled'], 'result' => FALSE, ], ], - 'disabled inpage navigation, negative, no node' => [ + 'disabled in-page navigation, negative, no node' => [ 'inpage_navigation_condition' => FALSE, 'inpage_navigation_condition_negate' => TRUE, 'node' => NULL, 'expected' => [ - 'summary' => ['The inpage navigation should not be disabled'], + 'summary' => ['The in-page navigation should not be disabled'], 'result' => FALSE, ], ], From 8325c9a71eb4b2c591464525399eac5eafe208e1 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Thu, 8 Apr 2021 17:23:31 +0300 Subject: [PATCH 011/147] EWPP-855: Optimise tests and fix issues in plugin. --- .../Condition/InPageNavigationState.php | 9 +++- .../Condition/InPageNavigationStateTest.php | 49 ++++++++----------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php index 5447ffa93..e8f6e77f1 100644 --- a/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php +++ b/modules/oe_theme_inpage_navigation/src/Plugin/Condition/InPageNavigationState.php @@ -54,7 +54,10 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#type' => 'radios', '#title' => $this->t('Inpage navigation'), '#default_value' => $this->configuration['inpage_navigation_state'], - '#options' => [$this->t('Disabled'), $this->t('Enabled')], + '#options' => [ + $this->t('Disabled'), + $this->t('Enabled'), + ], '#description' => $this->t('Choose with which inpage navigation state this condition should be met.'), ]; return parent::buildConfigurationForm($form, $form_state); @@ -76,11 +79,13 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s public function evaluate() { $node = $this->getContextValue('node'); + // If we don't have a node, we return FALSE, unless the plugin is configured + // to be negated, in which case, it's the opposite. if (!$node instanceof NodeInterface) { return $this->isNegated(); } - return InPageNavigationHelper::isInPageNavigationEnabled($node) === $this->configuration['inpage_navigation_state']; + return InPageNavigationHelper::isInPageNavigationEnabled($node) === (bool) $this->configuration['inpage_navigation_state']; } /** diff --git a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php index 7dbbe953d..fd64c546a 100644 --- a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php +++ b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php @@ -22,7 +22,7 @@ class InPageNavigationStateTest extends AbstractKernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'filter', 'text', 'emr', @@ -56,37 +56,30 @@ protected function setUp() { /** * Tests the inpage navigation state condition. - * - * @param bool|null $inpage_navigation_condition - * Inpage navigation state condition. - * @param bool|null $inpage_navigation_condition_negate - * Is negate. - * @param array|null $inpage_navigation_node_state - * Inpage navigation state in node. - * @param array $expected - * Array with expected values of 'summary' and 'result'. - * - * @dataProvider providerTestCondition */ - public function testCondition(?bool $inpage_navigation_condition, ?bool $inpage_navigation_condition_negate, ?array $inpage_navigation_node_state, array $expected): void { + public function testCondition(): void { + /** @var $condition \Drupal\Core\Condition\ConditionPluginBase */ $condition = $this->container->get('plugin.manager.condition')->createInstance('oe_theme_inpage_navigation_state'); - $condition->setConfiguration(['inpage_navigation_state' => $inpage_navigation_condition, 'negate' => $inpage_navigation_condition_negate]); - - if ($inpage_navigation_node_state) { - $condition->setContextMapping([ - 'node' => 'node', - ]); - $node = $this->createNode(['type' => 'example', 'title' => 'some title']); - if ($inpage_navigation_node_state['inpage_navigation']) { - InPageNavigationHelper::enableInPageNavigation($node); - $node->save(); + $node = $this->createNode(['type' => 'example', 'title' => 'some title']); + foreach ($this->providerTestCondition() as $test_case_name => $test_case) { + $condition_instance = clone $condition; + $node_instance = clone $node; + $condition_instance->setConfiguration(['inpage_navigation_state' => $test_case['inpage_navigation_condition'], 'negate' => $test_case['inpage_navigation_condition_negate']]); + if ($test_case['node']) { + $condition_instance->setContextMapping([ + 'node' => 'node', + ]); + if ($test_case['node']['inpage_navigation']) { + InPageNavigationHelper::enableInPageNavigation($node_instance); + $node_instance->save(); + } + $contexts['node'] = EntityContext::fromEntity($node_instance); + $this->container->get('context.handler')->applyContextMapping($condition_instance, $contexts); } - $contexts['node'] = EntityContext::fromEntity($node); - $this->container->get('context.handler')->applyContextMapping($condition, $contexts); + $this->assertEqual($condition_instance->summary(), new FormattableMarkup($test_case['expected']['summary'][0], $test_case['expected']['summary'][1] ?? []), $test_case_name); + $this->assertEqual($condition_instance->execute(), $test_case['expected']['result'], $test_case_name); + $node_instance->get('emr_entity_metas')->delete(); } - - $this->assertEqual($condition->summary(), new FormattableMarkup($expected['summary'][0], $expected['summary'][1] ?? [])); - $this->assertEqual($condition->execute(), $expected['result']); } /** From fd9db595a0851e0290e78dfca90063005b91cf33 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Mon, 12 Apr 2021 12:42:55 +0300 Subject: [PATCH 012/147] EWPP-855: Simplify tests of conditional plugin. --- composer.json | 2 +- .../Condition/InPageNavigationStateTest.php | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index d82464bd4..ec1c760f3 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "drupal/entity_browser": "^2.5", "drupal/extra_field": "^1.1", "drupal/field_group": "~3.0", - "drupal/inline_entity_form": "~1.0-rc7", + "drupal/inline_entity_form": "1.0-rc8", "drupal/json_field": "^1.0.0-rc2", "drupal/renderviz": "^1.0@alpha", "drupal/styleguide": "~1.0-alpha3", diff --git a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php index fd64c546a..84f3e6712 100644 --- a/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php +++ b/modules/oe_theme_inpage_navigation/tests/src/Kernel/Plugin/Condition/InPageNavigationStateTest.php @@ -59,36 +59,36 @@ protected function setUp() { */ public function testCondition(): void { /** @var $condition \Drupal\Core\Condition\ConditionPluginBase */ - $condition = $this->container->get('plugin.manager.condition')->createInstance('oe_theme_inpage_navigation_state'); - $node = $this->createNode(['type' => 'example', 'title' => 'some title']); - foreach ($this->providerTestCondition() as $test_case_name => $test_case) { - $condition_instance = clone $condition; - $node_instance = clone $node; - $condition_instance->setConfiguration(['inpage_navigation_state' => $test_case['inpage_navigation_condition'], 'negate' => $test_case['inpage_navigation_condition_negate']]); + foreach ($this->getTestScenarios() as $test_case_name => $test_case) { + $condition = $this->container->get('plugin.manager.condition')->createInstance('oe_theme_inpage_navigation_state'); + $node = $this->createNode(['type' => 'example', 'title' => 'some title']); + $condition->setConfiguration(['inpage_navigation_state' => $test_case['inpage_navigation_condition'], 'negate' => $test_case['inpage_navigation_condition_negate']]); if ($test_case['node']) { - $condition_instance->setContextMapping([ + $condition->setContextMapping([ 'node' => 'node', ]); if ($test_case['node']['inpage_navigation']) { - InPageNavigationHelper::enableInPageNavigation($node_instance); - $node_instance->save(); + InPageNavigationHelper::enableInPageNavigation($node); + $node->save(); } - $contexts['node'] = EntityContext::fromEntity($node_instance); - $this->container->get('context.handler')->applyContextMapping($condition_instance, $contexts); + $contexts['node'] = EntityContext::fromEntity($node); + $this->container->get('context.handler')->applyContextMapping($condition, $contexts); } - $this->assertEqual($condition_instance->summary(), new FormattableMarkup($test_case['expected']['summary'][0], $test_case['expected']['summary'][1] ?? []), $test_case_name); - $this->assertEqual($condition_instance->execute(), $test_case['expected']['result'], $test_case_name); - $node_instance->get('emr_entity_metas')->delete(); + $this->assertEqual($condition->summary(), new FormattableMarkup($test_case['expected']['summary'][0], $test_case['expected']['summary'][1] ?? []), $test_case_name); + $this->assertEqual($condition->execute(), $test_case['expected']['result'], $test_case_name); + $node->delete(); } } /** - * Data provider for testCondition(). + * Returns a test data for the 'In-page navigation' condition plugin. * * @return array[] * The test data. + * + * @see self::testCondition() */ - public function providerTestCondition(): array { + public function getTestScenarios(): array { return [ 'enabled in-page navigation, node w/ active inpage navigation' => [ 'inpage_navigation_condition' => TRUE, From 37057844784e78ca544cb785d2b7227a8ee0b7dc Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Sun, 18 Apr 2021 16:47:58 +0300 Subject: [PATCH 013/147] EWPP-990: Remove body field label from full view display. --- .../core.entity_view_display.node.oe_organisation.full.yml | 3 ++- tests/Functional/ContentOrganisationRenderTest.php | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml b/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml index bafa0ffbb..70eb9e3ed 100644 --- a/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml +++ b/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml @@ -2,6 +2,7 @@ langcode: en status: true dependencies: config: + - core.entity_view_mode.node.full - field.field.node.oe_organisation.body - field.field.node.oe_organisation.oe_organisation_acronym - field.field.node.oe_organisation.oe_organisation_contact @@ -43,7 +44,7 @@ third_party_settings: format_settings: id: '' classes: '' - label: Description + label: '' group_contact: children: - oe_organisation_contact diff --git a/tests/Functional/ContentOrganisationRenderTest.php b/tests/Functional/ContentOrganisationRenderTest.php index 4c9bc4db7..b60414d97 100644 --- a/tests/Functional/ContentOrganisationRenderTest.php +++ b/tests/Functional/ContentOrganisationRenderTest.php @@ -137,7 +137,6 @@ public function testOrganisationRendering(): void { $expected_values = [ 'title' => 'Page contents', 'list' => [ - ['label' => 'Description', 'href' => '#description'], ['label' => 'Contact', 'href' => '#contact'], ], ]; @@ -171,8 +170,8 @@ public function testOrganisationRendering(): void { $content_items = $content->findAll('xpath', '/div'); $this->assertCount(2, $content_items); - // Assert header of first field group. - $this->assertContentHeader($content_items[0], 'Description', 'description'); + // Assert header of first field group is not displayed anymore. + $this->assertSession()->pageTextNotContains('Description'); // Assert values for first group. $body = $content_items[0]->findAll('css', '.ecl-editor'); From c34c3555be160b91ee8d7b1427429db9b51570ce Mon Sep 17 00:00:00 2001 From: upchuk Date: Mon, 19 Apr 2021 12:25:48 +0300 Subject: [PATCH 014/147] EWPP-990: Showing - No label - in the backend on field groups with no label. --- modules/oe_theme_helper/oe_theme_helper.module | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/oe_theme_helper/oe_theme_helper.module b/modules/oe_theme_helper/oe_theme_helper.module index a906dfdc4..37852e0e1 100644 --- a/modules/oe_theme_helper/oe_theme_helper.module +++ b/modules/oe_theme_helper/oe_theme_helper.module @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Form\FormStateInterface; use Drupal\file\FileInterface; use Drupal\image\Plugin\Field\FieldType\ImageItem; use Drupal\media\MediaInterface; @@ -283,3 +284,14 @@ function oe_theme_helper_entity_bundle_info_alter(&$bundles) { : 'thumbnail'; } } + +/** + * Implements hook_form_FORM_ID_alter() for the entity view display form. + */ +function oe_theme_helper_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) { + foreach ($form['#fieldgroups'] as $name) { + if ($form['fields'][$name]['human_name']['#markup'] === "") { + $form['fields'][$name]['human_name']['#markup'] = t('- No label -'); + } + } +} From d110c3d7667c3ca12cc30ec5621bb01719b88549 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Mon, 19 Apr 2021 12:57:20 +0300 Subject: [PATCH 015/147] EWPP-990: Provide update path. --- ...view_display.node.oe_organisation.full.yml | 107 ++++++++++++++++++ ...theme_content_organisation.post_update.php | 16 +++ 2 files changed, 123 insertions(+) create mode 100644 modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml diff --git a/modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml b/modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml new file mode 100644 index 000000000..70eb9e3ed --- /dev/null +++ b/modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml @@ -0,0 +1,107 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.node.full + - field.field.node.oe_organisation.body + - field.field.node.oe_organisation.oe_organisation_acronym + - field.field.node.oe_organisation.oe_organisation_contact + - field.field.node.oe_organisation.oe_organisation_eu_org + - field.field.node.oe_organisation.oe_organisation_eu_org_type + - field.field.node.oe_organisation.oe_organisation_logo + - field.field.node.oe_organisation.oe_organisation_non_eu_org_type + - field.field.node.oe_organisation.oe_organisation_org_type + - field.field.node.oe_organisation.oe_summary + - field.field.node.oe_organisation.oe_teaser + - node.type.oe_organisation + module: + - entity_reference_revisions + - field_group + - text + - user +third_party_settings: + field_group: + group_in_page_navigation: + children: + - oe_organisation_logo + - group_description + - group_contact + parent_name: '' + weight: 0 + format_type: oe_theme_helper_in_page_navigation + region: content + format_settings: + id: '' + classes: '' + label: 'Page contents' + group_description: + children: + - body + parent_name: group_in_page_navigation + weight: 1 + format_type: oe_theme_helper_in_page_navigation_item + region: content + format_settings: + id: '' + classes: '' + label: '' + group_contact: + children: + - oe_organisation_contact + parent_name: group_in_page_navigation + weight: 2 + format_type: oe_theme_helper_in_page_navigation_item + region: content + format_settings: + id: '' + classes: '' + label: Contact +id: node.oe_organisation.full +targetEntityType: node +bundle: oe_organisation +mode: full +content: + body: + label: hidden + type: text_default + weight: 4 + settings: { } + third_party_settings: { } + region: content + links: + weight: 1 + region: content + settings: { } + third_party_settings: { } + oe_organisation_contact: + weight: 6 + label: hidden + settings: + view_mode: full + link: '' + third_party_settings: { } + type: entity_reference_revisions_entity_view + region: content + oe_organisation_logo: + type: entity_reference_label + weight: 0 + region: content + label: above + settings: + link: true + third_party_settings: { } +hidden: + extra_field_oe_theme_content_organisation_teaser_details: true + extra_field_oe_theme_helper_short_title_with_fallback: true + langcode: true + oe_content_content_owner: true + oe_content_legacy_link: true + oe_content_navigation_title: true + oe_content_short_title: true + oe_organisation_acronym: true + oe_organisation_eu_org: true + oe_organisation_eu_org_type: true + oe_organisation_non_eu_org_type: true + oe_organisation_org_type: true + oe_summary: true + oe_teaser: true diff --git a/modules/oe_theme_content_organisation/oe_theme_content_organisation.post_update.php b/modules/oe_theme_content_organisation/oe_theme_content_organisation.post_update.php index 202c049f3..2e44fdb30 100644 --- a/modules/oe_theme_content_organisation/oe_theme_content_organisation.post_update.php +++ b/modules/oe_theme_content_organisation/oe_theme_content_organisation.post_update.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Config\FileStorage; +use Drupal\Core\Entity\Entity\EntityViewDisplay; /** * Create the 'full' entity view display on the organisation CT. @@ -33,3 +34,18 @@ function oe_theme_content_organisation_post_update_00001() { $entity = $entity_storage->createFromStorageRecord($config); $entity->save(); } + +/** + * Update the 'full' entity view display on the organisation CT. + */ +function oe_theme_content_organisation_post_update_00002() { + $storage = new FileStorage(drupal_get_path('module', 'oe_theme_content_organisation') . '/config/post_updates/00002_update_full_view_display'); + $view_display_values = $storage->read('core.entity_view_display.node.oe_organisation.full'); + $view_display = EntityViewDisplay::load($view_display_values['id']); + if ($view_display) { + $updated_view_display = \Drupal::entityTypeManager() + ->getStorage($view_display->getEntityTypeId()) + ->updateFromStorageRecord($view_display, $view_display_values); + $updated_view_display->save(); + } +} From ae5ae140835e4adf51164453cd43a213369b9687 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Fri, 16 Apr 2021 15:04:00 +0300 Subject: [PATCH 016/147] EWPP-987: Add overview field group to full view display. --- composer.json | 2 +- ...view_display.node.oe_organisation.full.yml | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 7a04c3ced..f4afcd8f0 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "openeuropa/behat-transformation-context": "~0.1", "openeuropa/code-review": "~1.5", "openeuropa/drupal-core-require-dev": "^8.9.13", - "openeuropa/oe_content": "~2.1", + "openeuropa/oe_content": "dev-EWPP-986", "openeuropa/oe_corporate_blocks": "~4.0", "openeuropa/oe_corporate_countries": "~2.0", "openeuropa/oe_media": "~1.11", diff --git a/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml b/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml index 70eb9e3ed..4a77dee98 100644 --- a/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml +++ b/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml @@ -11,10 +11,12 @@ dependencies: - field.field.node.oe_organisation.oe_organisation_logo - field.field.node.oe_organisation.oe_organisation_non_eu_org_type - field.field.node.oe_organisation.oe_organisation_org_type + - field.field.node.oe_organisation.oe_organisation_overivew - field.field.node.oe_organisation.oe_summary - field.field.node.oe_organisation.oe_teaser - node.type.oe_organisation module: + - description_list_field - entity_reference_revisions - field_group - text @@ -24,6 +26,7 @@ third_party_settings: group_in_page_navigation: children: - oe_organisation_logo + - group_overview - group_description - group_contact parent_name: '' @@ -38,7 +41,7 @@ third_party_settings: children: - body parent_name: group_in_page_navigation - weight: 1 + weight: 2 format_type: oe_theme_helper_in_page_navigation_item region: content format_settings: @@ -49,13 +52,24 @@ third_party_settings: children: - oe_organisation_contact parent_name: group_in_page_navigation - weight: 2 + weight: 3 format_type: oe_theme_helper_in_page_navigation_item region: content format_settings: id: '' classes: '' label: Contact + group_overview: + children: + - oe_organisation_overivew + parent_name: group_in_page_navigation + weight: 1 + format_type: oe_theme_helper_in_page_navigation_item + region: content + format_settings: + id: '' + classes: '' + label: Overview id: node.oe_organisation.full targetEntityType: node bundle: oe_organisation @@ -90,6 +104,13 @@ content: settings: link: true third_party_settings: { } + oe_organisation_overivew: + type: description_list_formatter + weight: 0 + region: content + label: hidden + settings: { } + third_party_settings: { } hidden: extra_field_oe_theme_content_organisation_teaser_details: true extra_field_oe_theme_helper_short_title_with_fallback: true From b01bfb7ea150658c053c14211f4b3920039693ec Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Fri, 16 Apr 2021 15:04:53 +0300 Subject: [PATCH 017/147] EWPP-987: Update rendering test. --- .../ContentOrganisationRenderTest.php | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/tests/Functional/ContentOrganisationRenderTest.php b/tests/Functional/ContentOrganisationRenderTest.php index b60414d97..17099d6b3 100644 --- a/tests/Functional/ContentOrganisationRenderTest.php +++ b/tests/Functional/ContentOrganisationRenderTest.php @@ -163,28 +163,54 @@ public function testOrganisationRendering(): void { $logo = $this->assertSession()->elementExists('css', '.ecl-col-lg-3 img.ecl-media-container__media'); $this->assertContains('files/styles/oe_theme_medium_no_crop/public/media_avportal_thumbnails/' . $file->getFilename(), $logo->getAttribute('src')); + // Add overview values. + $node->set('oe_organisation_overivew', [ + [ + 'term' => 'Overview Term 1', + 'description' => 'Overview Description 1', + ], + [ + 'term' => 'Overview Term 2', + 'description' => 'Overview Description 2', + ], + ]); + $node->save(); + $this->drupalGet($node->toUrl()); + // Assert content part. $wrapper = $this->assertSession()->elementExists('css', '.ecl-row.ecl-u-mt-l'); $content = $this->assertSession()->elementExists('css', '.ecl-col-lg-9', $wrapper); $this->assertSession()->elementsCount('css', '.ecl-col-lg-9', 1); $content_items = $content->findAll('xpath', '/div'); - $this->assertCount(2, $content_items); - // Assert header of first field group is not displayed anymore. + // Assert header of the first field group. + $this->assertContentHeader($content_items[0], 'Overview', 'overview'); + // Assert values of the first group. + $overview = $content_items[0]->findAll('css', 'dl.ecl-description-list.ecl-description-list--horizontal'); + $this->assertCount(1, $overview); + $overview_terms = $overview[0]->findAll('css', 'dt.ecl-description-list__term'); + $this->assertCount(2, $overview_terms); + $this->assertEquals('Overview Term 1', $overview_terms[0]->getText()); + $this->assertEquals('Overview Term 2', $overview_terms[1]->getText()); + $overview_descriptions = $overview[0]->findAll('css', 'dd.ecl-description-list__definition'); + $this->assertCount(2, $overview_descriptions); + $this->assertEquals('Overview Description 1', $overview_descriptions[0]->getText()); + $this->assertEquals('Overview Description 2', $overview_descriptions[1]->getText()); + + // Assert body field label is not displayed anymore. $this->assertSession()->pageTextNotContains('Description'); - - // Assert values for first group. - $body = $content_items[0]->findAll('css', '.ecl-editor'); + // Assert values of the second group. + $body = $content_items[1]->findAll('css', '.ecl-editor'); $this->assertCount(1, $body); $this->assertEquals('My body text', $body[0]->getText()); - // Assert header of second field group. - $this->assertContentHeader($content_items[1], 'Contact', 'contact'); + // Assert header of the third field group. + $this->assertContentHeader($content_items[2], 'Contact', 'contact'); // Assert Organisation's contacts. - $contact_headers = $content_items[1]->findAll('css', 'h2'); + $contact_headers = $content_items[2]->findAll('css', 'h2'); $this->assertEquals($contact_headers[0]->getText(), 'Contact'); - $this->assertContactRendering($content_items[1], 'general_contact'); + $this->assertContactRendering($content_items[2], 'general_contact'); } /** From 59362b87c530840dd3f560a88d3ef45771ae5a88 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Fri, 16 Apr 2021 15:30:18 +0300 Subject: [PATCH 018/147] EWPP-987: Fix typos. --- .../core.entity_view_display.node.oe_organisation.full.yml | 6 +++--- tests/Functional/ContentOrganisationRenderTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml b/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml index 4a77dee98..ae660c46b 100644 --- a/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml +++ b/modules/oe_theme_content_organisation/config/install/core.entity_view_display.node.oe_organisation.full.yml @@ -11,7 +11,7 @@ dependencies: - field.field.node.oe_organisation.oe_organisation_logo - field.field.node.oe_organisation.oe_organisation_non_eu_org_type - field.field.node.oe_organisation.oe_organisation_org_type - - field.field.node.oe_organisation.oe_organisation_overivew + - field.field.node.oe_organisation.oe_organisation_overview - field.field.node.oe_organisation.oe_summary - field.field.node.oe_organisation.oe_teaser - node.type.oe_organisation @@ -61,7 +61,7 @@ third_party_settings: label: Contact group_overview: children: - - oe_organisation_overivew + - oe_organisation_overview parent_name: group_in_page_navigation weight: 1 format_type: oe_theme_helper_in_page_navigation_item @@ -104,7 +104,7 @@ content: settings: link: true third_party_settings: { } - oe_organisation_overivew: + oe_organisation_overview: type: description_list_formatter weight: 0 region: content diff --git a/tests/Functional/ContentOrganisationRenderTest.php b/tests/Functional/ContentOrganisationRenderTest.php index 17099d6b3..eeed65a76 100644 --- a/tests/Functional/ContentOrganisationRenderTest.php +++ b/tests/Functional/ContentOrganisationRenderTest.php @@ -164,7 +164,7 @@ public function testOrganisationRendering(): void { $this->assertContains('files/styles/oe_theme_medium_no_crop/public/media_avportal_thumbnails/' . $file->getFilename(), $logo->getAttribute('src')); // Add overview values. - $node->set('oe_organisation_overivew', [ + $node->set('oe_organisation_overview', [ [ 'term' => 'Overview Term 1', 'description' => 'Overview Description 1', From efa4eeaba01261f4590c976f33ea9d372f54b23e Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Fri, 16 Apr 2021 16:54:05 +0300 Subject: [PATCH 019/147] EWPP-987: Add missing dependency in kernel tests. --- tests/Kernel/OrganisationRenderTest.php | 1 + tests/Kernel/PersonRenderTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/Kernel/OrganisationRenderTest.php b/tests/Kernel/OrganisationRenderTest.php index f2b5cf44c..9e199b2a2 100644 --- a/tests/Kernel/OrganisationRenderTest.php +++ b/tests/Kernel/OrganisationRenderTest.php @@ -38,6 +38,7 @@ class OrganisationRenderTest extends ContentRenderTestBase { 'composite_reference', 'oe_theme_content_entity_contact', 'oe_theme_content_organisation', + 'description_list_field', ]; /** diff --git a/tests/Kernel/PersonRenderTest.php b/tests/Kernel/PersonRenderTest.php index a39fa7bf0..66387ca39 100644 --- a/tests/Kernel/PersonRenderTest.php +++ b/tests/Kernel/PersonRenderTest.php @@ -40,6 +40,7 @@ class PersonRenderTest extends ContentRenderTestBase { 'oe_theme_content_organisation', 'oe_theme_content_organisation_reference', 'oe_theme_content_person', + 'description_list_field', ]; /** From a0c59821d6c619611e23a3b3e00dcd12aad5ee96 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Mon, 19 Apr 2021 12:47:06 +0300 Subject: [PATCH 020/147] EWPP-987: Provide update path. --- ...view_display.node.oe_organisation.full.yml | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml b/modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml index 70eb9e3ed..ae660c46b 100644 --- a/modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml +++ b/modules/oe_theme_content_organisation/config/post_updates/00002_update_full_view_display/core.entity_view_display.node.oe_organisation.full.yml @@ -11,10 +11,12 @@ dependencies: - field.field.node.oe_organisation.oe_organisation_logo - field.field.node.oe_organisation.oe_organisation_non_eu_org_type - field.field.node.oe_organisation.oe_organisation_org_type + - field.field.node.oe_organisation.oe_organisation_overview - field.field.node.oe_organisation.oe_summary - field.field.node.oe_organisation.oe_teaser - node.type.oe_organisation module: + - description_list_field - entity_reference_revisions - field_group - text @@ -24,6 +26,7 @@ third_party_settings: group_in_page_navigation: children: - oe_organisation_logo + - group_overview - group_description - group_contact parent_name: '' @@ -38,7 +41,7 @@ third_party_settings: children: - body parent_name: group_in_page_navigation - weight: 1 + weight: 2 format_type: oe_theme_helper_in_page_navigation_item region: content format_settings: @@ -49,13 +52,24 @@ third_party_settings: children: - oe_organisation_contact parent_name: group_in_page_navigation - weight: 2 + weight: 3 format_type: oe_theme_helper_in_page_navigation_item region: content format_settings: id: '' classes: '' label: Contact + group_overview: + children: + - oe_organisation_overview + parent_name: group_in_page_navigation + weight: 1 + format_type: oe_theme_helper_in_page_navigation_item + region: content + format_settings: + id: '' + classes: '' + label: Overview id: node.oe_organisation.full targetEntityType: node bundle: oe_organisation @@ -90,6 +104,13 @@ content: settings: link: true third_party_settings: { } + oe_organisation_overview: + type: description_list_formatter + weight: 0 + region: content + label: hidden + settings: { } + third_party_settings: { } hidden: extra_field_oe_theme_content_organisation_teaser_details: true extra_field_oe_theme_helper_short_title_with_fallback: true From b8fa21c33c5df03903384e207836cc6a4790888a Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Tue, 20 Apr 2021 15:19:20 +0300 Subject: [PATCH 021/147] EWPP-987: Update oe_content patch and fix functional test. --- composer.json | 2 +- tests/Functional/ContentOrganisationRenderTest.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f4afcd8f0..6b26bd5e4 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "openeuropa/behat-transformation-context": "~0.1", "openeuropa/code-review": "~1.5", "openeuropa/drupal-core-require-dev": "^8.9.13", - "openeuropa/oe_content": "dev-EWPP-986", + "openeuropa/oe_content": "dev-EPIC-EWPP-953-Organisation", "openeuropa/oe_corporate_blocks": "~4.0", "openeuropa/oe_corporate_countries": "~2.0", "openeuropa/oe_media": "~1.11", diff --git a/tests/Functional/ContentOrganisationRenderTest.php b/tests/Functional/ContentOrganisationRenderTest.php index eeed65a76..feb9da310 100644 --- a/tests/Functional/ContentOrganisationRenderTest.php +++ b/tests/Functional/ContentOrganisationRenderTest.php @@ -160,6 +160,9 @@ public function testOrganisationRendering(): void { $node->save(); $this->drupalGet($node->toUrl()); + // Assert body field label is not displayed anymore. + $this->assertSession()->pageTextNotContains('Description'); + $logo = $this->assertSession()->elementExists('css', '.ecl-col-lg-3 img.ecl-media-container__media'); $this->assertContains('files/styles/oe_theme_medium_no_crop/public/media_avportal_thumbnails/' . $file->getFilename(), $logo->getAttribute('src')); @@ -197,8 +200,6 @@ public function testOrganisationRendering(): void { $this->assertEquals('Overview Description 1', $overview_descriptions[0]->getText()); $this->assertEquals('Overview Description 2', $overview_descriptions[1]->getText()); - // Assert body field label is not displayed anymore. - $this->assertSession()->pageTextNotContains('Description'); // Assert values of the second group. $body = $content_items[1]->findAll('css', '.ecl-editor'); $this->assertCount(1, $body); From 3f33c9c1bc43e6c196ad1940f970d249bc851f9b Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Mon, 19 Apr 2021 12:17:17 +0300 Subject: [PATCH 022/147] EWPP-992: Update contacts rendering on full and teaser view displays. --- .../Display/TeaserDetailsExtraField.php | 71 +++++++++---------- ...tent-organisation-teaser-details.html.twig | 11 +++ ...n-contact--oe-organisation--full.html.twig | 26 +++++++ .../ContentOrganisationRenderTest.php | 28 +++++--- tests/Kernel/OrganisationRenderTest.php | 52 ++++++++++++-- 5 files changed, 137 insertions(+), 51 deletions(-) create mode 100644 templates/field/field--node--extra-field-oe-theme-content-organisation-teaser-details.html.twig create mode 100644 templates/field/field--node--oe-organisation-contact--oe-organisation--full.html.twig diff --git a/modules/oe_theme_content_organisation/src/Plugin/ExtraField/Display/TeaserDetailsExtraField.php b/modules/oe_theme_content_organisation/src/Plugin/ExtraField/Display/TeaserDetailsExtraField.php index 1d320de0b..ee05d00b7 100644 --- a/modules/oe_theme_content_organisation/src/Plugin/ExtraField/Display/TeaserDetailsExtraField.php +++ b/modules/oe_theme_content_organisation/src/Plugin/ExtraField/Display/TeaserDetailsExtraField.php @@ -9,7 +9,6 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase; -use Drupal\oe_content_entity_contact\Entity\ContactInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -71,46 +70,46 @@ public function viewElements(ContentEntityInterface $entity) { return []; } - $contact = $entity->get('oe_organisation_contact')->entity; - if (!$contact instanceof ContactInterface) { - return []; - } - - $build = [ - '#type' => 'pattern', - '#id' => 'field_list', - '#variant' => 'horizontal', - '#fields' => [ - 'items' => [], - ], - ]; + $build = []; $cache = CacheableMetadata::createFromRenderArray($build); - $contact_access = $contact->access('view', NULL, TRUE); - $cache->addCacheableDependency($contact); - $cache->addCacheableDependency($contact_access); - - if (!$contact_access->isAllowed()) { - $cache->applyTo($build); - return $build; - } + /** @var \Drupal\oe_content_entity_contact\Entity\ContactInterface $contact */ + foreach ($entity->get('oe_organisation_contact')->referencedEntities() as $delta => $contact) { + if (!$contact) { + continue; + } + $contact_access = $contact->access('view', NULL, TRUE); + $cache->addCacheableDependency($contact); + $cache->addCacheableDependency($contact_access); + if (!$contact_access->isAllowed()) { + continue; + } - $items = []; - $fields = [ - 'oe_website' => [], - 'oe_email' => ['type' => 'email_mailto'], - 'oe_phone' => [], - 'oe_address' => [ - 'type' => 'oe_theme_helper_address_inline', - 'settings' => ['delimiter' => ', '], - ], - ]; - foreach ($fields as $field_name => $display_options) { - if (!$contact->get($field_name)->isEmpty()) { - $items[] = $this->getRenderableFieldListItem($contact, $field_name, $display_options); + $build[$delta] = [ + '#type' => 'pattern', + '#id' => 'field_list', + '#variant' => 'horizontal', + '#fields' => [ + 'items' => [], + ], + ]; + $items = []; + $fields = [ + 'oe_website' => [], + 'oe_email' => ['type' => 'email_mailto'], + 'oe_phone' => [], + 'oe_address' => [ + 'type' => 'oe_theme_helper_address_inline', + 'settings' => ['delimiter' => ', '], + ], + ]; + foreach ($fields as $field_name => $display_options) { + if (!$contact->get($field_name)->isEmpty()) { + $items[] = $this->getRenderableFieldListItem($contact, $field_name, $display_options); + } } + $build[$delta]['#fields']['items'] = $items; } - $build['#fields']['items'] = $items; $cache->applyTo($build); return $build; diff --git a/templates/field/field--node--extra-field-oe-theme-content-organisation-teaser-details.html.twig b/templates/field/field--node--extra-field-oe-theme-content-organisation-teaser-details.html.twig new file mode 100644 index 000000000..c2ede84d3 --- /dev/null +++ b/templates/field/field--node--extra-field-oe-theme-content-organisation-teaser-details.html.twig @@ -0,0 +1,11 @@ +{# +/** + * @file + * Field template for oe_theme_content_organisation_teaser_details extra field. + */ +#} +{% for item in items %} + {% if item.content|render|striptags|trim is not empty %} + {{ item.content }} + {% endif %} +{% endfor %} diff --git a/templates/field/field--node--oe-organisation-contact--oe-organisation--full.html.twig b/templates/field/field--node--oe-organisation-contact--oe-organisation--full.html.twig new file mode 100644 index 000000000..594e3f2c9 --- /dev/null +++ b/templates/field/field--node--oe-organisation-contact--oe-organisation--full.html.twig @@ -0,0 +1,26 @@ +{# +/** + * @file + * Organisation contacts field template. + * + * @see ./core/themes/stable/templates/field/field.html.twig + */ +#} +{% set contacts %}{% for item in items %}{{ item.content }}{% endfor %}{% endset %} + +{% if contacts is not empty %} + {% if items|length == 1 %} + {{ contacts }} + {% else %} + {% include '@ecl-twig/expandable' with { + 'label_expanded': 'Hide contact details'|t, + 'label_collapsed': 'Show contact details'|t, + 'button': { + 'icon': { + 'path': ecl_icon_path, + }, + }, + content: contacts + } only %} + {% endif %} +{% endif %} diff --git a/tests/Functional/ContentOrganisationRenderTest.php b/tests/Functional/ContentOrganisationRenderTest.php index feb9da310..c6bdfcc38 100644 --- a/tests/Functional/ContentOrganisationRenderTest.php +++ b/tests/Functional/ContentOrganisationRenderTest.php @@ -81,7 +81,7 @@ public function testOrganisationRendering(): void { ]); $media->save(); - $general_contact = $this->createContactEntity('general_contact', 'oe_general', CorporateEntityInterface::PUBLISHED); + $first_general_contact = $this->createContactEntity('first_general_contact', 'oe_general', CorporateEntityInterface::PUBLISHED); /** @var \Drupal\node\Entity\Node $node */ $node = $this->getStorage('node')->create([ @@ -127,7 +127,7 @@ public function testOrganisationRendering(): void { // Add body text and contact values. $node->set('body', 'My body text'); - $node->set('oe_organisation_contact', [$general_contact]); + $node->set('oe_organisation_contact', [$first_general_contact]); $node->save(); $this->drupalGet($node->toUrl()); @@ -205,13 +205,25 @@ public function testOrganisationRendering(): void { $this->assertCount(1, $body); $this->assertEquals('My body text', $body[0]->getText()); + // Assert Organisation's contact is displayed expanded. + $contact_headers = $content_items[2]->findAll('css', 'h2'); // Assert header of the third field group. - $this->assertContentHeader($content_items[2], 'Contact', 'contact'); + $this->assertEquals('Contact', $contact_headers[0]->getText()); + $this->assertSession()->pageTextNotContains('Show contact details'); + $this->assertContactRendering($content_items[2], 'first_general_contact'); - // Assert Organisation's contacts. - $contact_headers = $content_items[2]->findAll('css', 'h2'); - $this->assertEquals($contact_headers[0]->getText(), 'Contact'); - $this->assertContactRendering($content_items[2], 'general_contact'); + // Create another contact and add it to the node. + $second_general_contact = $this->createContactEntity('second_general_contact', 'oe_general', CorporateEntityInterface::PUBLISHED); + $node->set('oe_organisation_contact', [$first_general_contact, $second_general_contact]); + $node->save(); + $this->drupalGet($node->toUrl()); + + // Assert rendering is updated. + $this->assertSession()->pageTextContains('Show contact details'); + $contacts = $content->findAll('css', 'div#-content.ecl-expandable__content div.ecl-row.ecl-u-mv-xl'); + $this->assertCount(2, $contacts); + $this->assertContactRendering($contacts[0], 'first_general_contact'); + $this->assertContactRendering($contacts[1], 'second_general_contact'); } /** @@ -295,7 +307,7 @@ protected function createContactEntity(string $name, string $bundle, int $status protected function assertContactRendering(NodeElement $rendered_element, string $name): void { $contact_sub_headers = $rendered_element->findAll('css', 'h3'); $this->assertCount(1, $contact_sub_headers); - $this->assertEquals($contact_sub_headers[0]->getText(), 'general_contact'); + $this->assertEquals($contact_sub_headers[0]->getText(), $name); // Body field. $body = $rendered_element->findAll('css', '.ecl-editor'); diff --git a/tests/Kernel/OrganisationRenderTest.php b/tests/Kernel/OrganisationRenderTest.php index 9e199b2a2..b3f20eee6 100644 --- a/tests/Kernel/OrganisationRenderTest.php +++ b/tests/Kernel/OrganisationRenderTest.php @@ -11,6 +11,7 @@ use Drupal\Tests\oe_theme\PatternAssertions\PatternAssertState; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\Entity\User; +use Symfony\Component\DomCrawler\Crawler; /** * Tests the organisation rendering. @@ -70,7 +71,7 @@ protected function setUp(): void { */ public function testOrganisationTeaser(): void { $logo_media = $this->createMediaImage('organisation_logo'); - $contact = $this->createContactEntity('organisation_contact', 'oe_general'); + $first_contact = $this->createContactEntity('first_contact', 'oe_general'); $node = Node::create([ 'type' => 'oe_organisation', @@ -87,8 +88,8 @@ public function testOrganisationTeaser(): void { ], 'oe_organisation_contact' => [ [ - 'target_id' => $contact->id(), - 'target_revision_id' => $contact->getRevisionId(), + 'target_id' => $first_contact->id(), + 'target_revision_id' => $first_contact->getRevisionId(), ], ], 'status' => 1, @@ -114,19 +115,19 @@ public function testOrganisationTeaser(): void { 'items' => [ [ 'label' => 'Website', - 'body' => 'http://www.example.com/website_organisation_contact', + 'body' => 'http://www.example.com/website_first_contact', ], [ 'label' => 'Email', - 'body' => 'organisation_contact@example.com', + 'body' => 'first_contact@example.com', ], [ 'label' => 'Phone number', - 'body' => 'Phone number organisation_contact', + 'body' => 'Phone number first_contact', ], [ 'label' => 'Address', - 'body' => 'Address organisation_contact, 1001 Brussels, Belgium', + 'body' => 'Address first_contact, 1001 Brussels, Belgium', ], ], ]), @@ -135,7 +136,43 @@ public function testOrganisationTeaser(): void { $assert->assertPattern($expected_values, $html); $assert->assertVariant('thumbnail_secondary', $html); + // Create another contact and add it to the node. + $second_contact = $this->createContactEntity('second_contact', 'oe_general'); + $node->set('oe_organisation_contact', [$first_contact, $second_contact]); + $node->save(); + + $build = $this->nodeViewBuilder->view($node, 'teaser'); + $html = $this->renderRoot($build); + $crawler = new Crawler($html); + $first_contact_render = $crawler->filter('article .ecl-content-item__additional_information.ecl-u-mb-s div.ecl-u-border-bottom.ecl-u-border-color-grey-15.ecl-u-mb-m.ecl-u-pb-m'); + $this->assertCount(1, $first_contact_render); + + $field_assert = new FieldListAssert(); + $second_contact_expected_values = [ + 'items' => [ + [ + 'label' => 'Website', + 'body' => 'http://www.example.com/website_second_contact', + ], + [ + 'label' => 'Email', + 'body' => 'second_contact@example.com', + ], + [ + 'label' => 'Phone number', + 'body' => 'Phone number second_contact', + ], + [ + 'label' => 'Address', + 'body' => 'Address second_contact, 1001 Brussels, Belgium', + ], + ], + ]; + $second_contact_render = $crawler->filter('article div.ecl-content-item__additional_information.ecl-u-mb-s div:nth-child(2)'); + $field_assert->assertPattern($second_contact_expected_values, $second_contact_render->html()); + // Change organisation type to non eu. + $node->set('oe_organisation_contact', NULL); $node->set('oe_organisation_org_type', 'non_eu'); $node->set('oe_organisation_non_eu_org_type', 'http://data.europa.eu/uxp/5432'); $node->save(); @@ -143,6 +180,7 @@ public function testOrganisationTeaser(): void { $build = $this->nodeViewBuilder->view($node, 'teaser'); $html = $this->renderRoot($build); + $expected_values['additional_information'] = NULL; $expected_values['meta'] = 'embassy | Acronym'; $assert->assertPattern($expected_values, $html); $assert->assertVariant('thumbnail_secondary', $html); From 92203a69b62c7a328952039e95bde53aaab44d3f Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Tue, 6 Apr 2021 10:16:53 +0300 Subject: [PATCH 023/147] EWPP-856: Implementation of block plugin and js. --- .../js/inpage_navigation.js | 23 ++++++++++++++ .../oe_theme_inpage_navigation.libraries.yml | 5 +++ .../oe_theme_inpage_navigation.module | 16 ++++++++++ .../Plugin/Block/InpageNavigationBlock.php | 31 +++++++++++++++++++ ...oe-theme-inpage-navigation-block.html.twig | 10 ++++++ 5 files changed, 85 insertions(+) create mode 100644 modules/oe_theme_inpage_navigation/js/inpage_navigation.js create mode 100644 modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml create mode 100644 modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.module create mode 100644 modules/oe_theme_inpage_navigation/src/Plugin/Block/InpageNavigationBlock.php create mode 100644 modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig diff --git a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js new file mode 100644 index 000000000..1ea4bcdc5 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js @@ -0,0 +1,23 @@ +/** + * @file + * ECL inpage navigation initializer. + */ +(function (ECL, Drupal) { + Drupal.behaviors.eclInPageNavigation = { + attach: function attach(context, settings) { + var elements = document.querySelectorAll('[data-ecl-inpage-navigation]'); + var headers = document.querySelectorAll('h2.ecl-u-type-heading-2'); + li_html = []; + for (var h = 0; h < headers.length; h++) { + id = headers[h].getAttribute('id'); + title = headers[h].innerHTML; + li_html.push('
  • ' + title + '
  • '); + } + for (var i = 0; i < elements.length; i++) { + elements[i].querySelector('ul').innerHTML = li_html.join(' '); + var inpage_navigation = new ECL.InpageNavigation(elements[i]); + inpage_navigation.init(); + } + } + }; +})(ECL, Drupal); diff --git a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml new file mode 100644 index 000000000..8cd7ac60c --- /dev/null +++ b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml @@ -0,0 +1,5 @@ +inpage_navigation: + js: + js/inpage_navigation.js: {} + dependencies: + - core/drupal diff --git a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.module b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.module new file mode 100644 index 000000000..57255d4eb --- /dev/null +++ b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.module @@ -0,0 +1,16 @@ + [ + 'variables' => [ + 'title' => NULL, + ], + ], + ]; +} diff --git a/modules/oe_theme_inpage_navigation/src/Plugin/Block/InpageNavigationBlock.php b/modules/oe_theme_inpage_navigation/src/Plugin/Block/InpageNavigationBlock.php new file mode 100644 index 000000000..20176b1a3 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/src/Plugin/Block/InpageNavigationBlock.php @@ -0,0 +1,31 @@ + 'oe_theme_inpage_navigation_block', + '#title' => $this->t('Page contents'), + ]; + return $build; + } + +} diff --git a/modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig b/modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig new file mode 100644 index 000000000..ced2629b0 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig @@ -0,0 +1,10 @@ +{# +/** + * @file + * Theme override to display in-page navigation for organisation nodes. + * + * @see ./modules/oe_theme_helper/templates/oe-theme-helper-in-page-navigation.html.twig + */ +#} +{{ attach_library('oe_theme_inpage_navigation/inpage_navigation') }} +{% include "oe-theme-helper-in-page-navigation.html.twig" %} From 909ba557ca47809d546fe90c03c1588ad2fd1ff3 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 7 Apr 2021 19:51:56 +0300 Subject: [PATCH 024/147] EWPP-856: Create new left sidebar region. --- oe_theme.info.yml | 1 + ...block--oe-theme-inpage-navigation-menu.html.twig | 9 +++++++++ templates/layout/page.html.twig | 13 ++++++++++++- templates/layout/region--content.html.twig | 9 +++++++++ templates/layout/region--left-sidebar.html.twig | 9 +++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 templates/blocks/block--oe-theme-inpage-navigation-menu.html.twig create mode 100644 templates/layout/region--content.html.twig create mode 100644 templates/layout/region--left-sidebar.html.twig diff --git a/oe_theme.info.yml b/oe_theme.info.yml index 4c7b24163..a01e6bdf7 100644 --- a/oe_theme.info.yml +++ b/oe_theme.info.yml @@ -17,6 +17,7 @@ regions: site_header_secondary: "Site header secondary" page_header: "Page header" navigation: "Navigation" + left_sidebar: "Left sidebar" content: "Content" footer: "Footer" diff --git a/templates/blocks/block--oe-theme-inpage-navigation-menu.html.twig b/templates/blocks/block--oe-theme-inpage-navigation-menu.html.twig new file mode 100644 index 000000000..bb484fe47 --- /dev/null +++ b/templates/blocks/block--oe-theme-inpage-navigation-menu.html.twig @@ -0,0 +1,9 @@ +{# +/** + * @file + * Theme override for the breadcrumb block wrapper. + * + * @see ./core/themes/stable/templates/block/block.html.twig + */ +#} +{% include '@oe_theme/blocks/block--bare.html.twig' %} diff --git a/templates/layout/page.html.twig b/templates/layout/page.html.twig index 0c63a508c..4b6394fb6 100644 --- a/templates/layout/page.html.twig +++ b/templates/layout/page.html.twig @@ -38,7 +38,18 @@
    - {{ page.content }} + {% if page.left_sidebar %} +
    +
    + {{ page.left_sidebar }} +
    +
    + {{ page.content }} +
    +
    + {% else %} + {{ page.content }} + {% endif %}
    diff --git a/templates/layout/region--content.html.twig b/templates/layout/region--content.html.twig new file mode 100644 index 000000000..ef63d91b0 --- /dev/null +++ b/templates/layout/region--content.html.twig @@ -0,0 +1,9 @@ +{# +/** + * @file + * Theme override to display the navigation region. + * + * @see ./core/themes/stable/templates/layout/region.html.twig + */ +#} +{% extends "region--bare.html.twig" %} diff --git a/templates/layout/region--left-sidebar.html.twig b/templates/layout/region--left-sidebar.html.twig new file mode 100644 index 000000000..950afd69f --- /dev/null +++ b/templates/layout/region--left-sidebar.html.twig @@ -0,0 +1,9 @@ +{# +/** + * @file + * Theme override to display the left sidebar region. + * + * @see ./core/themes/stable/templates/layout/region.html.twig + */ +#} +{% extends "region--bare.html.twig" %} From 7363749a1da490056b468d88aa85a32a2d921e96 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 7 Apr 2021 19:59:16 +0300 Subject: [PATCH 025/147] EWPP-856: Update javascript file and template for block. --- .../js/inpage_navigation.js | 12 ++++++++++-- .../oe-theme-inpage-navigation-block.html.twig | 11 +++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js index 1ea4bcdc5..b0e2d551d 100644 --- a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js +++ b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js @@ -9,14 +9,22 @@ var headers = document.querySelectorAll('h2.ecl-u-type-heading-2'); li_html = []; for (var h = 0; h < headers.length; h++) { + if (!headers[h].hasAttribute('id')) { + continue; + } id = headers[h].getAttribute('id'); title = headers[h].innerHTML; li_html.push('
  • ' + title + '
  • '); } + + if (li_html.length === 0) { + document.querySelector('.oe-theme-left-sidebar').remove(); + document.querySelector('.oe-theme-content-region').setAttribute('class', 'ecl-col-12'); + return; + } + for (var i = 0; i < elements.length; i++) { elements[i].querySelector('ul').innerHTML = li_html.join(' '); - var inpage_navigation = new ECL.InpageNavigation(elements[i]); - inpage_navigation.init(); } } }; diff --git a/modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig b/modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig index ced2629b0..dc8cc95dc 100644 --- a/modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig +++ b/modules/oe_theme_inpage_navigation/templates/oe-theme-inpage-navigation-block.html.twig @@ -1,10 +1,13 @@ {# /** * @file - * Theme override to display in-page navigation for organisation nodes. - * - * @see ./modules/oe_theme_helper/templates/oe-theme-helper-in-page-navigation.html.twig + * Theme override to display in-page navigation for nodes. */ #} {{ attach_library('oe_theme_inpage_navigation/inpage_navigation') }} -{% include "oe-theme-helper-in-page-navigation.html.twig" %} +{% block navigation %} + {% include '@ecl-twig/inpage-navigation' with { + 'title': title, + 'icon_path': ecl_icon_path, + } %} +{% endblock %} From 67a784d2e8f1df332e3aa4d0803c1c5e9b00fcc2 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 7 Apr 2021 20:02:13 +0300 Subject: [PATCH 026/147] EWPP-856: Add tests for in-page navigation block. --- .../oe_theme_inpage_navigation.schema.yml | 5 + .../install/block.block.inpage_navigation.yml | 23 +++ .../oe_theme_inpage_navigation_test.info.yml | 7 + ...gation--group-in-page-navigation.html.twig | 40 ++++ .../InPageNavigationBlockTest.php | 176 ++++++++++++++++++ 5 files changed, 251 insertions(+) create mode 100644 modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml create mode 100644 modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.info.yml create mode 100644 modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/templates/oe-theme-helper-in-page-navigation--group-in-page-navigation.html.twig create mode 100644 modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php diff --git a/modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml b/modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml index 398bb1d6b..fe42f9436 100644 --- a/modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml +++ b/modules/oe_theme_inpage_navigation/config/schema/oe_theme_inpage_navigation.schema.yml @@ -6,3 +6,8 @@ node.type.*.third_party.oe_theme_inpage_navigation: type: boolean label: 'Whether to enable in-page navigation for this content type.' +condition.plugin.oe_theme_inpage_navigation_state: + type: condition.plugin + mapping: + inpage_navigation_state: + type: string diff --git a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml new file mode 100644 index 000000000..c9e8bc3a3 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml @@ -0,0 +1,23 @@ +langcode: en +status: true +dependencies: + module: + - oe_theme_inpage_navigation +id: inpage_navigation +theme: oe_theme +region: left_sidebar +weight: 0 +provider: null +plugin: oe_theme_inpage_navigation_menu +settings: + id: oe_theme_inpage_navigation_menu + label: 'Inpage Navigation block' + provider: oe_theme_inpage_navigation + label_display: '0' +visibility: + oe_theme_inpage_navigation_state: + id: oe_theme_inpage_navigation_state + inpage_navigation_state: '1' + negate: false + context_mapping: + node: '@node.node_route_context:node' diff --git a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.info.yml b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.info.yml new file mode 100644 index 000000000..5f479e96c --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.info.yml @@ -0,0 +1,7 @@ +name: 'OpenEuropa Theme In-page Navigation Test' +type: module +description: 'Module for testing in-page navigation functionality' +package: OpenEuropa +core: 8.x +dependencies: + - oe_theme:oe_theme_inpage_navigation diff --git a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/templates/oe-theme-helper-in-page-navigation--group-in-page-navigation.html.twig b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/templates/oe-theme-helper-in-page-navigation--group-in-page-navigation.html.twig new file mode 100644 index 000000000..ac4975f40 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/templates/oe-theme-helper-in-page-navigation--group-in-page-navigation.html.twig @@ -0,0 +1,40 @@ +{# +/** + * @file + * Default template for the 'oe_theme_helper_in_page_navigation' in-page navigation. + * + * Available variables: + * - element: Renderable elements. + * - entity: The rendering object. + * - title: Title of the navigation side. + * - items: In-page navigation items. + * + * @see template_preprocess_oe_theme_helper_in_page_navigation() + * + * @ingroup themeable + */ +#} +{% set _items = [] %} +{% for item in items %} + {# + We need to pre-render each item content so to establish if to show its related navigation link. + This will only work if Twig debug is set to "false" since, otherwise, the element will contain + debug HTML comments, which make the element not empty. + #} + {% set content = item.content|render %} + {% if content|trim is not empty %} + {% set _items = _items|merge([{ + id: item.id, + href: '#' ~ item.id, + label: item.label, + content: content + }]) %} + {% endif %} +{% endfor %} + +{% for item in _items %} + +

    {{ item.label }}

    + {{ item.content }} + +{% endfor %} diff --git a/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php new file mode 100644 index 000000000..f31377ff3 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php @@ -0,0 +1,176 @@ +container->get('theme_installer')->install(['oe_theme']); + $this->container->get('theme_handler')->setDefault('oe_theme'); + $this->container->set('theme.registry', NULL); + + // Enable test module with placed block in new region and overriden + // legacy inpage navigation template. + $this->container->get('module_installer') + ->install(['oe_theme_inpage_navigation_test']); + + // Rebuild the ui_pattern definitions to collect the ones provided by + // oe_theme itself. + \Drupal::service('plugin.manager.ui_patterns')->clearCachedDefinitions(); + + \Drupal::service('emr.installer') + ->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['oe_publication']); + + // Enable inpage_navigation for Publication content. + $ct_with = NodeType::load('oe_publication'); + $ct_with->setThirdPartySetting('oe_theme_inpage_navigation', 'enabled', TRUE); + $ct_with->save(); + } + + /** + * Test in-page entity meta relation plugin. + */ + public function testInPageNavigationForm(): void { + + // Create a document for Publication. + $media_document = $this->createMediaDocument('publication_document'); + + // Create a Publication node with required fields only. + /** @var \Drupal\node\Entity\Node $node */ + $node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->create([ + 'type' => 'oe_publication', + 'title' => 'Test Publication node', + 'oe_publication_type' => 'http://publications.europa.eu/resource/authority/resource-type/ABSTRACT_JUR', + 'oe_documents' => [$media_document], + 'oe_publication_date' => [ + 'value' => '2020-04-15', + ], + 'oe_subject' => 'http://data.europa.eu/uxp/1000', + 'oe_author' => 'http://publications.europa.eu/resource/authority/corporate-body/AASM', + 'oe_content_content_owner' => 'http://publications.europa.eu/resource/authority/corporate-body/COMMU', + 'uid' => 0, + 'status' => 1, + ]); + $node->save(); + $this->drupalGet($node->toUrl()); + + // Assert content part. + $this->assertSession()->elementExists('css', 'main#main-content div.ecl-col-sm-12 div.ecl-row.ecl-u-mt-l div.oe-theme-content-region.ecl-col-lg-9 #block-oe-theme-main-page-content article'); + + // Assert in-page navigation part. + $navigation = $this->assertSession() + ->elementExists('css', 'main#main-content div.ecl-col-sm-12 div.ecl-row.ecl-u-mt-l div.oe-theme-left-sidebar.ecl-col-12.ecl-col-lg-3 nav.ecl-inpage-navigation'); + $inpage_nav_assert = new InPageNavigationAssert(); + $inpage_nav_expected_values = [ + 'title' => 'Page contents', + 'list' => [ + ['label' => 'Details', 'href' => '#details'], + ['label' => 'Files', 'href' => '#files'], + ], + ]; + $inpage_nav_assert->assertPattern($inpage_nav_expected_values, $navigation->getOuterHtml()); + + // Add body field to node and check in-page navigation links. + $node->set('body', 'Publication description text'); + $node->save(); + $this->drupalGet($node->toUrl()); + $inpage_nav_expected_values['list'] = [ + ['label' => 'Details', 'href' => '#details'], + ['label' => 'Description', 'href' => '#description'], + ['label' => 'Files', 'href' => '#files'], + ]; + $inpage_nav_assert->assertPattern($inpage_nav_expected_values, $navigation->getOuterHtml()); + + // Remove body field value of node and check in-page navigation links. + $node->set('body', NULL); + $node->save(); + $this->drupalGet($node->toUrl()); + $inpage_nav_expected_values['list'] = [ + ['label' => 'Details', 'href' => '#details'], + ['label' => 'Files', 'href' => '#files'], + ]; + $inpage_nav_assert->assertPattern($inpage_nav_expected_values, $navigation->getOuterHtml()); + + // Remove body field value of node and check in-page navigation links. + $node->set('oe_documents', NULL); + $node->save(); + $this->drupalGet($node->toUrl()); + $inpage_nav_expected_values['list'] = [ + ['label' => 'Details', 'href' => '#details'], + ]; + $inpage_nav_assert->assertPattern($inpage_nav_expected_values, $navigation->getOuterHtml()); + + // Disable inpage_navigation for Publication content. + $ct_with = NodeType::load('oe_publication'); + $ct_with->setThirdPartySetting('oe_theme_inpage_navigation', 'enabled', FALSE); + $ct_with->save(); + $this->drupalGet($node->toUrl()); + + // Assert absence of in-page navigation block. + $this->assertSession()->elementNotExists('css', 'main#main-content div.ecl-col-sm-12 div.ecl-row.ecl-u-mt-l div.oe-theme-left-sidebar.ecl-col-12.ecl-col-lg-3 nav.ecl-inpage-navigation'); + // Assert content part. + $this->assertSession()->elementExists('css', 'main#main-content div.ecl-col-sm-12 > #block-oe-theme-main-page-content article'); + } + + /** + * Creates media document entity. + * + * @param string $name + * Name of the document media. + * + * @return \Drupal\media\MediaInterface + * Media document instance. + */ + protected function createMediaDocument(string $name): MediaInterface { + // Create file instance. + $file = file_save_data(file_get_contents(drupal_get_path('module', 'oe_media') . '/tests/fixtures/sample.pdf'), "public://sample_$name.pdf"); + $file->setPermanent(); + $file->save(); + + $media = $this->container->get('entity_type.manager') + ->getStorage('media') + ->create([ + 'bundle' => 'document', + 'name' => "Test document $name", + 'oe_media_file_type' => 'local', + 'oe_media_file' => [ + 'target_id' => (int) $file->id(), + ], + 'uid' => 0, + 'status' => 1, + ]); + $media->save(); + + return $media; + } + +} From 9b54f4d527adaee44226bdcf35fbb31aaea51871 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Wed, 7 Apr 2021 21:59:54 +0300 Subject: [PATCH 027/147] EWPP-856: Fixes related to template overriding. --- .../oe_theme_inpage_navigation_test.module | 10 ++++++++++ ...er-in-page-navigation--test-overridden.html.twig} | 12 ++---------- .../InPageNavigationBlockTest.php | 3 +-- 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module rename modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/templates/{oe-theme-helper-in-page-navigation--group-in-page-navigation.html.twig => oe-theme-helper-in-page-navigation--test-overridden.html.twig} (69%) diff --git a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module new file mode 100644 index 000000000..89d514c81 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module @@ -0,0 +1,10 @@ +clearCachedDefinitions(); - \Drupal::service('emr.installer') - ->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['oe_publication']); + \Drupal::service('emr.installer')->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['oe_publication']); // Enable inpage_navigation for Publication content. $ct_with = NodeType::load('oe_publication'); From 5f2c88fe5dd6073d97f0428a8bdd3743b90d3819 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Thu, 15 Apr 2021 19:44:57 +0300 Subject: [PATCH 028/147] EWPP-856: Remove usage of new region and modify test module. --- .../oe_theme_inpage_navigation_test.module | 10 ------ ...page-navigation--test-overridden.html.twig | 32 ------------------- oe_theme.info.yml | 1 - templates/layout/page.html.twig | 13 +------- templates/layout/region--content.html.twig | 9 ------ .../layout/region--left-sidebar.html.twig | 9 ------ 6 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module delete mode 100644 modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/templates/oe-theme-helper-in-page-navigation--test-overridden.html.twig delete mode 100644 templates/layout/region--content.html.twig delete mode 100644 templates/layout/region--left-sidebar.html.twig diff --git a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module deleted file mode 100644 index 89d514c81..000000000 --- a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/oe_theme_inpage_navigation_test.module +++ /dev/null @@ -1,10 +0,0 @@ - -

    {{ item.label }}

    - {{ item.content }} - -{% endfor %} diff --git a/oe_theme.info.yml b/oe_theme.info.yml index a01e6bdf7..4c7b24163 100644 --- a/oe_theme.info.yml +++ b/oe_theme.info.yml @@ -17,7 +17,6 @@ regions: site_header_secondary: "Site header secondary" page_header: "Page header" navigation: "Navigation" - left_sidebar: "Left sidebar" content: "Content" footer: "Footer" diff --git a/templates/layout/page.html.twig b/templates/layout/page.html.twig index 4b6394fb6..0c63a508c 100644 --- a/templates/layout/page.html.twig +++ b/templates/layout/page.html.twig @@ -38,18 +38,7 @@
    - {% if page.left_sidebar %} -
    -
    - {{ page.left_sidebar }} -
    -
    - {{ page.content }} -
    -
    - {% else %} - {{ page.content }} - {% endif %} + {{ page.content }}
    diff --git a/templates/layout/region--content.html.twig b/templates/layout/region--content.html.twig deleted file mode 100644 index ef63d91b0..000000000 --- a/templates/layout/region--content.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{# -/** - * @file - * Theme override to display the navigation region. - * - * @see ./core/themes/stable/templates/layout/region.html.twig - */ -#} -{% extends "region--bare.html.twig" %} diff --git a/templates/layout/region--left-sidebar.html.twig b/templates/layout/region--left-sidebar.html.twig deleted file mode 100644 index 950afd69f..000000000 --- a/templates/layout/region--left-sidebar.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{# -/** - * @file - * Theme override to display the left sidebar region. - * - * @see ./core/themes/stable/templates/layout/region.html.twig - */ -#} -{% extends "region--bare.html.twig" %} From 97e22f6923fcd1103b27093248a4d201486d15e7 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Thu, 15 Apr 2021 19:45:40 +0300 Subject: [PATCH 029/147] EWPP-856: Improve js for in-page navigation block. --- .../js/inpage_navigation.js | 25 ++++++++++--------- .../oe_theme_inpage_navigation.libraries.yml | 1 + ...tent--oe-theme-main-page-content.html.twig | 10 ++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 templates/blocks/block--region-content--oe-theme-main-page-content.html.twig diff --git a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js index b0e2d551d..adfdea4d2 100644 --- a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js +++ b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js @@ -2,30 +2,31 @@ * @file * ECL inpage navigation initializer. */ -(function (ECL, Drupal) { +(function (ECL, Drupal, $) { Drupal.behaviors.eclInPageNavigation = { attach: function attach(context, settings) { + // In-page navigation blocks. var elements = document.querySelectorAll('[data-ecl-inpage-navigation]'); - var headers = document.querySelectorAll('h2.ecl-u-type-heading-2'); + // List of headings inside source element of in-page navigation. + var headers = document.querySelectorAll('div[data-inpage-navigation-source-area] h2.ecl-u-type-heading-2'); li_html = []; for (var h = 0; h < headers.length; h++) { + title = headers[h].innerHTML; if (!headers[h].hasAttribute('id')) { - continue; + // Set id if not available yet in h2 tag. + headers[h].setAttribute('id', title.replace(/\W/g,'-').toLowerCase()) } - id = headers[h].getAttribute('id'); - title = headers[h].innerHTML; + id = $(headers[h]).uniqueId().attr('id'); li_html.push('
  • ' + title + '
  • '); } - if (li_html.length === 0) { - document.querySelector('.oe-theme-left-sidebar').remove(); - document.querySelector('.oe-theme-content-region').setAttribute('class', 'ecl-col-12'); - return; - } - for (var i = 0; i < elements.length; i++) { + if (li_html.length === 0) { + elements[i].remove(); + continue; + } elements[i].querySelector('ul').innerHTML = li_html.join(' '); } } }; -})(ECL, Drupal); +})(ECL, Drupal, jQuery); diff --git a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml index 8cd7ac60c..37a9371d5 100644 --- a/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml +++ b/modules/oe_theme_inpage_navigation/oe_theme_inpage_navigation.libraries.yml @@ -3,3 +3,4 @@ inpage_navigation: js/inpage_navigation.js: {} dependencies: - core/drupal + - core/jquery.ui diff --git a/templates/blocks/block--region-content--oe-theme-main-page-content.html.twig b/templates/blocks/block--region-content--oe-theme-main-page-content.html.twig new file mode 100644 index 000000000..d761a78c3 --- /dev/null +++ b/templates/blocks/block--region-content--oe-theme-main-page-content.html.twig @@ -0,0 +1,10 @@ +{# +/** + * @file + * Theme override for blocks in the content region for page content block. + * + * @see ./block--region-content.html.twig + */ +#} +{% extends 'block--region-content.html.twig' %} +{% set attributes = attributes.setAttribute('data-inpage-navigation-source-area', 'true') %} From b52045e87526493737860c76591cf7ccf261b595 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Thu, 15 Apr 2021 19:48:17 +0300 Subject: [PATCH 030/147] EWPP-856: Update tests and block config. --- .../install/block.block.inpage_navigation.yml | 2 +- .../InPageNavigationBlockTest.php | 88 ++++++++++++++++--- 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml index c9e8bc3a3..89e7f5ede 100644 --- a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml +++ b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/block.block.inpage_navigation.yml @@ -5,7 +5,7 @@ dependencies: - oe_theme_inpage_navigation id: inpage_navigation theme: oe_theme -region: left_sidebar +region: content weight: 0 provider: null plugin: oe_theme_inpage_navigation_menu diff --git a/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php index 2b35354f6..3bb5f7ecc 100644 --- a/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php +++ b/modules/oe_theme_inpage_navigation/tests/src/FunctionalJavascript/InPageNavigationBlockTest.php @@ -7,6 +7,7 @@ use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\media\MediaInterface; use Drupal\node\Entity\NodeType; +use Drupal\oe_theme_inpage_navigation\InPageNavigationHelper; use Drupal\Tests\oe_theme\PatternAssertions\InPageNavigationAssert; /** @@ -20,6 +21,7 @@ class InPageNavigationBlockTest extends WebDriverTestBase { protected static $modules = [ 'block', 'oe_theme_helper', + 'oe_theme_content_page', 'oe_theme_content_publication', 'oe_theme_content_organisation', 'oe_theme_content_organisation_reference', @@ -36,8 +38,7 @@ public function setUp() { $this->container->get('theme_handler')->setDefault('oe_theme'); $this->container->set('theme.registry', NULL); - // Enable test module with placed block in new region and overriden - // legacy inpage navigation template. + // Enable test module with placed block in new region. $this->container->get('module_installer') ->install(['oe_theme_inpage_navigation_test']); @@ -45,7 +46,7 @@ public function setUp() { // oe_theme itself. \Drupal::service('plugin.manager.ui_patterns')->clearCachedDefinitions(); - \Drupal::service('emr.installer')->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['oe_publication']); + \Drupal::service('emr.installer')->installEntityMetaTypeOnContentEntityType('oe_theme_inpage_navigation', 'node', ['oe_publication', 'oe_page']); // Enable inpage_navigation for Publication content. $ct_with = NodeType::load('oe_publication'); @@ -54,9 +55,9 @@ public function setUp() { } /** - * Test in-page entity meta relation plugin. + * Test content with enabled legacy in-page navigation by default. */ - public function testInPageNavigationForm(): void { + public function testContentWithInPageNav(): void { // Create a document for Publication. $media_document = $this->createMediaDocument('publication_document'); @@ -83,11 +84,10 @@ public function testInPageNavigationForm(): void { $this->drupalGet($node->toUrl()); // Assert content part. - $this->assertSession()->elementExists('css', 'main#main-content div.ecl-col-sm-12 div.ecl-row.ecl-u-mt-l div.oe-theme-content-region.ecl-col-lg-9 #block-oe-theme-main-page-content article'); + $this->assertSession()->elementExists('css', '#block-oe-theme-main-page-content[data-inpage-navigation-source-area] article'); // Assert in-page navigation part. - $navigation = $this->assertSession() - ->elementExists('css', 'main#main-content div.ecl-col-sm-12 div.ecl-row.ecl-u-mt-l div.oe-theme-left-sidebar.ecl-col-12.ecl-col-lg-3 nav.ecl-inpage-navigation'); + $navigation = $this->assertSession()->elementExists('css', '#block-inpage-navigation nav[data-ecl-inpage-navigation]'); $inpage_nav_assert = new InPageNavigationAssert(); $inpage_nav_expected_values = [ 'title' => 'Page contents', @@ -135,9 +135,77 @@ public function testInPageNavigationForm(): void { $this->drupalGet($node->toUrl()); // Assert absence of in-page navigation block. - $this->assertSession()->elementNotExists('css', 'main#main-content div.ecl-col-sm-12 div.ecl-row.ecl-u-mt-l div.oe-theme-left-sidebar.ecl-col-12.ecl-col-lg-3 nav.ecl-inpage-navigation'); + $this->assertSession()->elementNotExists('css', '#block-inpage-navigation nav[data-ecl-inpage-navigation]'); // Assert content part. - $this->assertSession()->elementExists('css', 'main#main-content div.ecl-col-sm-12 > #block-oe-theme-main-page-content article'); + $this->assertSession()->elementExists('css', '#block-oe-theme-main-page-content[data-inpage-navigation-source-area] article'); + } + + /** + * Test content with disabled legacy in-page navigation by default. + */ + public function testContentWithoutInPageNav(): void { + // Create a Page node with required fields only. + /** @var \Drupal\node\Entity\Node $node */ + $node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->create([ + 'type' => 'oe_page', + 'title' => 'Test Page node', + 'oe_teaser' => 'Teaser text', + 'oe_content_content_owner' => 'http://publications.europa.eu/resource/authority/corporate-body/COMMU', + 'uid' => 0, + 'status' => 1, + ]); + $node->save(); + $this->drupalGet($node->toUrl()); + + // Assert content part. + $this->assertSession()->elementExists('css', '#block-oe-theme-main-page-content[data-inpage-navigation-source-area] article'); + // Assert absence of in-page navigation block. + $this->assertSession()->elementNotExists('css', '#block-inpage-navigation nav[data-ecl-inpage-navigation]'); + + InPageNavigationHelper::enableInPageNavigation($node); + $node->save(); + $this->drupalGet($node->toUrl()); + + // Check that in-page navigation block still not visible. + $this->assertSession()->elementNotExists('css', 'nav[data-ecl-inpage-navigation]'); + + // Check that in-page navigation block visible when available + // heading in content. + $node->set('oe_related_links', [ + [ + 'uri' => 'internal:/node', + 'title' => 'Node listing', + ], + [ + 'uri' => 'https://example.com', + 'title' => 'External link', + ], + ]); + $node->save(); + $this->drupalGet($node->toUrl()); + // Assert in-page navigation part. + $navigation = $this->assertSession()->elementExists('css', '#block-inpage-navigation nav[data-ecl-inpage-navigation]'); + $inpage_nav_assert = new InPageNavigationAssert(); + $inpage_nav_expected_values = [ + 'title' => 'Page contents', + 'list' => [ + ['label' => 'Related links', 'href' => '#related-links'], + ], + ]; + $inpage_nav_assert->assertPattern($inpage_nav_expected_values, $navigation->getOuterHtml()); + + // Check that in-page navigation block is hidden when + // we don't have anymore heading elements. + $node->set('oe_related_links', NULL); + $node->save(); + $this->drupalGet($node->toUrl()); + + // Assert content part. + $this->assertSession()->elementExists('css', '#block-oe-theme-main-page-content[data-inpage-navigation-source-area] article'); + // Assert absence of in-page navigation block. + $this->assertSession()->elementNotExists('css', '#block-inpage-navigation nav[data-ecl-inpage-navigation]'); } /** From 4c9787d739c796cf307dd78ef599d218c790c3c5 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Fri, 16 Apr 2021 12:45:14 +0300 Subject: [PATCH 031/147] EWPP-856: Update in-page navigation js for adjusting template if we going to remove in-page navigation element. --- modules/oe_theme_inpage_navigation/js/inpage_navigation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js index adfdea4d2..32532be3d 100644 --- a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js +++ b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js @@ -22,6 +22,9 @@ for (var i = 0; i < elements.length; i++) { if (li_html.length === 0) { + // Adjust layout if we going to remove in-page element. + $(elements[i]).closest('.ecl-col-lg-3').next('.ecl-col-lg-9').removeClass('ecl-col-lg-9').addClass('ecl-col-lg-12') + // Remove in-page navigation element if we don't have links inside. elements[i].remove(); continue; } From 9de764a769f5d04eedfb03c76b8493f220619909 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Tue, 20 Apr 2021 18:57:19 +0300 Subject: [PATCH 032/147] EWPP-856: Add consideration of h2 tags inside dedicated elements and extend tests coverage. --- .../js/inpage_navigation.js | 4 +-- .../install/filter.format.full_html.yml | 27 +++++++++++++++++++ .../InPageNavigationBlockTest.php | 23 ++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/filter.format.full_html.yml diff --git a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js index 32532be3d..4aa2af964 100644 --- a/modules/oe_theme_inpage_navigation/js/inpage_navigation.js +++ b/modules/oe_theme_inpage_navigation/js/inpage_navigation.js @@ -8,8 +8,8 @@ // In-page navigation blocks. var elements = document.querySelectorAll('[data-ecl-inpage-navigation]'); // List of headings inside source element of in-page navigation. - var headers = document.querySelectorAll('div[data-inpage-navigation-source-area] h2.ecl-u-type-heading-2'); - li_html = []; + var headers = document.querySelectorAll('div[data-inpage-navigation-source-area] h2'); + var li_html = []; for (var h = 0; h < headers.length; h++) { title = headers[h].innerHTML; if (!headers[h].hasAttribute('id')) { diff --git a/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/filter.format.full_html.yml b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/filter.format.full_html.yml new file mode 100644 index 000000000..29c733815 --- /dev/null +++ b/modules/oe_theme_inpage_navigation/tests/modules/oe_theme_inpage_navigation_test/config/install/filter.format.full_html.yml @@ -0,0 +1,27 @@ +langcode: en +status: true +dependencies: + module: + - media +name: 'Full HTML' +format: full_html +weight: 0 +filters: + filter_html: + id: filter_html + provider: filter + status: true + weight: -10 + settings: + allowed_html: '