3 namespace Drupal\paragraphs\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\FieldItemListInterface;
7 use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
8 use Drupal\paragraphs\Entity\Paragraph;
9 use Drupal\paragraphs\ParagraphInterface;
12 * Plugin implementation of the 'paragraph_summary' formatter.
15 * id = "paragraph_summary",
16 * label = @Translation("Paragraph summary"),
18 * "entity_reference_revisions"
22 class ParagraphsSummaryFormatter extends EntityReferenceFormatterBase {
27 public function viewElements(FieldItemListInterface $items, $langcode) {
29 foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
32 '#markup' => $entity->getSummary(),
43 public static function isApplicable(FieldDefinitionInterface $field_definition) {
44 $target_type = $field_definition->getSetting('target_type');
45 $paragraph_type = \Drupal::entityTypeManager()->getDefinition($target_type);
46 if ($paragraph_type) {
47 return $paragraph_type->isSubclassOf(ParagraphInterface::class);