diff -u b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldFormatter/EntityTestReferenceCustomCacheTagFormatter.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldFormatter/EntityTestReferenceCustomCacheTagFormatter.php --- b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldFormatter/EntityTestReferenceCustomCacheTagFormatter.php +++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldFormatter/EntityTestReferenceCustomCacheTagFormatter.php @@ -3,30 +3,26 @@ namespace Drupal\entity_test\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; -use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceIdFormatter; +use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase; /** - * Plugin implementation of the 'entity_reference_label_custom_cache_tag' formatter. + * Plugin implementation of the 'entity_reference_custom_cache_tag' formatter. * * @FieldFormatter( * id = "entity_reference_custom_cache_tag", - * label = @Translation("Adding a custom cache tag"), + * label = @Translation("Custom cache tag"), * field_types = { * "entity_reference" * } * ) */ -class EntityTestReferenceCustomCacheTagFormatter extends EntityReferenceIdFormatter { +class EntityTestReferenceCustomCacheTagFormatter extends EntityReferenceFormatterBase { /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - $elements = parent::viewElements($items, $langcode); - - $elements['#cache']['tags'][] = 'custom_cache_tag'; - - return $elements; + return ['#cache' => ['tags' => ['custom_cache_tag']]]; } }