You are here

class SlickFileFormatter in Slick Carousel 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/SlickFileFormatter.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickFileFormatter
  2. 7.3 src/Plugin/Field/FieldFormatter/SlickFileFormatter.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickFileFormatter

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

This is not 'Slick Media', instead a simple mix of image and optional video.

@todo TBD; deprecate for core Media and remove post/ prior to 3.x release. @todo deprecated in blazy:8.x-2.0 and is removed from blazy:8.x-3.0. Use \Drupal\slick\Plugin\Field\FieldFormatter\SlickMediaFormatter instead.

Hierarchy

Expanded class hierarchy of SlickFileFormatter

File

src/Plugin/Field/FieldFormatter/SlickFileFormatter.php, line 18

Namespace

Drupal\slick\Plugin\Field\FieldFormatter
View source
class SlickFileFormatter extends SlickFileFormatterBase {

  // @todo remove post blazy:2.x.
  use BlazyVideoTrait;

  /**
   * {@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'])) {

      // @todo remove condition post blazy:2.x.
      if (method_exists($this->blazyOembed, 'getImageItem')) {
        $data = $this->blazyOembed
          ->getImageItem($entity);
      }
      elseif (method_exists($this, 'getImageItem')) {
        $data = $this
          ->getImageItem($entity);
      }
      if ($data) {
        $build['item'] = $data['item'];
        $build['settings'] = array_merge($settings, $data['settings']);
      }
    }
    $this->blazyOembed
      ->getMediaItem($build, $entity);
  }

  /**
   * {@inheritdoc}
   */
  public function buildSettings() {
    return [
      'blazy' => TRUE,
    ] + parent::getSettings();
  }

  /**
   * {@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
SlickFileFormatter::buildElement public function
SlickFileFormatter::buildSettings public function Builds the settings. Overrides SlickFormatterTrait::buildSettings
SlickFileFormatter::create public static function Overrides SlickFileFormatterBase::create
SlickFileFormatter::getScopedFormElements public function Overrides SlickFileFormatterBase::getScopedFormElements
SlickFileFormatter::isApplicable public static function Overrides SlickFormatterTrait::isApplicable
SlickFileFormatterBase::buildElements public function Build the slick carousel elements.
SlickFileFormatterBase::defaultSettings public static function
SlickFileFormatterBase::viewElements public function
SlickFormatterTrait::$imageFactory protected property The image factory service.
SlickFormatterTrait::$manager protected property The slick field formatter manager.
SlickFormatterTrait::admin public function Returns the slick admin service shortcut.
SlickFormatterTrait::formatter public function Returns the slick field formatter service.
SlickFormatterTrait::getCommonFieldDefinition public function Defines the common scope for both front and admin.
SlickFormatterTrait::getCommonScopedFormElements public function Defines the common scope for the form elements.
SlickFormatterTrait::imageFactory public function Returns the image factory.
SlickFormatterTrait::injectServices protected static function Injects DI services.
SlickFormatterTrait::manager public function Returns the slick service.
SlickFormatterTrait::settingsSummary public function
SlickFormatterViewTrait::commonViewElements public function Returns similar view elements.