Commit 985edb15 authored by catch's avatar catch

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

parent 84319249
......@@ -356,7 +356,7 @@ public function cachePerUser() {
* @return $this
*/
public function cacheUntilEntityChanges(EntityInterface $entity) {
$this->addCacheTags($entity->getCacheTag());
$this->addCacheTags($entity->getCacheTags());
return $this;
}
......
......@@ -163,7 +163,7 @@ public function enable() {
*/
public function disable() {
// An entity was disabled, invalidate its own cache tag.
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
return $this->setStatus(FALSE);
}
......
......@@ -95,7 +95,7 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
/**
* {@inheritdoc}
*/
public function getCacheTag() {
public function getCacheTags() {
return ['rendered'];
}
......
......@@ -424,7 +424,7 @@ public function referencedEntities() {
/**
* {@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 @@ protected function invalidateTagsOnSave($update) {
$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 @@ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_typ
// 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);
}
......
......@@ -402,6 +402,6 @@ public function getTypedData();
* @return array
* An array of cache tags.
*/
public function getCacheTag();
public function getCacheTags();
}
......@@ -159,7 +159,7 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco
'#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 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityView
/**
* {@inheritdoc}
*/
public function getCacheTag() {
public function getCacheTags() {
return array($this->entityTypeId . '_view');
}
......@@ -362,12 +362,12 @@ public function resetCache(array $entities = NULL) {
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());
}
}
......
......@@ -157,6 +157,6 @@ public function viewFieldItem(FieldItemInterface $item, $display_options = array
* @return array
* An array of cache tags.
*/
public function getCacheTag();
public function getCacheTags();
}
......@@ -223,14 +223,14 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// 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();
}
......
......@@ -195,7 +195,7 @@ public function build() {
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());
}
}
......@@ -72,7 +72,7 @@ protected function createEntity() {
*/
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'));
......
......@@ -71,8 +71,8 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
// 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.
);
......
......@@ -166,7 +166,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// 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 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
* 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]);
}
/**
......
......@@ -336,7 +336,7 @@ protected function generateFormatTagsSetting(Editor $editor) {
// 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;
......
......@@ -70,7 +70,7 @@ public function testCreateAccess() {
->with()
->will($this->returnValue(array()));
$entity->expects($this->once())
->method('getCacheTag')
->method('getCacheTags')
->will($this->returnValue(array('node:1337')));
// Set the route requirements.
......
......@@ -82,7 +82,7 @@ public function process($text, $langcode) {
$file = $this->entityManager->loadEntityByUuid('file', $uuid);
if ($file) {
$result->addCacheTags($file->getCacheTag());
$result->addCacheTags($file->getCacheTags());
}
}
}
......
......@@ -38,7 +38,7 @@ public function viewElements(FieldItemListInterface $items) {
// that the referenced entity is deleted, the cache for referring
// entities must be cleared.
'#cache' => array(
'tags' => $entity->getCacheTag(),
'tags' => $entity->getCacheTags(),
),
);
}
......
......@@ -85,7 +85,7 @@ public function viewElements(FieldItemListInterface $items) {
else {
$elements[$delta] = array('#markup' => String::checkPlain($label));
}
$elements[$delta]['#cache']['tags'] = $entity->getCacheTag();
$elements[$delta]['#cache']['tags'] = $entity->getCacheTags();
}
return $elements;
......
......@@ -143,7 +143,7 @@ public function testIdFormatter() {
$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 @@ public function testEntityFormatter() {
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)));
}
......
......@@ -129,7 +129,7 @@ public static function preRenderText($element) {
$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.
......
......@@ -49,7 +49,7 @@
* ));
*
* // Associate cache tags to be invalidated by.
* $result->setCacheTags($node->getCacheTag());
* $result->setCacheTags($node->getCacheTags());
*
* return $result;
* }
......
......@@ -262,7 +262,7 @@ public function flush($path = NULL) {
// Clear caches so that formatters may be added for this style.
drupal_theme_rebuild();
Cache::invalidateTags($this->getCacheTag());
Cache::invalidateTags($this->getCacheTags());
return $this;
}
......
......@@ -119,7 +119,7 @@ public function viewElements(FieldItemListInterface $items) {
$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) {
......
......@@ -198,7 +198,7 @@ public function viewElements(FieldItemListInterface $items) {
}
$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 @@ public function viewElements(FieldItemListInterface $items) {
}
$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) {
......
......@@ -129,7 +129,7 @@ public function view(Request $request, SearchPageInterface $entity) {
),
),
'#cache' => array(
'tags' => $entity->getCacheTag(),
'tags' => $entity->getCacheTags(),
),
);
......
......@@ -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)) {
......
......@@ -160,7 +160,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// 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 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
/**
* {@inheritdoc}
*/
public function getCacheTag() {
return $this->shortcut_set->entity->getCacheTag();
public function getCacheTags() {
return $this->shortcut_set->entity->getCacheTags();
}
}
......@@ -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().
......
......@@ -287,21 +287,21 @@ public function testReferencedEntity() {
$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 @@ public function testReferencedEntity() {
);
$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 @@ public function testReferencedEntity() {
$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 @@ public function testReferencedEntity() {
// 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 @@ public function testReferencedEntity() {
// 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);
......
......@@ -29,8 +29,8 @@ public function testEntityUri() {
$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 @@ public function testEntityUri() {
// 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.
......
......@@ -150,7 +150,7 @@ public function listEntitiesAlphabetically($entity_type_id) {
$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
......
......@@ -55,7 +55,7 @@ public function viewElements(FieldItemListInterface $items) {
unset($item->_attributes);
}
$elements[$delta]['#cache']['tags'] = $item->entity->getCacheTag();
$elements[$delta]['#cache']['tags'] = $item->entity->getCacheTags();
}
}
......
......@@ -92,7 +92,7 @@ public function testFormatters() {
$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)));
}
}
......
......@@ -65,7 +65,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
),
),
'#cache' => [
'tags' => $entity->getCacheTag(),
'tags' => $entity->getCacheTags(),
],
);
}
......
......@@ -39,7 +39,7 @@ public function viewElements(FieldItemListInterface $items) {
'#account' => $referenced_user,
'#link_options' => array('attributes' => array('rel' => 'author')),
'#cache' => array(
'tags' => $referenced_user->getCacheTag(),
'tags' => $referenced_user->getCacheTags(),
),
);
}
......
......@@ -1123,8 +1123,8 @@ public function getDependencies() {
/**
* {@inheritdoc}
*/
public function getCacheTag() {
$this->storage->getCacheTag();
public function getCacheTags() {
$this->storage->getCacheTags();
}
/**
......
......@@ -439,7 +439,7 @@ public function testCacheTags() {
// ::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);
......
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