diff --git a/docker-compose.yml b/docker-compose.yml index 5f9933e42..e93efe5b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: XDEBUG_MODE: "develop, debug" PHP_IDE_CONFIG: "serverName=Docker" # Enable step debugging for all PHP request. See ./README.md#step-debugging for more information. - XDEBUG_SESSION: 1 + # XDEBUG_SESSION: 1 mysql: image: percona/percona-server:5.7 command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 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..97aef784b 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,11 +2,15 @@ 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_departments - 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_sources - field.field.node.oe_news.oe_news_types - field.field.node.oe_news.oe_publication_date - field.field.node.oe_news.oe_reference_code @@ -16,7 +20,6 @@ dependencies: - field.field.node.oe_news.oe_teaser - node.type.oe_news module: - - datetime - entity_reference_revisions - field_group - link @@ -28,11 +31,12 @@ third_party_settings: group_details: children: - oe_reference_code - - oe_publication_date + - extra_field_oe_theme_content_news_date - oe_author + - oe_departments - oe_news_location parent_name: '' - weight: 1 + weight: 3 format_type: oe_theme_helper_field_list_pattern region: content format_settings: @@ -50,14 +54,10 @@ content: settings: { } third_party_settings: { } region: content - oe_news_contacts: - type: entity_reference_revisions_entity_view - weight: 2 + extra_field_oe_theme_content_news_date: + weight: 13 region: content - label: above - settings: - view_mode: full - link: '' + settings: { } third_party_settings: { } oe_author: type: skos_concept_entity_reference_label @@ -67,7 +67,7 @@ content: settings: link: false third_party_settings: { } - oe_news_location: + oe_departments: type: skos_concept_entity_reference_label weight: 15 region: content @@ -75,14 +75,34 @@ content: settings: link: false third_party_settings: { } - oe_publication_date: - type: datetime_default - weight: 13 + oe_news_contacts: + type: entity_reference_revisions_entity_view + weight: 4 region: content label: above settings: - timezone_override: '' - format_type: oe_theme_news_date + 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_news_sources: + type: link + weight: 1 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' third_party_settings: { } oe_reference_code: type: string @@ -94,7 +114,7 @@ content: third_party_settings: { } oe_related_links: type: link - weight: 3 + weight: 5 region: content label: hidden settings: @@ -113,7 +133,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/install/core.entity_view_display.node.oe_news.teaser.yml b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.teaser.yml index 6d935aed6..90dc8cbb9 100644 --- a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.teaser.yml +++ b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.teaser.yml @@ -5,10 +5,15 @@ dependencies: - core.entity_view_mode.node.teaser - field.field.node.oe_news.body - field.field.node.oe_news.oe_author + - field.field.node.oe_news.oe_departments + - 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_sources - 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 @@ -65,6 +70,7 @@ content: third_party_settings: { } hidden: body: true + extra_field_oe_theme_content_news_date: true langcode: true links: true oe_author: true @@ -72,7 +78,12 @@ hidden: oe_content_legacy_link: true oe_content_navigation_title: true oe_content_short_title: true + oe_departments: true + oe_news_contacts: true + oe_news_last_updated: true oe_news_location: true + oe_news_sources: true + oe_reference_code: true oe_related_links: true oe_subject: true oe_summary: 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..97aef784b --- /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,141 @@ +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_departments + - 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_sources + - 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: + - 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_news_date + - oe_author + - oe_departments + - oe_news_location + parent_name: '' + weight: 3 + 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_news_date: + weight: 13 + region: content + settings: { } + third_party_settings: { } + oe_author: + type: skos_concept_entity_reference_label + weight: 14 + region: content + label: above + settings: + link: false + third_party_settings: { } + oe_departments: + 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: 4 + 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_news_sources: + type: link + weight: 1 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' + 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: 5 + 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.module b/modules/oe_theme_content_news/oe_theme_content_news.module index 35bc55296..869f11423 100644 --- a/modules/oe_theme_content_news/oe_theme_content_news.module +++ b/modules/oe_theme_content_news/oe_theme_content_news.module @@ -57,12 +57,21 @@ function oe_theme_content_news_node_view_alter(array &$build, EntityInterface $e // Rename field labels based on number of items. $plural_label_overrides = [ 'oe_author' => t('Authors'), + 'oe_departments' => t('Departments'), + ]; + + $singular_label_overrides = [ + 'oe_departments' => t('Department'), ]; foreach ($plural_label_overrides as $name => $label_override) { if (!$entity->get($name)->isEmpty() && $entity->get($name)->count() > 1 && isset($build[$name]['#title'])) { $build[$name]['#title'] = $label_override; } + // Override singular labels if defined. + elseif (!$entity->get($name)->isEmpty() && $entity->get($name)->count() == 1 && isset($build[$name]['#title']) && isset($singular_label_overrides[$name])) { + $build[$name]['#title'] = $singular_label_overrides[$name]; + } } } } 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_news/src/Plugin/ExtraField/Display/PublicationDate.php b/modules/oe_theme_content_news/src/Plugin/ExtraField/Display/PublicationDate.php new file mode 100644 index 000000000..3e65ee6ca --- /dev/null +++ b/modules/oe_theme_content_news/src/Plugin/ExtraField/Display/PublicationDate.php @@ -0,0 +1,31 @@ +renderPublicationDateExtraField($entity, 'oe_theme_news_date'); + } + +} diff --git a/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php b/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php index 2be896326..d04cac246 100644 --- a/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php +++ b/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php @@ -5,11 +5,7 @@ namespace Drupal\oe_theme_content_publication\Plugin\ExtraField\Display; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\oe_theme_helper\Plugin\ExtraField\Display\PublicationDateExtraFieldBase; /** * Displays publication date and last update date fields. @@ -23,74 +19,13 @@ * visible = true * ) */ -class PublicationDate extends ExtraFieldDisplayFormattedBase implements ContainerFactoryPluginInterface { - - use StringTranslationTrait; - - /** - * Date formatter service instance. - * - * @var \Drupal\Core\Datetime\DateFormatterInterface - */ - protected $dateFormatter; - - /** - * PublicationDate constructor. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter - * Date formatter. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->dateFormatter = $date_formatter; - } +class PublicationDate extends PublicationDateExtraFieldBase { /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('date.formatter') - ); - } - - /** - * {@inheritdoc} - */ - public function getLabel() { - return $this->t('Publication date'); - } - - /** - * {@inheritdoc} - */ - public function viewElements(ContentEntityInterface $entity) { - $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()) { - return [ - '#markup' => $publication_date, - ]; - } - - $last_update_timestamp = $entity->get('oe_publication_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'), - ], - ]; + public function viewElements(ContentEntityInterface $entity): array { + return $this->renderPublicationDateExtraField($entity, 'oe_theme_publication_date'); } } diff --git a/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDateExtraFieldBase.php b/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDateExtraFieldBase.php new file mode 100644 index 000000000..133f6bfb4 --- /dev/null +++ b/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDateExtraFieldBase.php @@ -0,0 +1,96 @@ +dateFormatter = $date_formatter; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('date.formatter') + ); + } + + /** + * {@inheritdoc} + */ + public function getLabel() { + return $this->t('Publication date'); + } + + /** + * Render the publication date field with the specified date format. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * The entity the field is being rendered on. + * @param string $date_format + * The date format to use. + * + * @return array + * The render array. + */ + protected function renderPublicationDateExtraField(ContentEntityInterface $entity, string $date_format): array { + $bundle = $entity->bundle(); + $publication_date_timestamp = $entity->get('oe_publication_date')->date->getTimestamp(); + $publication_date = $this->dateFormatter->format($publication_date_timestamp, $date_format); + if ($entity->get($bundle . '_last_updated')->isEmpty()) { + return [ + '#markup' => $publication_date, + ]; + } + + $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, $date_format), + ], + ]; + } + +} diff --git a/oe_theme.theme b/oe_theme.theme index 871c7a0ae..a5a4d7a49 100644 --- a/oe_theme.theme +++ b/oe_theme.theme @@ -430,20 +430,6 @@ function oe_theme_preprocess_field(&$variables, $hook): void { $item['content']['#attributes']['class'][] = 'ecl-u-height-auto'; } } - - if ($variables['field_name'] === 'oe_related_links') { - foreach ($variables['items'] as $delta => $item) { - $variables['items'][$delta]['content'] = [ - '#type' => 'pattern', - '#id' => 'list_item', - '#variant' => 'default', - '#fields' => [ - 'url' => $item['content']['#url'], - 'title' => $item['content']['#title'], - ], - ]; - } - } } /** diff --git a/templates/field/field--node--oe-departments--oe-news--full.html.twig b/templates/field/field--node--oe-departments--oe-news--full.html.twig new file mode 100644 index 000000000..22aa0b583 --- /dev/null +++ b/templates/field/field--node--oe-departments--oe-news--full.html.twig @@ -0,0 +1,9 @@ +{# +/** + * @file + * Theme override for the Related department field template of the News content type. + * + * @see ./core/themes/stable/templates/field/field.html.twig + */ +#} +{%- include 'field--multiple-values--pipe-separated.html.twig' -%} diff --git a/templates/field/field--node--oe-news-sources--oe-news--full.html.twig b/templates/field/field--node--oe-news-sources--oe-news--full.html.twig new file mode 100644 index 000000000..32e1aa1ed --- /dev/null +++ b/templates/field/field--node--oe-news-sources--oe-news--full.html.twig @@ -0,0 +1,23 @@ +{# +/** + * @file + * News sources field template. + * + * @see ./core/themes/stable/templates/field/field.html.twig + */ +#} +