BlazyFileFormatter.php in Blazy 7
File
src/Plugin/Field/FieldFormatter/BlazyFileFormatter.php
View source
<?php
namespace Drupal\blazy\Plugin\Field\FieldFormatter;
use Drupal\blazy\BlazyEntity;
class BlazyFileFormatter extends BlazyFormatterBlazy {
use BlazyFormatterTrait;
use BlazyVideoTrait;
protected $blazyEntity;
public function blazyEntity() {
if (!isset($this->blazyEntity)) {
$this->blazyEntity = new BlazyEntity($this->formatter);
}
return $this->blazyEntity;
}
public function getRequiredForms() {
return [
'fieldable' => TRUE,
] + parent::getRequiredForms();
}
public function buildElement(array &$element, $entity, $delta = 0) {
$settings = $element['settings'];
if ($settings['type'] == 'video') {
if ($image = $this
->getImageItem($entity)) {
$element['item'] = $image['item'];
$element['settings'] = array_merge($settings, $image['settings']);
}
$this
->getMediaItem($element, $entity);
}
}
protected function getCaption($entity, $field_name, $settings) {
return $this
->blazyEntity()
->getFieldRenderable($entity, $field_name, $settings, TRUE);
}
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();
}
}
Classes
Name |
Description |
BlazyFileFormatter |
Plugin implementation of the 'Blazy File' to get videos within images/files. |