You are here

class SlickParagraphsFormatter in Slick Paragraphs 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/SlickParagraphsFormatter.php \Drupal\slick_paragraphs\Plugin\Field\FieldFormatter\SlickParagraphsFormatter

Plugin implementation of the 'Slick Paragraphs Media' formatter.

Hierarchy

  • class \Drupal\slick_paragraphs\Plugin\Field\FieldFormatter\SlickParagraphsFormatter extends \Drupal\slick_media\Plugin\Field\FieldFormatter\SlickMediaFormatter

Expanded class hierarchy of SlickParagraphsFormatter

File

src/Plugin/Field/FieldFormatter/SlickParagraphsFormatter.php, line 11

Namespace

Drupal\slick_paragraphs\Plugin\Field\FieldFormatter
View source
class SlickParagraphsFormatter extends SlickMediaFormatter {

  /**
   * Overrides the scope for the form elements.
   */
  public function getScopedFormElements() {
    $admin = $this
      ->admin();
    $target_type = $this
      ->getFieldSetting('target_type');
    $views_ui = $this
      ->getFieldSetting('handler') == 'default';
    $bundles = $views_ui ? [] : $this
      ->getFieldSetting('handler_settings')['target_bundles'];
    $media = $admin
      ->getFieldOptions($bundles, [
      'entity_reference',
    ], $target_type, 'media');
    $stages = $admin
      ->getFieldOptions($bundles, [
      'image',
      'video_embed_field',
    ], $target_type);
    return [
      'images' => $stages,
      'overlays' => $stages + $media,
    ] + parent::getScopedFormElements();
  }

  /**
   * {@inheritdoc}
   */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    $storage = $field_definition
      ->getFieldStorageDefinition();

    // Excludes host, prevents complication with multiple nested paragraphs.
    $paragraph = $storage
      ->getTargetEntityTypeId() === 'paragraph';
    return $paragraph && $storage
      ->isMultiple() && $storage
      ->getSetting('target_type') === 'paragraph';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SlickParagraphsFormatter::getScopedFormElements public function Overrides the scope for the form elements.
SlickParagraphsFormatter::isApplicable public static function