Skip to content

Commit

Permalink
EWPP-2706: Make sure featured media title is not printed when field i…
Browse files Browse the repository at this point in the history
…s empty.
  • Loading branch information
nagyad committed Oct 25, 2022
1 parent 34c78e4 commit 2e32f85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ public function getLabel() {
* {@inheritdoc}
*/
public function viewElements(ContentEntityInterface $entity) {
// If we have no renderable text wee don't need a title.
$text = $this->getRenderableText($entity);
$title = !empty($text[0]['#text']) ? $this->getRenderableTitle($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),
'title' => $title,
'text' => $text,
],
];

Expand Down
3 changes: 3 additions & 0 deletions tests/src/Functional/ContentEventRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ public function testEventRendering(): void {
$this->assertSession()->linkNotExistsExact('Main link for media items');
$this->assertSession()->pageTextNotContains('More media links');

// 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
// (these fields have to be filled all together).
$node->set('body', 'Event full text');
Expand Down

0 comments on commit 2e32f85

Please sign in to comment.