Skip to content

Commit

Permalink
EWPP-2714: Adapt Event Description extra field rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra committed Oct 27, 2022
1 parent 504579d commit 9e70f07
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"openeuropa/behat-transformation-context": "~0.1",
"openeuropa/code-review": "^2.0",
"openeuropa/oe_contact_forms": "^1.5",
"openeuropa/oe_content": "^3.0.0-alpha4",
"openeuropa/oe_content": "dev-EWPP-2714",
"openeuropa/oe_corporate_blocks": "^4.4",
"openeuropa/oe_corporate_countries": "~2.0",
"openeuropa/oe_media": "^1.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public function viewElements(ContentEntityInterface $entity) {

$this->addFeaturedMediaThumbnail($build, $entity);

// If we have a media but no description text, we use the 'right_simple'
// variant of the pattern to render the media on the left side.
if (empty($build['#fields']['text']) && isset($build['#fields']['image'])) {
$build['#variant'] = 'right_simple';
}

return $build;
}

Expand Down Expand Up @@ -148,13 +154,18 @@ public function getRenderableTitle(ContentEntityInterface $entity): array {
public function getRenderableText(ContentEntityInterface $entity): array {
$event = EventNodeWrapper::getInstance($entity);

// By default 'body' is the event description field.
// If the event is over and we have a report, we use 'oe_event_report_text'.
// By default 'body' is the event description field. If the event is over,
// we use 'oe_event_report_text'.
$field_name = 'body';
if ($event->isOver($this->requestDateTime) && !$entity->get('oe_event_report_text')->isEmpty()) {
if ($event->isOver($this->requestDateTime)) {
$field_name = 'oe_event_report_text';
}

// If the field we're using is empty, we don't have a description text.
if ($entity->get($field_name)->isEmpty()) {
return [];
}

/** @var \Drupal\Core\Entity\EntityViewBuilderInterface $view_builder */
$view_builder = $this->entityTypeManager->getViewBuilder('node');
$build = $view_builder->viewField($entity->get($field_name), [
Expand Down
19 changes: 14 additions & 5 deletions tests/src/Functional/ContentEventRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,25 +496,34 @@ public function testEventRendering(): void {
$this->assertSession()->linkNotExistsExact('Main link for media items');
$this->assertSession()->pageTextNotContains('More media links');

// Assert "Full text", "Featured media", "Featured media legend" fields
// (these fields have to be filled all together).
$node->set('body', 'Event full text');
// Fill in "Featured media" and "Featured media legend" fields.
$node->set('oe_event_featured_media_legend', 'Event featured media legend');
$media_image = $this->createMediaImage('event_featured_media');
$node->set('oe_event_featured_media', [$media_image])->save();
$this->drupalGet($node->toUrl());

// Assert "Description" field group.
$description_content = $this->assertSession()->elementExists('css', 'article > div > div:nth-child(3)');
$text_featured = new TextFeaturedMediaAssert();
$text_featured_expected_values = [
'title' => 'Description',
'caption' => 'Event featured media legend',
'text' => 'Event full text',
'image' => [
'alt' => 'Alternative text event_featured_media',
'src' => 'event_featured_media.png',
],
];
// If the "Full text" field is not filled in, we render using the
// "right_simple" variant with the image on the left.
$text_featured->assertVariant('right_simple', $description_content->getHtml());
$text_featured->assertPattern($text_featured_expected_values, $description_content->getHtml());

// Fill in the "Full text" field too.
$node->set('body', 'Event full text')->save();
$this->drupalGet($node->toUrl());
$text_featured_expected_values['text'] = 'Event full text';
// Assert we render using the "left_simple" variant when "Full text" is
// provided.
$text_featured->assertVariant('left_simple', $description_content->getHtml());
$text_featured->assertPattern($text_featured_expected_values, $description_content->getHtml());

// Assert "Description summary" field value.
Expand Down

0 comments on commit 9e70f07

Please sign in to comment.