Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EWPP-2706: Make sure featured media title is not printed when field is empty. #1194

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,28 @@ public function getLabel() {
* {@inheritdoc}
*/
public function viewElements(ContentEntityInterface $entity) {
// Display event description using "text_featured_media" pattern.
$build = [
'#type' => 'pattern',
'#id' => 'text_featured_media',
'#fields' => [
'title' => $this->getRenderableTitle($entity),
'text' => $this->getRenderableText($entity),
],
];

// If we have no renderable text and image we don't need a title.
$text = $this->getRenderableText($entity);
$title = $this->getRenderableTitle($entity);
$this->addFeaturedMediaThumbnail($build, $entity);
upchuk marked this conversation as resolved.
Show resolved Hide resolved
$title = !empty($text[0]['#text']) || isset($build['#fields']['image']) ? $title : '';

// If we don't have a title we do not render anything because there is
// no text and no image.
if (empty($title)) {
// Make sure we continue to carry over the cache tags.
CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromRenderArray($text))
->applyTo($build);
return $build;
upchuk marked this conversation as resolved.
Show resolved Hide resolved
}

$build['#fields']['title'] = $title;
$build['#fields']['text'] = $text;
22Alexandra marked this conversation as resolved.
Show resolved Hide resolved

return $build;
}
Expand Down
17 changes: 15 additions & 2 deletions tests/src/Functional/ContentEventRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,22 @@ 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).
// Assert "Description" title is not rendered unless there is a body text.
$this->assertSession()->pageTextNotContains('Description');

// Assert "Full text", "Featured media", "Featured media legend" fields.
$node->set('body', 'Event full text');
$node->save();
$this->drupalGet($node->toUrl());

$description_content = $this->assertSession()->elementExists('css', 'article > div > div:nth-child(3)');
$text_featured = new TextFeaturedMediaAssert();
$text_featured_expected_values = [
'title' => 'Description',
'text' => 'Event full text',
];
$text_featured->assertPattern($text_featured_expected_values, $description_content->getHtml());

$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();
Expand Down