diff --git a/composer.json b/composer.json index 762f26507..c438e515d 100644 --- a/composer.json +++ b/composer.json @@ -95,6 +95,9 @@ "patches": { "drupal/entity_reference_revisions": { "https://www.drupal.org/project/entity_reference_revisions/issues/2937835": "https://www.drupal.org/files/issues/2021-03-26/entity_reference_revisions-field_formatter_label-2937835-36.patch" + }, + "openeuropa/oe_bootstrap_theme": { + "latest": "https://github.com/openeuropa/oe_bootstrap_theme/compare/0.1.202208041835...1.x.diff" } }, "drupal-scaffold": { diff --git a/modules/oe_whitelabel_starter_event/config/install/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml b/modules/oe_whitelabel_starter_event/config/install/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml index bd0d1312b..a2142027e 100644 --- a/modules/oe_whitelabel_starter_event/config/install/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml +++ b/modules/oe_whitelabel_starter_event/config/install/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml @@ -12,8 +12,6 @@ dependencies: - field.field.node.oe_sc_event.oe_summary - node.type.oe_sc_event module: - - link - - oe_content_featured_media_field - text - user id: node.oe_sc_event.oe_w_content_banner @@ -21,26 +19,6 @@ targetEntityType: node bundle: oe_sc_event mode: oe_w_content_banner content: - oe_featured_media: - type: oe_featured_media_label - label: hidden - settings: - link: true - third_party_settings: { } - weight: 1 - region: content - oe_sc_event_registration_url: - type: link - label: above - settings: - trim_length: 80 - url_only: false - url_plain: false - rel: '' - target: '' - third_party_settings: { } - weight: 2 - region: content oe_summary: type: text_default label: hidden @@ -57,6 +35,8 @@ hidden: oe_content_navigation_title: true oe_content_short_title: true oe_documents: true + oe_featured_media: true oe_sc_event_dates: true oe_sc_event_location: true + oe_sc_event_registration_url: true search_api_excerpt: true diff --git a/modules/oe_whitelabel_starter_event/config/post_updates/00003_add_registration_url_field/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml b/modules/oe_whitelabel_starter_event/config/post_updates/00003_add_registration_url_field/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml index bd0d1312b..a2142027e 100644 --- a/modules/oe_whitelabel_starter_event/config/post_updates/00003_add_registration_url_field/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml +++ b/modules/oe_whitelabel_starter_event/config/post_updates/00003_add_registration_url_field/core.entity_view_display.node.oe_sc_event.oe_w_content_banner.yml @@ -12,8 +12,6 @@ dependencies: - field.field.node.oe_sc_event.oe_summary - node.type.oe_sc_event module: - - link - - oe_content_featured_media_field - text - user id: node.oe_sc_event.oe_w_content_banner @@ -21,26 +19,6 @@ targetEntityType: node bundle: oe_sc_event mode: oe_w_content_banner content: - oe_featured_media: - type: oe_featured_media_label - label: hidden - settings: - link: true - third_party_settings: { } - weight: 1 - region: content - oe_sc_event_registration_url: - type: link - label: above - settings: - trim_length: 80 - url_only: false - url_plain: false - rel: '' - target: '' - third_party_settings: { } - weight: 2 - region: content oe_summary: type: text_default label: hidden @@ -57,6 +35,8 @@ hidden: oe_content_navigation_title: true oe_content_short_title: true oe_documents: true + oe_featured_media: true oe_sc_event_dates: true oe_sc_event_location: true + oe_sc_event_registration_url: true search_api_excerpt: true diff --git a/modules/oe_whitelabel_starter_event/oe_whitelabel_starter_event.module b/modules/oe_whitelabel_starter_event/oe_whitelabel_starter_event.module index cb7742159..bab7c35c9 100755 --- a/modules/oe_whitelabel_starter_event/oe_whitelabel_starter_event.module +++ b/modules/oe_whitelabel_starter_event/oe_whitelabel_starter_event.module @@ -7,12 +7,13 @@ declare(strict_types = 1); +use Drupal\Component\Utility\Html; use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Template\Attribute; use Drupal\media\MediaInterface; use Drupal\media\Plugin\media\Source\Image; use Drupal\media_avportal\Plugin\media\Source\MediaAvPortalPhotoSource; use Drupal\oe_bootstrap_theme\ValueObject\ImageValueObject; -use Drupal\Component\Utility\Html; /** * Implements template_preprocess_node() for the Event node type. @@ -26,6 +27,52 @@ function oe_whitelabel_starter_event_preprocess_node__oe_sc_event__full(&$variab */ function oe_whitelabel_starter_event_preprocess_node__oe_sc_event__oe_w_content_banner(&$variables) { _oe_whitelabel_starter_event_preprocess_featured_media($variables); + _oe_whitelabel_starter_event_preprocess_links($variables); +} + +/** + * Helper function to preprocess the content banner links. + * + * @param array $variables + * Render array variables. + */ +function _oe_whitelabel_starter_event_preprocess_links(array &$variables): void { + /** @var \Drupal\node\NodeInterface $node */ + $node = $variables['node']; + $registration_url = $node->get('oe_sc_event_registration_url'); + + // Bail out if there is no link item. + if ($registration_url->isEmpty()) { + return; + } + + $attributes = new Attribute([ + 'class' => [ + 'btn', + 'btn-primary', + 'd-block', + 'd-md-inline-block', + 'text-white', + ], + ]); + $url = $registration_url->first()->getUrl(); + + if ($url->isExternal()) { + $attributes->setAttribute('target', '_blank'); + } + + $variables['links'] = [ + [ + 'label' => 'Register', + 'path' => $url->toString(), + 'icon_position' => 'before', + 'icon' => [ + 'name' => 'calendar-check', + 'path' => $variables['bcl_icon_path'], + ], + 'attributes' => $attributes, + ], + ]; } /** @@ -123,16 +170,4 @@ function _oe_whitelabel_starter_event_preprocess_inpage_nav(array &$variables): 'label' => $node->{$item['#field_name']}->getFieldDefinition()->getLabel(), ]; } - -} - -/** - * Implements hook_preprocess_HOOK(). - */ -function oe_whitelabel_starter_event_preprocess_field__node__oe_sc_event_registration_url(&$variables) { - foreach ($variables['items'] as &$item) { - if ($item['content']['#url']->isExternal()) { - $item['content']['attributes']['target'] = '_blank'; - } - } } diff --git a/templates/content/field--node--oe-sc-event-registration-url.html.twig b/templates/content/field--node--oe-sc-event-registration-url.html.twig deleted file mode 100644 index 09967c3cc..000000000 --- a/templates/content/field--node--oe-sc-event-registration-url.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{# -/** - * @file - * Event registration button display. - */ -#} -{% for item in items %} -
- {% set button %} - {{ pattern('button', { - 'label': 'Register'|t, - 'icon': 'calendar-check', - 'icon_position': 'before', - }) }} - {% endset %} - {{ pattern('link', { - 'label': button, - 'path': item['content']['#url'].toString(), - 'attributes': item['content']['attributes'] - }) }} -
-{% endfor %} diff --git a/templates/content/node--oe-sc-event--oe-w-content-banner.html.twig b/templates/content/node--oe-sc-event--oe-w-content-banner.html.twig index 494f8f6ba..35f649887 100755 --- a/templates/content/node--oe-sc-event--oe-w-content-banner.html.twig +++ b/templates/content/node--oe-sc-event--oe-w-content-banner.html.twig @@ -10,8 +10,8 @@ title: label, content: [ content.oe_summary, - content.oe_sc_event_registration_url, ], image: image, + links: links, }) }} diff --git a/tests/src/Functional/ContentEventRenderTest.php b/tests/src/Functional/ContentEventRenderTest.php index 7097c9ea9..4ed21ffba 100644 --- a/tests/src/Functional/ContentEventRenderTest.php +++ b/tests/src/Functional/ContentEventRenderTest.php @@ -84,9 +84,8 @@ public function testEventPage(): void { $link = $crawler->filter('.bcl-content-banner a[target="_blank"]'); $this->assertCount(1, $link); $this->assertEquals('https://europa.eu', $link->attr('href')); - $button = $link->filter('button'); - $this->assertStringContainsString('Register', $button->text()); - $this->assertStringContainsString('calendar-check', $button->html()); + $this->assertStringContainsString('Register', $link->text()); + $this->assertStringContainsString('calendar-check', $link->html()); // Assert registration button with internal route. $node->set('oe_sc_event_registration_url', 'entity:node/' . $node->id()); @@ -98,9 +97,8 @@ public function testEventPage(): void { $link = $crawler->filter('.bcl-content-banner a[href="/build/node/' . $node->id() . '"]'); $this->assertCount(1, $link); $this->assertObjectNotHasAttribute('target', $link); - $button = $link->filter('button'); - $this->assertStringContainsString('Register', $button->text()); - $this->assertStringContainsString('calendar-check', $button->html()); + $this->assertStringContainsString('Register', $link->text()); + $this->assertStringContainsString('calendar-check', $link->html()); $date = $crawler->filter('dl > dd');