class BlazyFileFormatter in Blazy 7
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/BlazyFileFormatter.php \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFileFormatter
- 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
- class \Drupal\blazy\Plugin\Field\FieldFormatter\FormatterBase implements FormatterInterface
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBase
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBlazy
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFileFormatter uses BlazyFormatterTrait, BlazyVideoTrait
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBlazy
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBase
Expanded class hierarchy of BlazyFileFormatter
File
- src/
Plugin/ Field/ FieldFormatter/ BlazyFileFormatter.php, line 10
Namespace
Drupal\blazy\Plugin\Field\FieldFormatterView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyFileFormatter:: |
protected | property | The blazy entity instance. | |
BlazyFileFormatter:: |
public | function | Returns the blazy entity object. | |
BlazyFileFormatter:: |
public | function |
Build individual item if so configured such as for file entity goodness. Overrides BlazyFormatterBlazy:: |
|
BlazyFileFormatter:: |
protected | function |
Returns the captions. Overrides BlazyFormatterBlazy:: |
|
BlazyFileFormatter:: |
public | function |
Returns required form elements for the current formatter. Overrides BlazyFormatterBase:: |
|
BlazyFileFormatter:: |
public | function |
Defines the scope for the form elements. Overrides BlazyFormatterBase:: |
|
BlazyFormatterBase:: |
public static | function |
Returns default settings. Overrides FormatterBase:: |
1 |
BlazyFormatterBase:: |
protected | function | Converts $items array to object for easy D8 -> D7 backports. | 1 |
BlazyFormatterBase:: |
public | function |
Implements hook_field_formatter_settings_form(). Overrides FormatterBase:: |
1 |
BlazyFormatterBlazy:: |
public | function |
Returns the blazy admin service for blazy-related module. Overrides BlazyFormatterBase:: |
|
BlazyFormatterBlazy:: |
public | function | Build the Blazy elements for image and file entity/ media. | |
BlazyFormatterBlazy:: |
public | function |
Implements hook_field_formatter_view(). Overrides FormatterBase:: |
|
BlazyFormatterBlazy:: |
public | function |
Constructs a BlazyFormatter instance. Overrides FormatterBase:: |
|
BlazyFormatterTrait:: |
protected | property | The blazy-related formatter service. | |
BlazyFormatterTrait:: |
protected | property | The blazy field formatter manager. | |
BlazyFormatterTrait:: |
public | function | Returns the blazy-related formatter. | |
BlazyFormatterTrait:: |
public | function | Returns the blazy service. | |
BlazyFormatterTrait:: |
public | function | ||
BlazyVideoTrait:: |
public | function | Returns video embed URL with an autoplay parameter. | |
BlazyVideoTrait:: |
public | function | Returns the host for scheme. | |
BlazyVideoTrait:: |
public | function | Gets the faked image item out of file entity, or ER, if applicable. | |
BlazyVideoTrait:: |
public | function | Gets the Media item thumbnail, or re-associate the file entity to ME. | |
BlazyVideoTrait:: |
public | function | Returns Youtube/ Vimeo video embed suitable for non-file-entity. | |
BlazyVideoTrait:: |
public | function | Returns Youtube/ Vimeo video ID from URL, thanks to Kus from s.o. | |
BlazyVideoTrait:: |
public | function | Returns video thumbnail based on video id, needed by BlazyFilter. | |
FormatterBase:: |
protected | property | The blazy-related admin formatter service. | |
FormatterBase:: |
protected | property | Whether default settings have been merged into the current $settings. | |
FormatterBase:: |
protected | property | The field definition. | |
FormatterBase:: |
protected | property | The field display. | |
FormatterBase:: |
protected | property | The field instance. | |
FormatterBase:: |
protected | property | The form settings. | |
FormatterBase:: |
protected | property | True if the field cardinality equals -1. | |
FormatterBase:: |
protected | property | The known hard-coded entities. | |
FormatterBase:: |
protected | property | The langcode. | |
FormatterBase:: |
protected | property | The blazy formatter plugin id. | |
FormatterBase:: |
protected | property | The formatter settings. | |
FormatterBase:: |
protected | property | The view mode. | |
FormatterBase:: |
public | function | Builds the settings. | 1 |
FormatterBase:: |
public | function | Implements hook_field_formatter_settings_form(). | |
FormatterBase:: |
public | function | ||
FormatterBase:: |
public | function | Gets html settings. | |
FormatterBase:: |
public | function | Gets formatter plugin id. | |
FormatterBase:: |
public | function | ||
FormatterBase:: |
public | function | Gets formatter settings. | |
FormatterBase:: |
protected | function | Merges default settings values into $settings. | |
FormatterBase:: |
public | function | Sets html settings. | |
FormatterBase:: |
public | function | ||
FormatterBase:: |
public | function | Sets formatter settings. | |
FormatterBase:: |
protected | function | Setup common variables across different hooks. | |
FormatterBase:: |
public | function | Implements hook_field_formatter_view(). |