Skip to content

Commit

Permalink
Merge pull request #172 from openeuropa/OEL-1650
Browse files Browse the repository at this point in the history
OEL-1650: Move Event registration url to links.
  • Loading branch information
brummbar authored Aug 5, 2022
2 parents c186bfe + dc51281 commit e0533cd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 86 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,13 @@ 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
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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,13 @@ 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
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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
],
];
}

/**
Expand Down Expand Up @@ -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';
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
title: label,
content: [
content.oe_summary,
content.oe_sc_event_registration_url,
],
image: image,
links: links,
}) }}
</div>
10 changes: 4 additions & 6 deletions tests/src/Functional/ContentEventRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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');

Expand Down

0 comments on commit e0533cd

Please sign in to comment.