You are here

class SlickMediaFormatter in Slick Carousel 8.2

Plugin implementation of the 'slick media' formatter.

Plugin annotation


@FieldFormatter(
  id = "slick_media",
  label = @Translation("Slick Media"),
  description = @Translation("Display the referenced entities as a Slick carousel."),
  field_types = {
    "entity_reference",
  },
  quickedit = {
    "editor" = "disabled"
  }
)

Hierarchy

Expanded class hierarchy of SlickMediaFormatter

File

src/Plugin/Field/FieldFormatter/SlickMediaFormatter.php, line 23

Namespace

Drupal\slick\Plugin\Field\FieldFormatter
View source
class SlickMediaFormatter extends SlickEntityReferenceFormatterBase {
  use SlickFormatterViewTrait;

  /**
   * Returns the blazy manager.
   */
  public function blazyManager() {
    return $this->formatter;
  }

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $entities = $this
      ->getEntitiesToView($items, $langcode);

    // Early opt-out if the field is empty.
    if (empty($entities)) {
      return [];
    }
    return $this
      ->commonViewElements($items, $langcode, $entities);
  }

  /**
   * Builds the settings.
   *
   * @todo inherit and extends parent post blazy:2.x.
   */
  public function buildSettings() {
    return [
      'blazy' => TRUE,
    ] + $this
      ->traitBuildSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function getScopedFormElements() {
    $multiple = $this->fieldDefinition
      ->getFieldStorageDefinition()
      ->isMultiple();
    return [
      'grid_form' => $multiple,
      'style' => $multiple,
    ] + $this
      ->getCommonScopedFormElements() + parent::getScopedFormElements();
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
SlickEntityReferenceFormatterBase::$loggerFactory protected property The logger factory.
SlickEntityReferenceFormatterBase::buildElementThumbnail public function
SlickEntityReferenceFormatterBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
SlickEntityReferenceFormatterBase::defaultSettings public static 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::buildSettings public function Builds the settings. Aliased as: traitBuildSettings 1
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.
SlickMediaFormatter::blazyManager public function Returns the blazy manager.
SlickMediaFormatter::buildSettings public function Builds the settings.
SlickMediaFormatter::getScopedFormElements public function Overrides SlickEntityReferenceFormatterBase::getScopedFormElements
SlickMediaFormatter::isApplicable public static function Overrides SlickFormatterTrait::isApplicable
SlickMediaFormatter::viewElements public function