abstract class ExtraFieldDisplayFormattedBase in Extra Field 8
Same name and namespace in other branches
- 8.2 src/Plugin/ExtraFieldDisplayFormattedBase.php \Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase
Base class for Extra field Display plugins with field wrapper output.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\extra_field\Plugin\ExtraFieldDisplayBase implements ExtraFieldDisplayInterface
- class \Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase implements ExtraFieldDisplayFormattedInterface
- class \Drupal\extra_field\Plugin\ExtraFieldDisplayBase implements ExtraFieldDisplayInterface
Expanded class hierarchy of ExtraFieldDisplayFormattedBase
6 files declare their use of ExtraFieldDisplayFormattedBase
- EmptyFormattedFieldTest.php in tests/
extra_field_test/ src/ Plugin/ ExtraField/ Display/ EmptyFormattedFieldTest.php - ExampleFormattedField.php in modules/
extra_field_example/ src/ Plugin/ ExtraField/ Display/ ExampleFormattedField.php - ExampleMultilingualField.php in modules/
extra_field_example/ src/ Plugin/ ExtraField/ Display/ ExampleMultilingualField.php - MultipleItemsFieldTest.php in tests/
extra_field_test/ src/ Plugin/ ExtraField/ Display/ MultipleItemsFieldTest.php - MultipleItemsFieldWithCacheDependencyTest.php in tests/
extra_field_test/ src/ Plugin/ ExtraField/ Display/ MultipleItemsFieldWithCacheDependencyTest.php
File
- src/
Plugin/ ExtraFieldDisplayFormattedBase.php, line 12
Namespace
Drupal\extra_field\PluginView source
abstract class ExtraFieldDisplayFormattedBase extends ExtraFieldDisplayBase implements ExtraFieldDisplayFormattedInterface {
/**
* Flag to indicate that the extra field has no content.
*
* Set this flag when the render elements returned by ::viewElements only
* contains non-visible render data such as #cache or #attached but does not
* contain actual renderable data such as #markup, #theme or #item.
*
* When this flag is set, the render elements will not be wrapped in a field
* wrapper.
*
* @var bool
*/
protected $isEmpty = FALSE;
/**
* The langcode of the field values.
*
* @var string
*/
protected $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* {@inheritdoc}
*/
public function view(ContentEntityInterface $entity) {
$elements = $this
->viewElements($entity);
if (!empty($elements) && !$this
->isEmpty()) {
// Construct a render array for the extra field elements.
// @see \Drupal\Core\Field\FormatterBase::view
$build = [
'#theme' => 'field',
'#title' => $this
->getLabel(),
'#label_display' => $this
->getLabelDisplay(),
// Prevent quickedit from editing this field by using a special view
// mode.
// @see quickedit_preprocess_field()
'#view_mode' => '_custom',
'#language' => $this
->getLangcode(),
'#field_name' => $this
->getFieldName(),
'#field_type' => $this
->getFieldType(),
'#field_translatable' => $this
->isTranslatable(),
'#entity_type' => $entity
->getEntityTypeId(),
'#bundle' => $entity
->bundle(),
'#object' => $entity,
'#formatter' => $this
->getPluginId(),
];
if ($children = Element::children($elements, TRUE)) {
$build['#is_multiple'] = TRUE;
$build['#cache'] = !empty($elements['#cache']) ? $elements['#cache'] : [];
// Without #children the field will not show up.
$build['#children'] = '';
foreach ($children as $key) {
// Only keys in "#items" property are required in
// template_preprocess_field().
$build['#items'][$key] = new \stdClass();
$build[$key] = $elements[$key];
}
}
else {
$build['#is_multiple'] = FALSE;
// Only keys in "#items" property are required in
// template_preprocess_field().
$build['#items'][] = new \stdClass();
$build[] = $elements;
}
}
else {
$build = $elements;
}
return $build;
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return '';
}
/**
* {@inheritdoc}
*/
public function getLabelDisplay() {
return 'hidden';
}
/**
* {@inheritdoc}
*/
public function getFieldType() {
return 'extra_field';
}
/**
* {@inheritdoc}
*/
public function getFieldName() {
return 'extra_field_' . $this->pluginId;
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
return $this->isEmpty;
}
/**
* {@inheritdoc}
*/
public function setLangcode($langcode) {
$this->langcode = $langcode;
}
/**
* {@inheritdoc}
*/
public function getLangcode() {
return $this->langcode;
}
/**
* {@inheritdoc}
*/
public function isTranslatable() {
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExtraFieldDisplayBase:: |
protected | property | The field's parent entity. | |
ExtraFieldDisplayBase:: |
protected | property | The entity view display. | |
ExtraFieldDisplayBase:: |
protected | property | The view mode the entity is rendered in. | |
ExtraFieldDisplayBase:: |
public | function |
Returns the field's parent entity. Overrides ExtraFieldDisplayInterface:: |
|
ExtraFieldDisplayBase:: |
public | function |
Returns the entity view display object of the field's host entity. Overrides ExtraFieldDisplayInterface:: |
|
ExtraFieldDisplayBase:: |
public | function |
Returns the entity view mode object of the field's host entity. Overrides ExtraFieldDisplayInterface:: |
|
ExtraFieldDisplayBase:: |
public | function |
Stores the field's parent entity. Overrides ExtraFieldDisplayInterface:: |
|
ExtraFieldDisplayBase:: |
public | function |
Stores the entity view display. Overrides ExtraFieldDisplayInterface:: |
|
ExtraFieldDisplayBase:: |
public | function |
Stores the entity view mode. Overrides ExtraFieldDisplayInterface:: |
|
ExtraFieldDisplayFormattedBase:: |
protected | property | Flag to indicate that the extra field has no content. | |
ExtraFieldDisplayFormattedBase:: |
protected | property | The langcode of the field values. | |
ExtraFieldDisplayFormattedBase:: |
protected | property | The language manager. | |
ExtraFieldDisplayFormattedBase:: |
public | function |
The machine name of the field. Overrides ExtraFieldDisplayFormattedInterface:: |
1 |
ExtraFieldDisplayFormattedBase:: |
public | function |
The type of field. Overrides ExtraFieldDisplayFormattedInterface:: |
1 |
ExtraFieldDisplayFormattedBase:: |
public | function |
The label of the field. Overrides ExtraFieldDisplayFormattedInterface:: |
5 |
ExtraFieldDisplayFormattedBase:: |
public | function |
How to display the field label will be displayed. Overrides ExtraFieldDisplayFormattedInterface:: |
5 |
ExtraFieldDisplayFormattedBase:: |
public | function |
Gets the langcode of the field values. Overrides ExtraFieldDisplayFormattedInterface:: |
1 |
ExtraFieldDisplayFormattedBase:: |
public | function |
Check if the extra field has data. Overrides ExtraFieldDisplayFormattedInterface:: |
|
ExtraFieldDisplayFormattedBase:: |
public | function |
The field is translatable. Overrides ExtraFieldDisplayFormattedInterface:: |
1 |
ExtraFieldDisplayFormattedBase:: |
public | function | ||
ExtraFieldDisplayFormattedBase:: |
public | function |
Builds a renderable array for the field. Overrides ExtraFieldDisplayInterface:: |
|
ExtraFieldDisplayFormattedInterface:: |
public | function | Returns the renderable array of the field item(s). | 6 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |