You are here

class BlazyFileFormatter in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/BlazyFileFormatter.php \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFileFormatter
  2. 8 src/Plugin/Field/FieldFormatter/BlazyFileFormatter.php \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFileFormatter

Plugin implementation of the 'Blazy File' to get videos within images/files.

Hierarchy

Expanded class hierarchy of BlazyFileFormatter

File

src/Plugin/Field/FieldFormatter/BlazyFileFormatter.php, line 10

Namespace

Drupal\blazy\Plugin\Field\FieldFormatter
View source
class BlazyFileFormatter extends BlazyFormatterBlazy {
  use BlazyFormatterTrait;
  use BlazyVideoTrait;

  /**
   * The blazy entity instance.
   *
   * @var object
   */
  protected $blazyEntity;

  /**
   * Returns the blazy entity object.
   */
  public function blazyEntity() {
    if (!isset($this->blazyEntity)) {
      $this->blazyEntity = new BlazyEntity($this->formatter);
    }
    return $this->blazyEntity;
  }

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

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

    // Extract image item from file, and assign it to $element['item'] so that
    // Blazy can display an image along with video, or just mixed.
    if ($settings['type'] == 'video') {
      if ($image = $this
        ->getImageItem($entity)) {
        $element['item'] = $image['item'];
        $element['settings'] = array_merge($settings, $image['settings']);
      }
      $this
        ->getMediaItem($element, $entity);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function getCaption($entity, $field_name, $settings) {
    return $this
      ->blazyEntity()
      ->getFieldRenderable($entity, $field_name, $settings, TRUE);
  }

  /**
   * {@inheritdoc}
   */
  public function getScopedFormElements() {
    $bundles = !empty($this->fieldDefinition['bundles']) ? $this->fieldDefinition['bundles'] : [];
    return [
      'captions' => $this
        ->admin()
        ->getFieldOptions($this->fieldInstance, [], $this->targetType, $bundles),
      'multimedia' => TRUE,
      'target_type' => $this->targetType,
      'use_view_mode' => TRUE,
    ] + parent::getScopedFormElements();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlazyFileFormatter::$blazyEntity protected property The blazy entity instance.
BlazyFileFormatter::blazyEntity public function Returns the blazy entity object.
BlazyFileFormatter::buildElement public function Build individual item if so configured such as for file entity goodness. Overrides BlazyFormatterBlazy::buildElement
BlazyFileFormatter::getCaption protected function Returns the captions. Overrides BlazyFormatterBlazy::getCaption
BlazyFileFormatter::getRequiredForms public function Returns required form elements for the current formatter. Overrides BlazyFormatterBase::getRequiredForms
BlazyFileFormatter::getScopedFormElements public function Defines the scope for the form elements. Overrides BlazyFormatterBase::getScopedFormElements
BlazyFormatterBase::defaultSettings public static function Returns default settings. Overrides FormatterBase::defaultSettings 1
BlazyFormatterBase::getEntitiesToView protected function Converts $items array to object for easy D8 -> D7 backports. 1
BlazyFormatterBase::settingsForm public function Implements hook_field_formatter_settings_form(). Overrides FormatterBase::settingsForm 1
BlazyFormatterBlazy::admin public function Returns the blazy admin service for blazy-related module. Overrides BlazyFormatterBase::admin
BlazyFormatterBlazy::buildElements public function Build the Blazy elements for image and file entity/ media.
BlazyFormatterBlazy::viewElements public function Implements hook_field_formatter_view(). Overrides FormatterBase::viewElements
BlazyFormatterBlazy::__construct public function Constructs a BlazyFormatter instance. Overrides FormatterBase::__construct
BlazyFormatterTrait::$formatter protected property The blazy-related formatter service.
BlazyFormatterTrait::$manager protected property The blazy field formatter manager.
BlazyFormatterTrait::formatter public function Returns the blazy-related formatter.
BlazyFormatterTrait::manager public function Returns the blazy service.
BlazyFormatterTrait::settingsSummary public function
BlazyVideoTrait::getAutoplayUrl public function Returns video embed URL with an autoplay parameter.
BlazyVideoTrait::getHost public function Returns the host for scheme.
BlazyVideoTrait::getImageItem public function Gets the faked image item out of file entity, or ER, if applicable.
BlazyVideoTrait::getMediaItem public function Gets the Media item thumbnail, or re-associate the file entity to ME.
BlazyVideoTrait::getVideoEmbedUrl public function Returns Youtube/ Vimeo video embed suitable for non-file-entity.
BlazyVideoTrait::getVideoId public function Returns Youtube/ Vimeo video ID from URL, thanks to Kus from s.o.
BlazyVideoTrait::getVideoThumbnail public function Returns video thumbnail based on video id, needed by BlazyFilter.
FormatterBase::$admin protected property The blazy-related admin formatter service.
FormatterBase::$defaultSettingsMerged protected property Whether default settings have been merged into the current $settings.
FormatterBase::$fieldDefinition protected property The field definition.
FormatterBase::$fieldDisplay protected property The field display.
FormatterBase::$fieldInstance protected property The field instance.
FormatterBase::$htmlSettings protected property The form settings.
FormatterBase::$isMultiple protected property True if the field cardinality equals -1.
FormatterBase::$knownEntities protected property The known hard-coded entities.
FormatterBase::$langcode protected property The langcode.
FormatterBase::$pluginId protected property The blazy formatter plugin id.
FormatterBase::$settings protected property The formatter settings.
FormatterBase::$viewMode protected property The view mode.
FormatterBase::buildSettings public function Builds the settings. 1
FormatterBase::buildSettingsForm public function Implements hook_field_formatter_settings_form().
FormatterBase::buildSettingsSummary public function
FormatterBase::getHtmlSettings public function Gets html settings.
FormatterBase::getPluginId public function Gets formatter plugin id.
FormatterBase::getSetting public function
FormatterBase::getSettings public function Gets formatter settings.
FormatterBase::mergeDefaults protected function Merges default settings values into $settings.
FormatterBase::setHtmlSettings public function Sets html settings.
FormatterBase::setSetting public function
FormatterBase::setSettings public function Sets formatter settings.
FormatterBase::setupFieldVariables protected function Setup common variables across different hooks.
FormatterBase::view public function Implements hook_field_formatter_view().