Skip to content

Commit

Permalink
Merge pull request #901 from openeuropa/EWPP-1362
Browse files Browse the repository at this point in the history
[EWPP-1360] EWPP-1362: Use PublicationDate extra field to display the publication date and last update date fields for News.
  • Loading branch information
22Alexandra authored Aug 5, 2021
2 parents 55865bb + 46dea81 commit 8369a15
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 25 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ''
Expand All @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +19,7 @@
* label = @Translation("Publication date"),
* bundles = {
* "node.oe_publication",
* "node.oe_news",
* },
* visible = true
* )
Expand All @@ -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.
*
Expand Down Expand Up @@ -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]),
],
];
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Functional/ContentNewsRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 8369a15

Please sign in to comment.