Base class for 'Field formatter' plugin implementations.
Expanded class hierarchy of FormatterBase
abstract class FormatterBase extends PluginSettingsBase implements FormatterInterface {
/**
* The field definition.
*
* @var array
*/
protected $field;
/**
* The field instance definition.
*
* @var \Drupal\field\Plugin\Core\Entity\FieldInstance
*/
protected $instance;
/**
* The formatter settings.
*
* @var array
*/
protected $settings;
/**
* The label display setting.
*
* @var string
*/
protected $label;
/**
* The view mode.
*
* @var string
*/
protected $viewMode;
/**
* Constructs a FormatterBase object.
*
* @param string $plugin_id
* The plugin_id for the formatter.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance
* The field instance to which the formatter is associated.
* @param array $settings
* The formatter settings.
* @param string $label
* The formatter label display setting.
* @param string $view_mode
* The view mode.
*/
public function __construct($plugin_id, array $plugin_definition, $instance, array $settings, $label, $view_mode) {
parent::__construct(array(), $plugin_id, $plugin_definition);
$this->instance = $instance;
$this->field = field_info_field($instance['field_name']);
$this->settings = $settings;
$this->label = $label;
$this->viewMode = $view_mode;
}
/**
* {@inheritdoc}
*/
public function view(EntityInterface $entity, $langcode, array $items) {
$field = $this->field;
$instance = $this->instance;
$addition = array();
$elements = $this
->viewElements($entity, $langcode, $items);
if ($elements) {
$entity_type = $entity
->entityType();
$info = array(
'#theme' => 'field',
'#title' => $instance['label'],
'#access' => field_access('view', $field, $entity
->entityType(), $entity),
'#label_display' => $this->label,
'#view_mode' => $this->viewMode,
'#language' => $langcode,
'#field_name' => $field['field_name'],
'#field_type' => $field['type'],
'#field_translatable' => $field['translatable'],
'#entity_type' => $entity_type,
'#bundle' => $entity
->bundle(),
'#object' => $entity,
'#items' => $items,
'#formatter' => $this
->getPluginId(),
);
$addition[$field['field_name']] = array_merge($info, $elements);
}
return $addition;
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
return array();
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
return array();
}
/**
* {@inheritdoc}
*/
public function prepareView(array $entities, $langcode, array &$items) {
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormatterBase:: |
protected | property | The field definition. | |
FormatterBase:: |
protected | property | The field instance definition. | |
FormatterBase:: |
protected | property | The label display setting. | |
FormatterBase:: |
protected | property |
The formatter settings. Overrides PluginSettingsBase:: |
|
FormatterBase:: |
protected | property | The view mode. | |
FormatterBase:: |
public | function |
Allows formatters to load information for field values being displayed. Overrides FormatterInterface:: |
6 |
FormatterBase:: |
public | function |
Returns a form to configure settings for the formatter. Overrides FormatterInterface:: |
12 |
FormatterBase:: |
public | function |
Returns a short summary for the current formatter settings. Overrides FormatterInterface:: |
12 |
FormatterBase:: |
public | function |
Builds a renderable array for one field on one entity instance. Overrides FormatterInterface:: |
|
FormatterBase:: |
public | function |
Constructs a FormatterBase object. Overrides PluginBase:: |
|
FormatterInterface:: |
public | function | Builds a renderable array for a field value. | 26 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
public | function |
Returns the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginSettingsBase:: |
protected | property | Whether default settings have been merged into the current $settings. | |
PluginSettingsBase:: |
public | function |
Implements Drupal\field\Plugin\PluginSettingsInterface::getDefaultSettings(). Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Implements Drupal\field\Plugin\PluginSettingsInterface::getSetting(). Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Implements Drupal\field\Plugin\PluginSettingsInterface::getSettings(). Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
protected | function | Merges default settings values into $settings. | |
PluginSettingsBase:: |
public | function |
Implements Drupal\field\Plugin\PluginSettingsInterface::setSetting(). Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Implements Drupal\field\Plugin\PluginSettingsInterface::setSettings(). Overrides PluginSettingsInterface:: |