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

8.0.x
Alex Pott 2015-04-12 11:07:03 +01:00
parent b85ec521f5
commit 817e361e5f
5 changed files with 47 additions and 10 deletions

View File

@ -0,0 +1,38 @@
<?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;
}
}

View File

@ -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 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
// 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());
}
}

View File

@ -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 @@ use Drupal\Core\TypedData\OptionsProviderInterface;
*/
class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionInterface, FieldStorageDefinitionInterface {
use UnchangingCacheableDependencyTrait;
/**
* The field type.
*

View File

@ -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 @@ use Drupal\Core\TypedData\ListDataDefinitionInterface;
* 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.

View File

@ -7,6 +7,7 @@
namespace Drupal\Core\Field;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
/**
@ -27,7 +28,7 @@ use Drupal\Core\Entity\FieldableEntityInterface;
*
* @see hook_entity_field_storage_info()
*/
interface FieldStorageDefinitionInterface {
interface FieldStorageDefinitionInterface extends CacheableDependencyInterface {
/**
* Value indicating a field accepts an unlimited number of values.