Issue #2351847 by damiankloip: Fixed Rename getCacheTag() to getCacheTags().

8.0.x
Nathaniel Catchpole 2014-10-21 09:46:57 +01:00
parent 8431924993
commit 985edb1548
36 changed files with 65 additions and 65 deletions

View File

@ -356,7 +356,7 @@ abstract class AccessResult implements AccessResultInterface, CacheableInterface
* @return $this
*/
public function cacheUntilEntityChanges(EntityInterface $entity) {
$this->addCacheTags($entity->getCacheTag());
$this->addCacheTags($entity->getCacheTags());
return $this;
}

View File

@ -163,7 +163,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
*/
public function disable() {
// An entity was disabled, invalidate its own cache tag.
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
return $this->setStatus(FALSE);
}

View File

@ -95,7 +95,7 @@ class DateFormat extends ConfigEntityBase implements DateFormatInterface {
/**
* {@inheritdoc}
*/
public function getCacheTag() {
public function getCacheTags() {
return ['rendered'];
}

View File

@ -424,7 +424,7 @@ abstract class Entity implements EntityInterface {
/**
* {@inheritdoc}
*/
public function getCacheTag() {
public function getCacheTags() {
// @todo Add bundle-specific listing cache tag? https://drupal.org/node/2145751
return [$this->entityTypeId . ':' . $this->id()];
}
@ -467,7 +467,7 @@ abstract class Entity implements EntityInterface {
$tags = $this->getEntityType()->getListCacheTags();
if ($update) {
// An existing entity was updated, also invalidate its unique cache tag.
$tags = Cache::mergeTags($tags, $this->getCacheTag());
$tags = Cache::mergeTags($tags, $this->getCacheTags());
$this->onUpdateBundleEntity();
}
Cache::invalidateTags($tags);
@ -489,7 +489,7 @@ abstract class Entity implements EntityInterface {
// other pages than the one it's on. The one it's on is handled by its own
// cache tag, but subsequent list pages would not be invalidated, hence we
// must invalidate its list cache tags as well.)
$tags = Cache::mergeTags($tags, $entity->getCacheTag());
$tags = Cache::mergeTags($tags, $entity->getCacheTags());
}
Cache::invalidateTags($tags);
}

View File

@ -402,6 +402,6 @@ interface EntityInterface extends AccessibleInterface {
* @return array
* An array of cache tags.
*/
public function getCacheTag();
public function getCacheTags();
}

View File

@ -159,7 +159,7 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf
'#langcode' => $langcode,
// Collect cache defaults for this entity.
'#cache' => array(
'tags' => Cache::mergeTags($this->getCacheTag(), $entity->getCacheTag()),
'tags' => Cache::mergeTags($this->getCacheTags(), $entity->getCacheTags()),
),
);
@ -341,7 +341,7 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf
/**
* {@inheritdoc}
*/
public function getCacheTag() {
public function getCacheTags() {
return array($this->entityTypeId . '_view');
}
@ -362,12 +362,12 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf
if (isset($entities)) {
$tags = [];
foreach ($entities as $entity) {
$tags = Cache::mergeTags($tags, $entity->getCacheTag(), $entity->getEntityType()->getListCacheTags());
$tags = Cache::mergeTags($tags, $entity->getCacheTags(), $entity->getEntityType()->getListCacheTags());
}
Cache::invalidateTags($tags);
}
else {
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
}
}

View File

@ -157,6 +157,6 @@ interface EntityViewBuilderInterface {
* @return array
* An array of cache tags.
*/
public function getCacheTag();
public function getCacheTags();
}

View File

@ -223,14 +223,14 @@ class Item extends ContentEntityBase implements ItemInterface {
// handles the regular cases. The Item entity has one special case: a newly
// created Item is *also* associated with a Feed, so we must invalidate the
// associated Feed's cache tag.
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
}
/**
* {@inheritdoc}
*/
public function getCacheTag() {
return Feed::load($this->getFeedId())->getCacheTag();
public function getCacheTags() {
return Feed::load($this->getFeedId())->getCacheTags();
}

View File

@ -195,7 +195,7 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
public function getCacheTags() {
$cache_tags = parent::getCacheTags();
$feed = $this->feedStorage->load($this->configuration['feed']);
return Cache::mergeTags($cache_tags, $feed->getCacheTag());
return Cache::mergeTags($cache_tags, $feed->getCacheTags());
}
}

View File

@ -72,7 +72,7 @@ class ItemCacheTagsTest extends EntityCacheTagsTestBase {
*/
public function testEntityCreation() {
// Create a cache entry that is tagged with a feed cache tag.
\Drupal::cache('render')->set('foo', 'bar', \Drupal\Core\Cache\CacheBackendInterface::CACHE_PERMANENT, $this->entity->getCacheTag());
\Drupal::cache('render')->set('foo', 'bar', \Drupal\Core\Cache\CacheBackendInterface::CACHE_PERMANENT, $this->entity->getCacheTags());
// Verify a cache hit.
$this->verifyRenderCache('foo', array('aggregator_feed:1'));

View File

@ -71,8 +71,8 @@ class BlockViewBuilder extends EntityViewBuilder {
// Set cache tags; these always need to be set, whether the block is
// cacheable or not, so that the page cache is correctly informed.
$build[$entity_id]['#cache']['tags'] = Cache::mergeTags(
$this->getCacheTag(), // Block view builder cache tag.
$entity->getCacheTag(), // Block entity cache tag.
$this->getCacheTags(), // Block view builder cache tag.
$entity->getCacheTags(), // Block entity cache tag.
$plugin->getCacheTags() // Block plugin cache tags.
);

View File

@ -166,7 +166,7 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
// so we must invalidate the associated block's cache tag (which includes
// the theme cache tag).
if (!$update) {
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
}
}
@ -179,8 +179,8 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
* appear there currently. Hence a block configuration entity must also return
* the associated theme's cache tag.
*/
public function getCacheTag() {
return Cache::mergeTags(parent::getCacheTag(), ['theme:' . $this->theme]);
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), ['theme:' . $this->theme]);
}
/**

View File

@ -336,7 +336,7 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
// Cache the "format_tags" configuration. This cache item is infinitely
// valid; it only changes whenever the text format is changed, hence it's
// tagged with the text format's cache tag.
$this->cache->set($cid, $format_tags, Cache::PERMANENT, $format->getCacheTag());
$this->cache->set($cid, $format_tags, Cache::PERMANENT, $format->getCacheTags());
}
return $format_tags;

View File

@ -70,7 +70,7 @@ class ContentTranslationManageAccessCheckTest extends UnitTestCase {
->with()
->will($this->returnValue(array()));
$entity->expects($this->once())
->method('getCacheTag')
->method('getCacheTags')
->will($this->returnValue(array('node:1337')));
// Set the route requirements.

View File

@ -82,7 +82,7 @@ class EditorFileReference extends FilterBase implements ContainerFactoryPluginIn
$file = $this->entityManager->loadEntityByUuid('file', $uuid);
if ($file) {
$result->addCacheTags($file->getCacheTag());
$result->addCacheTags($file->getCacheTags());
}
}
}

View File

@ -38,7 +38,7 @@ class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {
// that the referenced entity is deleted, the cache for referring
// entities must be cleared.
'#cache' => array(
'tags' => $entity->getCacheTag(),
'tags' => $entity->getCacheTags(),
),
);
}

View File

@ -85,7 +85,7 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
else {
$elements[$delta] = array('#markup' => String::checkPlain($label));
}
$elements[$delta]['#cache']['tags'] = $entity->getCacheTag();
$elements[$delta]['#cache']['tags'] = $entity->getCacheTags();
}
return $elements;

View File

@ -143,7 +143,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
$build = $items->view(array('type' => $formatter));
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->id(), format_string('The markup returned by the @formatter formatter is correct.', array('@formatter' => $formatter)));
$this->assertEqual($build[0]['#cache']['tags'], $this->referencedEntity->getCacheTag(), format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
$this->assertEqual($build[0]['#cache']['tags'], $this->referencedEntity->getCacheTags(), format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
}
@ -180,9 +180,9 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
drupal_render($build[0]);
$this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field . $expected_rendered_body_field, format_string('The markup returned by the @formatter formatter is correct.', array('@formatter' => $formatter)));
$expected_cache_tags = Cache::mergeTags(
\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTag(),
$this->referencedEntity->getCacheTag(),
FilterFormat::load('full_html')->getCacheTag()
\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTags(),
$this->referencedEntity->getCacheTags(),
FilterFormat::load('full_html')->getCacheTags()
);
$this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
}

View File

@ -129,7 +129,7 @@ class ProcessedText extends RenderElement {
$cache_tags = Cache::mergeTags($cache_tags, $element['#cache']['tags']);
}
// Prepend the text format's cache tags array.
$cache_tags = Cache::mergeTags($cache_tags, $format->getCacheTag());
$cache_tags = Cache::mergeTags($cache_tags, $format->getCacheTags());
$element['#cache']['tags'] = $cache_tags;
// Collect all attached assets.

View File

@ -49,7 +49,7 @@ use Drupal\Core\Cache\Cache;
* ));
*
* // Associate cache tags to be invalidated by.
* $result->setCacheTags($node->getCacheTag());
* $result->setCacheTags($node->getCacheTags());
*
* return $result;
* }

View File

@ -262,7 +262,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
// Clear caches so that formatters may be added for this style.
drupal_theme_rebuild();
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
return $this;
}

View File

@ -119,7 +119,7 @@ class ImageFormatter extends ImageFormatterBase {
$cache_tags = array();
if (!empty($image_style_setting)) {
$image_style = entity_load('image_style', $image_style_setting);
$cache_tags = $image_style->getCacheTag();
$cache_tags = $image_style->getCacheTags();
}
foreach ($items as $delta => $item) {

View File

@ -198,7 +198,7 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa
}
$cache_tags = [];
if ($responsive_image_mapping) {
$cache_tags = Cache::mergeTags($cache_tags, $responsive_image_mapping->getCacheTag());
$cache_tags = Cache::mergeTags($cache_tags, $responsive_image_mapping->getCacheTags());
foreach ($responsive_image_mapping->getMappings() as $mapping) {
// First mapping found is used as fallback.
if (empty($fallback_image_style)) {
@ -209,7 +209,7 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa
}
$image_styles = entity_load_multiple('image_style', $image_styles_to_load);
foreach ($image_styles as $image_style) {
$cache_tags = Cache::mergeTags($cache_tags, $image_style->getCacheTag());
$cache_tags = Cache::mergeTags($cache_tags, $image_style->getCacheTags());
}
foreach ($items as $delta => $item) {

View File

@ -129,7 +129,7 @@ class SearchController extends ControllerBase {
),
),
'#cache' => array(
'tags' => $entity->getCacheTag(),
'tags' => $entity->getCacheTags(),
),
);

View File

@ -260,7 +260,7 @@ function shortcut_renderable_links($shortcut_set = NULL) {
'title' => $shortcut->label(),
'url' => Url::fromRoute($shortcut->getRouteName(), $shortcut->getRouteParameters()),
);
$cache_tags = Cache::mergeTags($cache_tags, $shortcut->getCacheTag());
$cache_tags = Cache::mergeTags($cache_tags, $shortcut->getCacheTags());
}
if (!empty($links)) {

View File

@ -160,7 +160,7 @@ class Shortcut extends ContentEntityBase implements ShortcutInterface {
// newly created shortcut is *also* added to a shortcut set, so we must
// invalidate the associated shortcut set's cache tag.
if (!$update) {
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
}
}
@ -232,8 +232,8 @@ class Shortcut extends ContentEntityBase implements ShortcutInterface {
/**
* {@inheritdoc}
*/
public function getCacheTag() {
return $this->shortcut_set->entity->getCacheTag();
public function getCacheTags() {
return $this->shortcut_set->entity->getCacheTags();
}
}

View File

@ -483,7 +483,7 @@
* This also is the case when you define your own entity types: you'll get the
* exact same cache tag invalidation as any of the built-in entity types, with
* the ability to override any of the default behavior if needed.
* See \Drupal\Core\Entity\EntityInterface::getCacheTag(),
* See \Drupal\Core\Entity\EntityInterface::getCacheTags(),
* \Drupal\Core\Entity\EntityTypeInterface::getListCacheTags(),
* \Drupal\Core\Entity\Entity::invalidateTagsOnSave() and
* \Drupal\Core\Entity\Entity::invalidateTagsOnDelete().

View File

@ -287,21 +287,21 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
$view_cache_tag = array();
if ($this->entity->getEntityType()->hasHandlerClass('view_builder')) {
$view_cache_tag = \Drupal::entityManager()->getViewBuilder($entity_type)
->getCacheTag();
->getCacheTags();
}
// Generate the cache tags for the (non) referencing entities.
$referencing_entity_cache_tags = Cache::mergeTags(
$this->referencing_entity->getCacheTag(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTag(),
$this->referencing_entity->getCacheTags(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(),
// Includes the main entity's cache tags, since this entity references it.
$this->entity->getCacheTag(),
$this->entity->getCacheTags(),
$this->getAdditionalCacheTagsForEntity($this->entity),
$view_cache_tag
);
$non_referencing_entity_cache_tags = Cache::mergeTags(
$this->non_referencing_entity->getCacheTag(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTag()
$this->non_referencing_entity->getCacheTags(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags()
);
// Generate the cache tags for all two possible entity listing paths.
@ -314,7 +314,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
);
$nonempty_entity_listing_cache_tags = Cache::mergeTags(
$this->entity->getEntityType()->getListCacheTags(),
$this->entity->getCacheTag(),
$this->entity->getCacheTags(),
$this->getAdditionalCacheTagsForEntityListing($this->entity),
$theme_cache_tags,
$render_cache_tags
@ -444,7 +444,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
$this->verifyPageCache($non_referencing_entity_path, 'HIT');
// Special case: entity types may choose to use their bundle entity type
// cache tags, to avoid having excessively granular invalidation.
$is_special_case = $bundle_entity->getCacheTag() == $this->entity->getCacheTag() && $bundle_entity->getEntityType()->getListCacheTags() == $this->entity->getEntityType()->getListCacheTags();
$is_special_case = $bundle_entity->getCacheTags() == $this->entity->getCacheTags() && $bundle_entity->getEntityType()->getListCacheTags() == $this->entity->getEntityType()->getListCacheTags();
if ($is_special_case) {
$this->verifyPageCache($empty_entity_listing_path, 'MISS');
$this->verifyPageCache($nonempty_entity_listing_path, 'MISS');
@ -504,7 +504,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
// a cache miss for every route except the ones for the non-referencing
// entity and the empty entity listing.
$this->pass("Test invalidation of referenced entity's cache tag.", 'Debug');
Cache::invalidateTags($this->entity->getCacheTag());
Cache::invalidateTags($this->entity->getCacheTags());
$this->verifyPageCache($referencing_entity_path, 'MISS');
$this->verifyPageCache($listing_path, 'MISS');
$this->verifyPageCache($nonempty_entity_listing_path, 'MISS');
@ -561,8 +561,8 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
// Verify cache hits.
$referencing_entity_cache_tags = Cache::mergeTags(
$this->referencing_entity->getCacheTag(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTag()
$this->referencing_entity->getCacheTags(),
\Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags()
);
$tags = Cache::mergeTags($render_cache_tags, $theme_cache_tags, $referencing_entity_cache_tags);
$this->verifyPageCache($referencing_entity_path, 'HIT', $tags);

View File

@ -29,8 +29,8 @@ abstract class EntityWithUriCacheTagsTestBase extends EntityCacheTagsTestBase {
$view_mode = $this->selectViewMode($entity_type);
// Generate the standardized entity cache tags.
$cache_tag = $this->entity->getCacheTag();
$view_cache_tag = \Drupal::entityManager()->getViewBuilder($entity_type)->getCacheTag();
$cache_tag = $this->entity->getCacheTags();
$view_cache_tag = \Drupal::entityManager()->getViewBuilder($entity_type)->getCacheTags();
$render_cache_tag = 'rendered';
@ -110,7 +110,7 @@ abstract class EntityWithUriCacheTagsTestBase extends EntityCacheTagsTestBase {
// Verify that after invalidating the entity's cache tag directly, there is
// a cache miss.
$this->pass("Test invalidation of entity's cache tag.", 'Debug');
Cache::invalidateTags($this->entity->getCacheTag());
Cache::invalidateTags($this->entity->getCacheTags());
$this->verifyPageCache($entity_path, 'MISS');
// Verify a cache hit.

View File

@ -150,7 +150,7 @@ class EntityTestController extends ControllerBase {
$labels = [];
foreach ($entities as $entity) {
$labels[] = $entity->label();
$cache_tags = Cache::mergeTags($cache_tags, $entity->getCacheTag());
$cache_tags = Cache::mergeTags($cache_tags, $entity->getCacheTags());
}
// Always associate the list cache tag, otherwise the cached empty result
// wouldn't be invalidated. This would continue to show nothing matches the

View File

@ -55,7 +55,7 @@ class LinkFormatter extends TaxonomyFormatterBase {
unset($item->_attributes);
}
$elements[$delta]['#cache']['tags'] = $item->entity->getCacheTag();
$elements[$delta]['#cache']['tags'] = $item->entity->getCacheTags();
}
}

View File

@ -92,7 +92,7 @@ class TextFormatterTest extends EntityUnitTestBase {
$build = $entity->get('formatted_text')->view(array('type' => $formatter));
drupal_render($build[0]);
$this->assertEqual($build[0]['#markup'], "<p>Hello, world!</p>\n");
$this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTag(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter)));
$this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTags(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter)));
}
}

View File

@ -65,7 +65,7 @@ class TourViewBuilder extends EntityViewBuilder {
),
),
'#cache' => [
'tags' => $entity->getCacheTag(),
'tags' => $entity->getCacheTags(),
],
);
}

View File

@ -39,7 +39,7 @@ class AuthorFormatter extends FormatterBase {
'#account' => $referenced_user,
'#link_options' => array('attributes' => array('rel' => 'author')),
'#cache' => array(
'tags' => $referenced_user->getCacheTag(),
'tags' => $referenced_user->getCacheTags(),
),
);
}

View File

@ -1123,8 +1123,8 @@ class ViewUI implements ViewStorageInterface {
/**
* {@inheritdoc}
*/
public function getCacheTag() {
$this->storage->getCacheTag();
public function getCacheTags() {
$this->storage->getCacheTags();
}
/**

View File

@ -439,7 +439,7 @@ class AccessResultTest extends UnitTestCase {
// ::cacheUntilEntityChanges() convenience method.
$node = $this->getMock('\Drupal\node\NodeInterface');
$node->expects($this->any())
->method('getCacheTag')
->method('getCacheTags')
->will($this->returnValue(array('node:20011988')));
$tags = array('node:20011988');
$a = AccessResult::neutral()->addCacheTags($tags);