lory-8.x-1.x-dev/src/Plugin/Field/FieldFormatter/LoryParagraphsFormatter.php

src/Plugin/Field/FieldFormatter/LoryParagraphsFormatter.php
<?php

namespace Drupal\lory\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldDefinitionInterface;

/**
 * Plugin implementation of the 'Lory Paragraphs Media' formatter.
 *
 * @FieldFormatter(
 *   id = "lory_paragraphs",
 *   label = @Translation("Lory Paragraphs Media"),
 *   description = @Translation("Display the rich paragraph as a Lory."),
 *   field_types = {
 *     "entity_reference_revisions"
 *   },
 *   quickedit = {
 *     "editor" = "disabled"
 *   }
 * )
 */
class LoryParagraphsFormatter extends LoryMediaFormatter {

  /**
   * 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', 'entity_reference'], $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';
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc