You are here

class GridStackFileFormatter in GridStack 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/GridStackFileFormatter.php \Drupal\gridstack\Plugin\Field\FieldFormatter\GridStackFileFormatter

Plugin implementation of the 'GridStack' formatter to get ME within images.

@todo TBD; deprecated and removed for core Media.

Hierarchy

Expanded class hierarchy of GridStackFileFormatter

File

src/Plugin/Field/FieldFormatter/GridStackFileFormatter.php, line 13

Namespace

Drupal\gridstack\Plugin\Field\FieldFormatter
View source
class GridStackFileFormatter extends GridStackFileFormatterBase {

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    return self::injectServices($instance, $container, 'entity');
  }

  /**
   * {@inheritdoc}
   */
  public function buildElement(array &$build, $entity) {
    $settings = $build['settings'];
    $data = [];

    /** @var Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $item */

    // EntityReferenceItem provides $item->entity Drupal\file\Entity\File.
    if (empty($build['item'])) {
      if ($data = $this->blazyOembed
        ->getImageItem($entity)) {
        $build['item'] = $data['item'];
        $build['settings'] = array_merge($settings, $data['settings']);
      }
    }
    $this->blazyOembed
      ->getMediaItem($build, $entity);
  }

  /**
   * {@inheritdoc}
   */
  public function getScopedFormElements() {
    return [
      'fieldable_form' => TRUE,
      'multimedia' => TRUE,
      'view_mode' => $this->viewMode,
    ] + $this
      ->getCommonScopedFormElements() + parent::getScopedFormElements();
  }

  /**
   * {@inheritdoc}
   */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    $storage = $field_definition
      ->getFieldStorageDefinition();
    return $storage
      ->isMultiple() && $storage
      ->getSetting('target_type') === 'file';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GridStackFileFormatter::buildElement public function
GridStackFileFormatter::create public static function Overrides GridStackFileFormatterBase::create
GridStackFileFormatter::getScopedFormElements public function Overrides GridStackFileFormatterBase::getScopedFormElements
GridStackFileFormatter::isApplicable public static function Overrides GridStackFormatterTrait::isApplicable
GridStackFileFormatterBase::buildElements public function Build the gridstack carousel elements.
GridStackFileFormatterBase::defaultSettings public static function
GridStackFileFormatterBase::viewElements public function
GridStackFormatterTrait::$formatter protected property The gridstack field formatter manager.
GridStackFormatterTrait::$loggerFactory protected property The logger factory.
GridStackFormatterTrait::$manager protected property The gridstack field formatter manager.
GridStackFormatterTrait::admin public function Returns the gridstack admin service shortcut.
GridStackFormatterTrait::blazyManager public function Overrides the blazy manager.
GridStackFormatterTrait::buildSettings public function Builds the settings.
GridStackFormatterTrait::formatter public function Returns the gridstack field formatter service.
GridStackFormatterTrait::getCommonFieldDefinition public function Defines the common scope for both front and admin.
GridStackFormatterTrait::getCommonScopedFormElements public function Defines the common scope for the form elements.
GridStackFormatterTrait::injectServices protected static function Injects DI services.
GridStackFormatterTrait::manager public function Returns the gridstack service.
GridStackFormatterTrait::settingsSummary public function
GridStackFormatterViewTrait::commonViewElements public function Returns similar view elements.