You are here

class MultipleItemsFieldWithCacheDependencyTest in Extra Field 8.2

Same name and namespace in other branches
  1. 8 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"),
  description = @Translation("An extra field with cache dependency."),
  bundles = {
    "node.first_node_type",
  },
  visible = true
)

Hierarchy

Expanded class hierarchy of MultipleItemsFieldWithCacheDependencyTest

File

tests/extra_field_test/src/Plugin/ExtraField/Display/MultipleItemsFieldWithCacheDependencyTest.php, line 26

Namespace

Drupal\extra_field_test\Plugin\ExtraField\Display
View 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

Namesort descending Modifiers Type Description Overrides
ExtraFieldDisplayBase::$entity protected property The field's parent entity.
ExtraFieldDisplayBase::$entityViewDisplay protected property The entity view display.
ExtraFieldDisplayBase::$viewMode protected property The view mode the entity is rendered in.
ExtraFieldDisplayBase::getEntity public function Returns the field's parent entity. Overrides ExtraFieldDisplayInterface::getEntity
ExtraFieldDisplayBase::getEntityViewDisplay public function Returns the entity view display object of the field's host entity. Overrides ExtraFieldDisplayInterface::getEntityViewDisplay
ExtraFieldDisplayBase::getViewMode public function Returns the entity view mode object of the field's host entity. Overrides ExtraFieldDisplayInterface::getViewMode
ExtraFieldDisplayBase::setEntity public function Stores the field's parent entity. Overrides ExtraFieldDisplayInterface::setEntity
ExtraFieldDisplayBase::setEntityViewDisplay public function Stores the entity view display. Overrides ExtraFieldDisplayInterface::setEntityViewDisplay
ExtraFieldDisplayBase::setViewMode public function Stores the entity view mode. Overrides ExtraFieldDisplayInterface::setViewMode
ExtraFieldDisplayFormattedBase::$isEmpty protected property Flag to indicate that the extra field has no content.
ExtraFieldDisplayFormattedBase::$langcode protected property The langcode of the field values.
ExtraFieldDisplayFormattedBase::$languageManager protected property The language manager.
ExtraFieldDisplayFormattedBase::getFieldName public function The machine name of the field. Overrides ExtraFieldDisplayFormattedInterface::getFieldName 1
ExtraFieldDisplayFormattedBase::getFieldType public function The type of field. Overrides ExtraFieldDisplayFormattedInterface::getFieldType 1
ExtraFieldDisplayFormattedBase::getLangcode public function Gets the langcode of the field values. Overrides ExtraFieldDisplayFormattedInterface::getLangcode 1
ExtraFieldDisplayFormattedBase::isEmpty public function Check if the extra field has data. Overrides ExtraFieldDisplayFormattedInterface::isEmpty
ExtraFieldDisplayFormattedBase::isTranslatable public function The field is translatable. Overrides ExtraFieldDisplayFormattedInterface::isTranslatable 1
ExtraFieldDisplayFormattedBase::setLangcode public function Set the language code.
ExtraFieldDisplayFormattedBase::view public function Builds a renderable array for the field. Overrides ExtraFieldDisplayInterface::view
MultipleItemsFieldWithCacheDependencyTest::$entityTypeManager protected property The entity type manager.
MultipleItemsFieldWithCacheDependencyTest::$renderer protected property The render service.
MultipleItemsFieldWithCacheDependencyTest::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
MultipleItemsFieldWithCacheDependencyTest::getLabel public function The label of the field. Overrides ExtraFieldDisplayFormattedBase::getLabel
MultipleItemsFieldWithCacheDependencyTest::getLabelDisplay public function How to display the field label will be displayed. Overrides ExtraFieldDisplayFormattedBase::getLabelDisplay
MultipleItemsFieldWithCacheDependencyTest::viewElements public function Returns the renderable array of the field item(s). Overrides ExtraFieldDisplayFormattedInterface::viewElements
MultipleItemsFieldWithCacheDependencyTest::__construct public function Constructs a MultipleItemsFieldWithCacheDependencyTest object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.