diff --git a/src/Entity/Paragraph.php b/src/Entity/Paragraph.php index 2fbe8dd..7681a71 100644 --- a/src/Entity/Paragraph.php +++ b/src/Entity/Paragraph.php @@ -475,6 +475,18 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface { $summary[] = $block_admin_label; } } + + if ($field_definition->getType() == 'link') { + if (!empty($this->get($field_name)->first())) { + // If no title is set, fallback to the uri. + if ($title = $this->get($field_name)->first()->getProperties()['title']->getValue()) { + $summary[] = $title; + } + else { + $summary[] = $this->get($field_name)->first()->get('uri')->getValue(); + } + } + } } if ($show_behavior_summary) { diff --git a/src/Tests/Experimental/ParagraphsExperimentalEditModesTest.php b/src/Tests/Experimental/ParagraphsExperimentalEditModesTest.php index d1f4d6a..2a2dee3 100644 --- a/src/Tests/Experimental/ParagraphsExperimentalEditModesTest.php +++ b/src/Tests/Experimental/ParagraphsExperimentalEditModesTest.php @@ -21,6 +21,7 @@ class ParagraphsExperimentalEditModesTest extends ParagraphsExperimentalTestBase public static $modules = [ 'image', 'block_field', + 'link' ]; /** @@ -135,6 +136,30 @@ class ParagraphsExperimentalEditModesTest extends ParagraphsExperimentalTestBase ]; $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse'); $this->assertRaw('
Breadcrumbs'); + + // Test the summary of a Block field. + $paragraph_type = 'link_paragraph'; + $this->addParagraphsType($paragraph_type); + static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'link', 'Link', 'link', [], []); + // Create a node with a link paragraph. + $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_link_paragraph_add_more'); + $edit = [ + 'title[0][value]' => 'Test link', + 'field_paragraphs[0][subform][field_link][0][uri]' => 'http://www.google.com', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + // Check the summary when no link title is provided. + $this->clickLink(t('Edit')); + $this->assertRaw('
http://www.google.com'); + // Set a link title. + $this->drupalPostAjaxForm(NULL, NULL, 'field_paragraphs_0_edit'); + $edit = [ + 'field_paragraphs[0][subform][field_link][0][title]' => 'Link title', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + // Check the summary when the link title is set. + $this->clickLink(t('Edit')); + $this->assertRaw('
Link title'); } }