class MultipleItemsFieldWithCacheDependencyTest in Extra Field 8
Same name and namespace in other branches
- 8.2 tests/extra_field_test/src/Plugin/ExtraField/Display/MultipleItemsFieldWithCacheDependencyTest.php \Drupal\extra_field_test\Plugin\ExtraField\Display\MultipleItemsFieldWithCacheDependencyTest
Extra field Display for a field with multiple items output.
Plugin annotation
@ExtraFieldDisplay(
id = "multiple_text_with_cache_dependency_test",
label = @Translation("Extra field with multiple text item and a cache dependency"),
bundles = {
"node.first_node_type",
},
visible = true
)
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_test\Plugin\ExtraField\Display\MultipleItemsFieldWithCacheDependencyTest implements ContainerFactoryPluginInterface uses StringTranslationTrait
- class \Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase implements ExtraFieldDisplayFormattedInterface
- class \Drupal\extra_field\Plugin\ExtraFieldDisplayBase implements ExtraFieldDisplayInterface
Expanded class hierarchy of MultipleItemsFieldWithCacheDependencyTest
File
- tests/
extra_field_test/ src/ Plugin/ ExtraField/ Display/ MultipleItemsFieldWithCacheDependencyTest.php, line 25
Namespace
Drupal\extra_field_test\Plugin\ExtraField\DisplayView source
class MultipleItemsFieldWithCacheDependencyTest extends ExtraFieldDisplayFormattedBase implements ContainerFactoryPluginInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The render service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a MultipleItemsFieldWithCacheDependencyTest object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The render service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('renderer'));
}
/**
* {@inheritdoc}
*/
public function viewElements(ContentEntityInterface $entity) {
$build = [];
$another_node_type_nodes = $this->entityTypeManager
->getStorage('node')
->loadByProperties([
'type' => 'another_node_type',
]);
foreach ($another_node_type_nodes as $another_node) {
$build[] = [
'#markup' => $another_node
->label(),
];
$this->renderer
->addCacheableDependency($build, $another_node);
}
return $build;
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this
->t('Related pages');
}
/**
* {@inheritdoc}
*/
public function getLabelDisplay() {
return 'inline';
}
}
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 |
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:: |
|
MultipleItemsFieldWithCacheDependencyTest:: |
protected | property | The entity type manager. | |
MultipleItemsFieldWithCacheDependencyTest:: |
protected | property | The render service. | |
MultipleItemsFieldWithCacheDependencyTest:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
MultipleItemsFieldWithCacheDependencyTest:: |
public | function |
The label of the field. Overrides ExtraFieldDisplayFormattedBase:: |
|
MultipleItemsFieldWithCacheDependencyTest:: |
public | function |
How to display the field label will be displayed. Overrides ExtraFieldDisplayFormattedBase:: |
|
MultipleItemsFieldWithCacheDependencyTest:: |
public | function |
Returns the renderable array of the field item(s). Overrides ExtraFieldDisplayFormattedInterface:: |
|
MultipleItemsFieldWithCacheDependencyTest:: |
public | function |
Constructs a MultipleItemsFieldWithCacheDependencyTest object. Overrides PluginBase:: |
|
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. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |