Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Plugin / Field / FieldFormatter / ParagraphsSummaryFormatter.php
1 <?php
2
3 namespace Drupal\paragraphs\Plugin\Field\FieldFormatter;
4
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;
10
11 /**
12  * Plugin implementation of the 'paragraph_summary' formatter.
13  *
14  * @FieldFormatter(
15  *   id = "paragraph_summary",
16  *   label = @Translation("Paragraph summary"),
17  *   field_types = {
18  *     "entity_reference_revisions"
19  *   }
20  * )
21  */
22 class ParagraphsSummaryFormatter extends EntityReferenceFormatterBase {
23
24   /**
25    * {@inheritdoc}
26    */
27   public function viewElements(FieldItemListInterface $items, $langcode) {
28     $elements = [];
29     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
30       if ($entity->id()) {
31         $elements[$delta] = [
32           '#markup' => $entity->getSummary(),
33         ];
34       }
35     }
36
37     return $elements;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
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);
48     }
49
50     return FALSE;
51   }
52 }