diff --git a/composer.json b/composer.json index 21581da06..05079fb5b 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "openeuropa/behat-transformation-context": "~0.1", "openeuropa/code-review": "~1.5", "openeuropa/drupal-core-require-dev": "^8.9.14", - "openeuropa/oe_content": "2.x-dev", + "openeuropa/oe_content": "dev-EWPP-1362", "openeuropa/oe_corporate_blocks": "~4.0", "openeuropa/oe_corporate_countries": "~2.0", "openeuropa/oe_media": "~1.12", diff --git a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml index 031243316..34eddde0d 100644 --- a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml +++ b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml @@ -2,10 +2,12 @@ langcode: en status: true dependencies: config: + - core.entity_view_mode.node.full - field.field.node.oe_news.body - field.field.node.oe_news.oe_author - field.field.node.oe_news.oe_news_contacts - field.field.node.oe_news.oe_news_featured_media + - field.field.node.oe_news.oe_news_last_updated - field.field.node.oe_news.oe_news_location - field.field.node.oe_news.oe_news_types - field.field.node.oe_news.oe_publication_date @@ -28,7 +30,7 @@ third_party_settings: group_details: children: - oe_reference_code - - oe_publication_date + - extra_field_oe_theme_content_publication_date - oe_author - oe_news_location parent_name: '' @@ -50,39 +52,35 @@ content: settings: { } third_party_settings: { } region: content - oe_news_contacts: - type: entity_reference_revisions_entity_view - weight: 2 + extra_field_oe_theme_content_publication_date: + weight: 13 region: content - label: above - settings: - view_mode: full - link: '' + settings: { } third_party_settings: { } oe_author: type: skos_concept_entity_reference_label - weight: 14 + weight: 15 region: content label: above settings: link: false third_party_settings: { } - oe_news_location: - type: skos_concept_entity_reference_label - weight: 15 + oe_news_contacts: + type: entity_reference_revisions_entity_view + weight: 2 region: content label: above settings: - link: false + view_mode: full + link: '' third_party_settings: { } - oe_publication_date: - type: datetime_default - weight: 13 + oe_news_location: + type: skos_concept_entity_reference_label + weight: 16 region: content label: above settings: - timezone_override: '' - format_type: oe_theme_news_date + link: false third_party_settings: { } oe_reference_code: type: string @@ -113,7 +111,9 @@ hidden: oe_content_navigation_title: true oe_content_short_title: true oe_news_featured_media: true + oe_news_last_updated: true oe_news_types: true + oe_publication_date: true oe_subject: true oe_summary: true oe_teaser: true diff --git a/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml b/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml new file mode 100644 index 000000000..34eddde0d --- /dev/null +++ b/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml @@ -0,0 +1,119 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.node.full + - field.field.node.oe_news.body + - field.field.node.oe_news.oe_author + - field.field.node.oe_news.oe_news_contacts + - field.field.node.oe_news.oe_news_featured_media + - field.field.node.oe_news.oe_news_last_updated + - field.field.node.oe_news.oe_news_location + - field.field.node.oe_news.oe_news_types + - field.field.node.oe_news.oe_publication_date + - field.field.node.oe_news.oe_reference_code + - field.field.node.oe_news.oe_related_links + - field.field.node.oe_news.oe_subject + - field.field.node.oe_news.oe_summary + - field.field.node.oe_news.oe_teaser + - node.type.oe_news + module: + - datetime + - entity_reference_revisions + - field_group + - link + - rdf_skos + - text + - user +third_party_settings: + field_group: + group_details: + children: + - oe_reference_code + - extra_field_oe_theme_content_publication_date + - oe_author + - oe_news_location + parent_name: '' + weight: 1 + format_type: oe_theme_helper_field_list_pattern + region: content + format_settings: + variant: horizontal + label: Details +id: node.oe_news.full +targetEntityType: node +bundle: oe_news +mode: full +content: + body: + label: hidden + type: text_default + weight: 0 + settings: { } + third_party_settings: { } + region: content + extra_field_oe_theme_content_publication_date: + weight: 13 + region: content + settings: { } + third_party_settings: { } + oe_author: + type: skos_concept_entity_reference_label + weight: 15 + region: content + label: above + settings: + link: false + third_party_settings: { } + oe_news_contacts: + type: entity_reference_revisions_entity_view + weight: 2 + region: content + label: above + settings: + view_mode: full + link: '' + third_party_settings: { } + oe_news_location: + type: skos_concept_entity_reference_label + weight: 16 + region: content + label: above + settings: + link: false + third_party_settings: { } + oe_reference_code: + type: string + weight: 12 + region: content + label: above + settings: + link_to_entity: false + third_party_settings: { } + oe_related_links: + type: link + weight: 3 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' + third_party_settings: { } +hidden: + extra_field_oe_theme_helper_short_title_with_fallback: true + langcode: true + links: true + oe_content_content_owner: true + oe_content_legacy_link: true + oe_content_navigation_title: true + oe_content_short_title: true + oe_news_featured_media: true + oe_news_last_updated: true + oe_news_types: true + oe_publication_date: true + oe_subject: true + oe_summary: true + oe_teaser: true diff --git a/modules/oe_theme_content_news/oe_theme_content_news.post_update.php b/modules/oe_theme_content_news/oe_theme_content_news.post_update.php index 82105ef58..a4627b945 100644 --- a/modules/oe_theme_content_news/oe_theme_content_news.post_update.php +++ b/modules/oe_theme_content_news/oe_theme_content_news.post_update.php @@ -131,3 +131,23 @@ function oe_theme_content_news_post_update_00008(): void { $display = $storage->createFromStorageRecord($display_values); $display->save(); } + +/** + * Updates the full view display. + */ +function oe_theme_content_news_post_update_00009(): void { + $storage = new FileStorage(drupal_get_path('module', 'oe_theme_content_news') . '/config/post_updates/00009_update_full_view_display'); + + $display_values = $storage->read('core.entity_view_display.node.oe_news.full'); + $storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); + + $view_display = EntityViewDisplay::load($display_values['id']); + if ($view_display) { + $display = $storage->updateFromStorageRecord($view_display, $display_values); + $display->save(); + return; + } + + $display = $storage->createFromStorageRecord($display_values); + $display->save(); +} diff --git a/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php b/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDate.php similarity index 80% rename from modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php rename to modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDate.php index 2be896326..ef825b6cb 100644 --- a/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php +++ b/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDate.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace Drupal\oe_theme_content_publication\Plugin\ExtraField\Display; +namespace Drupal\oe_theme_helper\Plugin\ExtraField\Display; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -19,6 +19,7 @@ * label = @Translation("Publication date"), * bundles = { * "node.oe_publication", + * "node.oe_news", * }, * visible = true * ) @@ -27,6 +28,16 @@ class PublicationDate extends ExtraFieldDisplayFormattedBase implements Containe use StringTranslationTrait; + /** + * Date formats keyed by bundle ids. + * + * @var string[] + */ + protected $dateFormats = [ + 'oe_publication' => 'oe_theme_publication_date', + 'oe_news' => 'oe_theme_news_date', + ]; + /** * Date formatter service instance. * @@ -73,22 +84,23 @@ public function getLabel() { /** * {@inheritdoc} */ - public function viewElements(ContentEntityInterface $entity) { + public function viewElements(ContentEntityInterface $entity): array { + $bundle = $entity->bundle(); $publication_date_timestamp = $entity->get('oe_publication_date')->date->getTimestamp(); - $publication_date = $this->dateFormatter->format($publication_date_timestamp, 'oe_theme_publication_date'); - if ($entity->get('oe_publication_last_updated')->isEmpty()) { + $publication_date = $this->dateFormatter->format($publication_date_timestamp, $this->dateFormats[$bundle]); + if ($entity->get($bundle . '_last_updated')->isEmpty()) { return [ '#markup' => $publication_date, ]; } - $last_update_timestamp = $entity->get('oe_publication_last_updated')->date->getTimestamp(); + $last_update_timestamp = $entity->get($bundle . '_last_updated')->date->getTimestamp(); return [ '#type' => 'inline_template', '#template' => "{{ publication_date }} ({{'Last updated on: @date'|t({'@date': last_update}) }})", '#context' => [ 'publication_date' => $publication_date, - 'last_update' => $this->dateFormatter->format($last_update_timestamp, 'oe_theme_publication_date'), + 'last_update' => $this->dateFormatter->format($last_update_timestamp, $this->dateFormats[$bundle]), ], ]; } diff --git a/tests/Functional/ContentNewsRenderTest.php b/tests/Functional/ContentNewsRenderTest.php index 2b97d3c51..6c91a5646 100644 --- a/tests/Functional/ContentNewsRenderTest.php +++ b/tests/Functional/ContentNewsRenderTest.php @@ -124,6 +124,14 @@ public function testNewsRendering(): void { $field_list_assert->assertPattern($details_expected_values, $details_html); $field_list_assert->assertVariant('horizontal', $details_html); + // Assert Last update date field. + $node->set('oe_news_last_updated', '2021-08-04')->save(); + $this->drupalGet($node->toUrl()); + + $details_expected_values['items'][1]['body'] = '18 September 2020 (Last updated on: 4 August 2021)'; + $details_html = $details->getHtml(); + $field_list_assert->assertPattern($details_expected_values, $details_html); + // Assert Author field label. $node->set('oe_author', [ ['target_id' => 'http://publications.europa.eu/resource/authority/corporate-body/ACJHR'],