class CustomFormatters in Custom Formatters 8.3
Same name in this branch
- 8.3 src/Plugin/Derivative/CustomFormatters.php \Drupal\custom_formatters\Plugin\Derivative\CustomFormatters
- 8.3 src/Plugin/Field/FieldFormatter/CustomFormatters.php \Drupal\custom_formatters\Plugin\Field\FieldFormatter\CustomFormatters
Retrieves field formatter plugin definitions for all custom formatters.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\custom_formatters\Plugin\Derivative\CustomFormatters
Expanded class hierarchy of CustomFormatters
File
- src/
Plugin/ Derivative/ CustomFormatters.php, line 10
Namespace
Drupal\custom_formatters\Plugin\DerivativeView source
class CustomFormatters extends DeriverBase {
protected $settings = [];
/**
* CustomFormatters constructor.
*/
public function __construct() {
$this->settings = \Drupal::config('custom_formatters.settings');
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$formatters = \Drupal::entityTypeManager()
->getStorage('formatter')
->loadMultiple();
/** @var \Drupal\custom_formatters\FormatterInterface $formatter */
foreach ($formatters as $formatter) {
if ($formatter
->get('status')) {
$this->derivatives[$formatter
->id()] = $base_plugin_definition;
$this->derivatives[$formatter
->id()]['label'] = t($this
->getLabel($formatter
->label()));
$this->derivatives[$formatter
->id()]['field_types'] = $formatter
->get('field_types');
$this->derivatives[$formatter
->id()]['formatter'] = $formatter
->id();
$this->derivatives[$formatter
->id()]['config_dependencies'] = $formatter
->getDependencies();
$this->derivatives[$formatter
->id()]['config_dependencies']['config'][] = $formatter
->getConfigDependencyName();
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
/**
* Returns Formatter label with optional prefix.
*
* @param string $label
* Formatter label.
*
* @return string
* The Formatter label with optional prefix.
*/
protected function getLabel($label) {
// Label prefix.
if ($this->settings
->get('label_prefix')) {
$label = "{$this->settings->get('label_prefix_value')}: {$label}";
}
return $label;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CustomFormatters:: |
protected | property | ||
CustomFormatters:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
CustomFormatters:: |
protected | function | Returns Formatter label with optional prefix. | |
CustomFormatters:: |
public | function | CustomFormatters constructor. | |
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |