class FormatterPlugin in Blazy 7
Blazy formatter plugin initializer.
Hierarchy
- class \Drupal\blazy\Plugin\Field\FieldFormatter\FormatterPlugin uses BlazyFormatterTrait
Expanded class hierarchy of FormatterPlugin
1 file declares its use of FormatterPlugin
- blazy.runtime.inc in ./
blazy.runtime.inc - Provides basic Blazy integration for lazy loading and multi-serving images.
File
- src/
Plugin/ Field/ FieldFormatter/ FormatterPlugin.php, line 12
Namespace
Drupal\blazy\Plugin\Field\FieldFormatterView source
class FormatterPlugin {
use BlazyFormatterTrait;
/**
* The formatter info.
*
* @var array
*/
protected $formatterInfo;
/**
* The formatter type instance.
*
* @var object
*/
protected $formatterType;
/**
* Constructs a BlazyFormatter instance.
*/
public function __construct(BlazyFormatter $formatter, BlazyManagerInterface $manager) {
$this->formatter = $formatter;
$this->manager = $manager;
}
/**
* Implements hook_field_formatter_info().
*/
public function formatterInfo() {
if (!isset($this->formatterInfo)) {
$formatters = [];
foreach ([
'file',
'image',
'text',
] as $type) {
$class = 'Drupal\\blazy\\Plugin\\Field\\FieldFormatter\\Blazy' . ucwords($type) . 'Formatter';
$formatters['blazy_' . $type] = [
'label' => $type == 'text' ? t('Blazy grid') : t('Blazy'),
'class' => $class,
'field types' => $type == 'text' ? BlazyDefault::TEXTS : [
$type,
],
'settings' => $class::defaultSettings(),
];
}
$this->formatterInfo = $formatters;
}
return $this->formatterInfo;
}
/**
* Return the cached formatter based on the field type.
*/
public function getFormatter($type, $field, $instance, $namespace = 'blazy') {
if (!isset($this->formatterType[$type])) {
$this->formatterType[$type] = $this
->getActiveFormatter($type, $field, $instance, $namespace);
}
return $this->formatterType[$type];
}
/**
* Return the uncached formatter based on the field type.
*/
public function getActiveFormatter($type, $field, $instance, $namespace = 'blazy') {
$plugin_id = $namespace . '_' . $type;
foreach ($this
->formatterInfo() as $key => $info) {
if ($key == $plugin_id && !empty($info['class'])) {
$class = $info['class'];
return new $class($plugin_id, $field, $instance, $this->formatter, $this->manager);
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | ||
FormatterPlugin:: |
protected | property | The formatter info. | |
FormatterPlugin:: |
protected | property | The formatter type instance. | |
FormatterPlugin:: |
public | function | Implements hook_field_formatter_info(). | |
FormatterPlugin:: |
public | function | Return the uncached formatter based on the field type. | |
FormatterPlugin:: |
public | function | Return the cached formatter based on the field type. | |
FormatterPlugin:: |
public | function | Constructs a BlazyFormatter instance. |