Commit 817e361e authored by alexpott's avatar alexpott

Issue #2467627 by Wim Leers: Field(Storage)DefinitionInterface should...

Issue #2467627 by Wim Leers: Field(Storage)DefinitionInterface should implement CacheableDependencyInterface
parent b85ec521
<?php
/**
* @file
* Contains \Drupal\Core\Cache\UnchangingCacheableDependencyTrait.
*/
namespace Drupal\Core\Cache;
/**
* Trait to implement CacheableDependencyInterface for unchanging objects.
*
* @see \Drupal\Core\Cache\CacheableDependencyInterface
*/
trait UnchangingCacheableDependencyTrait {
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
}
......@@ -7,7 +7,6 @@
namespace Drupal\Core\Entity\Entity;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Entity\EntityDisplayPluginCollection;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
......@@ -178,13 +177,8 @@ public function buildForm(FieldableEntityInterface $entity, array &$form, FormSt
// Associate the cache tags for the field definition & field storage
// definition.
$field_definition = $this->getFieldDefinition($name);
if ($field_definition instanceof CacheableDependencyInterface) {
$this->renderer->addDependency($form[$name], $field_definition);
}
$field_storage_definition = $field_definition->getFieldStorageDefinition();
if ($field_storage_definition instanceof CacheableDependencyInterface) {
$this->renderer->addDependency($form[$name], $field_storage_definition);
}
$this->renderer->addDependency($form[$name], $field_definition);
$this->renderer->addDependency($form[$name], $field_definition->getFieldStorageDefinition());
}
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Field;
use Drupal\Core\Cache\UnchangingCacheableDependencyTrait;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\Core\Field\TypedData\FieldItemDataDefinition;
......@@ -18,6 +19,8 @@
*/
class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionInterface, FieldStorageDefinitionInterface {
use UnchangingCacheableDependencyTrait;
/**
* The field type.
*
......
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Field;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\TypedData\ListDataDefinitionInterface;
......@@ -52,7 +53,7 @@
* based on that abstract definition, even though that abstract definition can
* differ from the concrete definition of any particular node's body field.
*/
interface FieldDefinitionInterface extends ListDataDefinitionInterface {
interface FieldDefinitionInterface extends ListDataDefinitionInterface, CacheableDependencyInterface {
/**
* Returns the machine name of the field.
......
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Field;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
/**
......@@ -27,7 +28,7 @@
*
* @see hook_entity_field_storage_info()
*/
interface FieldStorageDefinitionInterface {
interface FieldStorageDefinitionInterface extends CacheableDependencyInterface {
/**
* Value indicating a field accepts an unlimited number of values.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment