abstract class BlazyEntityBase in Blazy 7
Base class for entity reference formatters without field details.
Hierarchy
- class \Drupal\blazy\Plugin\Field\FieldFormatter\FormatterBase implements FormatterInterface
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBase
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyEntityBase
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBase
Expanded class hierarchy of BlazyEntityBase
See also
Drupal\slick\Plugin\Field\FieldFormatter\SlickEntityFormatterBase
Drupal\slick\Plugin\Field\FieldFormatter\SlickEntityReferenceFormatterBase
Drupal\slick\Plugin\Field\FieldFormatter\SlickFieldCollectionFormatter
Drupal\slick\Plugin\Field\FieldFormatter\SlickParagraphsFormatter
File
- src/
Plugin/ Field/ FieldFormatter/ BlazyEntityBase.php, line 15
Namespace
Drupal\blazy\Plugin\Field\FieldFormatterView source
abstract class BlazyEntityBase extends BlazyFormatterBase {
/**
* 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}
*/
protected function getEntitiesToView($items) {
if (empty($items)) {
return [];
}
// Assumes we have entityreference, or sub-moduled which prepare the view.
$entities = [];
foreach ($items as $item) {
// Skip an item that is not accessible.
if (empty($item['access'])) {
continue;
}
$entity = clone $item['entity'];
unset($entity->content);
$entities[] = $entity;
}
return $entities;
}
/**
* Returns media contents.
*/
public function buildElements(array &$build, $entities) {
$settings =& $build['settings'];
foreach ($entities as $delta => $entity) {
// Overrides Constructor::targetType via blazy_entity_load().
// Safe as a formatter is designed to work for a particular entity type
// like what entityreference does, to not be confused with bundles.
$this->targetType = $settings['target_type'] = $entity->targetType;
list($entity_id) = entity_extract_ids($this->targetType, $entity);
// Protect ourselves from recursive rendering.
static $depth = 0;
$depth++;
if ($depth > 20) {
throw new \Exception(t('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', [
'@entity_type' => $settings['entity_type_id'],
'@entity_id' => $entity_id,
]));
}
$settings['delta'] = $delta;
$settings['entity_id'] = $entity_id;
$this
->buildElement($build, $entity, $delta);
$depth = 0;
}
// Supports Blazy formatter multi-breakpoint images if available.
$settings['check_blazy'] = empty($settings['vanilla']);
}
/**
* Build individual item contents.
*/
public function buildElement(array &$build, $entity, $delta = 0) {
$build['items'][$delta] = $this
->blazyEntity()
->entityView($entity->targetType, $entity, $build['settings']) ?: [];
}
/**
* {@inheritdoc}
*/
public function settingsForm($form, &$form_state, $definition) {
parent::settingsForm($form, $form_state, $definition);
$element = [];
$definition['_views'] = isset($form['field_api_classes']);
$this
->admin()
->buildSettingsForm($element, $definition);
return $element;
}
/**
* Defines the scope for the form elements.
*/
public function getScopedFormElements() {
return [
'use_view_mode' => TRUE,
] + parent::getScopedFormElements();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyEntityBase:: |
protected | property | The blazy entity instance. | |
BlazyEntityBase:: |
public | function | Returns the blazy entity object. | |
BlazyEntityBase:: |
public | function |
Build individual item contents. Overrides BlazyFormatterBase:: |
1 |
BlazyEntityBase:: |
public | function | Returns media contents. | |
BlazyEntityBase:: |
protected | function |
Converts $items array to object for easy D8 -> D7 backports. Overrides BlazyFormatterBase:: |
|
BlazyEntityBase:: |
public | function |
Defines the scope for the form elements. Overrides BlazyFormatterBase:: |
1 |
BlazyEntityBase:: |
public | function |
Implements hook_field_formatter_settings_form(). Overrides BlazyFormatterBase:: |
1 |
BlazyFormatterBase:: |
abstract public | function | Returns the blazy admin service for blazy-related module. | 1 |
BlazyFormatterBase:: |
public static | function |
Returns default settings. Overrides FormatterBase:: |
1 |
BlazyFormatterBase:: |
public | function |
Returns required form elements for the current formatter. Overrides FormatterBase:: |
2 |
BlazyFormatterBase:: |
public | function |
Implements hook_field_formatter_settings_summary(). Overrides FormatterBase:: |
|
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(). | |
FormatterBase:: |
abstract public | function |
Implements hook_field_formatter_view(). Overrides FormatterInterface:: |
2 |
FormatterBase:: |
public | function | Constructs a base formatter object. | 2 |