abstract class BlazyFormatterBase in Blazy 7
Base class for blazy-related modules (slick, etc.).
Defines one base class to extend for both image and file entity formatters.
Hierarchy
- class \Drupal\blazy\Plugin\Field\FieldFormatter\FormatterBase implements FormatterInterface
- class \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBase
Expanded class hierarchy of BlazyFormatterBase
See also
Drupal\blazy\Plugin\Field\FieldFormatter\BlazyEntityBase
Drupal\blazy\Plugin\Field\FieldFormatter\BlazyImageFormatter
Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFileFormatter
Drupal\slick\Plugin\Field\FieldFormatter\SlickImageFormatter
Drupal\slick\Plugin\Field\FieldFormatter\SlickFileFormatter
File
- src/
Plugin/ Field/ FieldFormatter/ BlazyFormatterBase.php, line 18
Namespace
Drupal\blazy\Plugin\Field\FieldFormatterView source
abstract class BlazyFormatterBase extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return BlazyDefault::imageSettings();
}
/**
* Returns the blazy admin service for blazy-related module.
*/
public abstract function admin();
/**
* {@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;
}
/**
* {@inheritdoc}
*/
public function getRequiredForms() {
return [
'grid' => $this->isMultiple,
'image_style' => TRUE,
'media_switch' => TRUE,
];
}
/**
* {@inheritdoc}
*/
public function getScopedFormElements() {
return [
'background' => TRUE,
'breakpoints' => BlazyDefault::getConstantBreakpoints(),
'box_captions' => TRUE,
'namespace' => 'blazy',
'style' => $this->isMultiple,
'thumbnail_style' => TRUE,
'captions' => [
'title' => t('Title'),
'alt' => t('Alt'),
],
] + parent::getScopedFormElements();
}
/**
* Converts $items array to object for easy D8 -> D7 backports.
*
* When extending this class, be sure to override this as needed as $items
* can be just anything. This one assumes image, or file entity.
* The actual D8 method is now taken care of at image_field_prepare_view().
* At D7, image is not an entity, of course, bear the method name.
*
* @see \Drupal\blazy\BlazyEntityBase
*/
protected function getEntitiesToView($items) {
if (empty($items)) {
return [];
}
$files = [];
foreach ($items as $item) {
$file = is_object($item) ? $item : (object) $item;
$file->targetType = 'file';
$files[] = $file;
}
return $files;
}
/**
* Build individual item if so configured such as for file entity goodness.
*/
public abstract function buildElement(array &$element, $entity, $delta = 0);
/**
* {@inheritdoc}
*/
public function settingsSummary(array $definition) {
return $this
->admin()
->getSettingsSummary($definition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyFormatterBase:: |
abstract public | function | Returns the blazy admin service for blazy-related module. | 1 |
BlazyFormatterBase:: |
abstract public | function | Build individual item if so configured such as for file entity goodness. | 2 |
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 |
Returns required form elements for the current formatter. Overrides FormatterBase:: |
2 |
BlazyFormatterBase:: |
public | function |
Defines the scope for the form elements. Overrides FormatterBase:: |
2 |
BlazyFormatterBase:: |
public | function |
Implements hook_field_formatter_settings_form(). Overrides FormatterBase:: |
1 |
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 |