Commit 00339b3d authored by alexpott's avatar alexpott

Issue #2167167 by Berdir: Remove field_info_*().

parent 2d3d33b4
......@@ -224,7 +224,7 @@ services:
arguments: ['@config.factory', '@module_handler', '@state', '@info_parser', '@config.installer', '@router.builder']
entity.manager:
class: Drupal\Core\Entity\EntityManager
arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver']
arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager']
parent: container.trait
tags:
- { name: plugin_manager_cache_clear }
......
......@@ -10,15 +10,6 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
/**
* Resets the cached information about entity types.
*/
function entity_info_cache_clear() {
// Clear all languages.
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::entityManager()->clearCachedFieldDefinitions();
}
/**
* Clears the entity render cache for all entity types.
*/
......@@ -67,7 +58,7 @@ function entity_get_bundles($entity_type = NULL) {
* NULL.
*/
function entity_invoke_bundle_hook($hook, $entity_type, $bundle, $bundle_new = NULL) {
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedBundles();
// Notify the entity storage.
$method = 'onBundle' . ucfirst($hook);
......
......@@ -85,10 +85,10 @@ public function status();
* because imported entities were already given the body field when they were
* originally created, and the imported configuration includes all of their
* currently-configured fields. On the other hand,
* \Drupal\field\Entity\Field::preSave() and the methods it calls make sure
* that the storage tables are created or updated for the field configuration
* entity, which is not a configuration change, and it must be done whether
* due to an import or not. So, the first method should check
* \Drupal\field\Entity\FieldConfig::preSave() and the methods it calls make
* sure that the storage tables are created or updated for the field
* configuration entity, which is not a configuration change, and it must be
* done whether due to an import or not. So, the first method should check
* $entity->isSyncing() and skip executing if it returns TRUE, and the second
* should not perform this check.
*
......
......@@ -8,6 +8,7 @@
namespace Drupal\Core\Entity;
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Field\PrepareCacheInterface;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldInstanceConfigInterface;
......@@ -165,7 +166,7 @@ protected function loadFieldItems(array $entities) {
}
}
$cid = "field:{$this->entityTypeId}:$id";
\Drupal::cache('entity')->set($cid, $data);
\Drupal::cache('entity')->set($cid, $data, Cache::PERMANENT, array('entity_field_info' => TRUE));
}
}
}
......
......@@ -21,6 +21,7 @@
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\Core\TypedData\TypedDataManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
......@@ -95,6 +96,13 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
*/
protected $classResolver;
/**
* The typed data manager.
*
* @var \Drupal\Core\TypedData\TypedDataManager
*/
protected $typedDataManager;
/**
* Static cache of bundle information.
*
......@@ -136,7 +144,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* The class resolver.
*/
public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, TranslationInterface $translation_manager, ClassResolverInterface $class_resolver) {
public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, TranslationInterface $translation_manager, ClassResolverInterface $class_resolver, TypedDataManager $typed_data_manager) {
parent::__construct('Entity', $namespaces, $module_handler, 'Drupal\Core\Entity\Annotation\EntityType');
$this->setCacheBackend($cache, $language_manager, 'entity_type:', array('entity_types' => TRUE));
......@@ -144,6 +152,7 @@ public function __construct(\Traversable $namespaces, ModuleHandlerInterface $mo
$this->translationManager = $translation_manager;
$this->classResolver = $class_resolver;
$this->typedDataManager = $typed_data_manager;
}
/**
......@@ -151,10 +160,8 @@ public function __construct(\Traversable $namespaces, ModuleHandlerInterface $mo
*/
public function clearCachedDefinitions() {
parent::clearCachedDefinitions();
$this->bundleInfo = NULL;
$this->displayModeInfo = array();
$this->extraFields = array();
$this->clearCachedBundles();
$this->clearCachedFieldDefinitions();
}
/**
......@@ -591,7 +598,22 @@ public function clearCachedFieldDefinitions() {
$this->fieldDefinitions = array();
$this->fieldStorageDefinitions = array();
$this->fieldMap = array();
$this->displayModeInfo = array();
$this->extraFields = array();
Cache::deleteTags(array('entity_field_info' => TRUE));
// The typed data manager statically caches prototype objects with injected
// definitions, clear those as well.
$this->typedDataManager->clearCachedDefinitions();
}
/**
* {@inheritdoc}
*/
public function clearCachedBundles() {
$this->bundleInfo = array();
Cache::deleteTags(array('entity_bundles' => TRUE));
// Entity bundles are exposed as data types, clear that cache too.
$this->typedDataManager->clearCachedDefinitions();
}
/**
......@@ -606,7 +628,7 @@ public function getBundleInfo($entity_type) {
* {@inheritdoc}
*/
public function getAllBundleInfo() {
if (!isset($this->bundleInfo)) {
if (empty($this->bundleInfo)) {
$langcode = $this->languageManager->getCurrentLanguage()->id;
if ($cache = $this->cacheBackend->get("entity_bundle_info:$langcode")) {
$this->bundleInfo = $cache->data;
......@@ -629,7 +651,7 @@ public function getAllBundleInfo() {
}
}
$this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo);
$this->cacheBackend->set("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, array('entity_types' => TRUE));
$this->cacheBackend->set("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, array('entity_types' => TRUE, 'entity_bundles' => TRUE));
}
}
......@@ -786,7 +808,7 @@ protected function getAllDisplayModesByEntityType($display_type) {
$this->displayModeInfo[$display_type][$display_mode_entity_type][$display_mode_name] = (array) $display_mode;
}
$this->moduleHandler->alter($key, $this->displayModeInfo[$display_type]);
$this->cacheBackend->set("$key:$langcode", $this->displayModeInfo[$display_type], CacheBackendInterface::CACHE_PERMANENT, array('entity_types' => TRUE));
$this->cacheBackend->set("$key:$langcode", $this->displayModeInfo[$display_type], CacheBackendInterface::CACHE_PERMANENT, array('entity_types' => TRUE, 'entity_field_info' => TRUE));
}
}
......
......@@ -142,6 +142,16 @@ public function getAllBundleInfo();
*/
public function clearCachedDefinitions();
/**
* Clears static and persistent field definition caches.
*/
public function clearCachedFieldDefinitions();
/**
* Clears static and persistent bundles.
*/
public function clearCachedBundles();
/**
* Creates a new view builder instance.
*
......@@ -177,11 +187,6 @@ public function getListBuilder($entity_type);
*/
public function getFormObject($entity_type, $operation);
/**
* Clears static and persistent field definition caches.
*/
public function clearCachedFieldDefinitions();
/**
* Checks whether a certain entity type has a certain controller.
*
......
......@@ -119,7 +119,8 @@ public function isRequired();
*
* @return mixed
* The default value for the field, as accepted by
* Drupal\field\Plugin\Core\Entity\Field::setValue(). This can be either:
* Drupal\field\Plugin\Core\Entity\FieldConfig::setValue(). This can be
* either:
* - a literal, in which case it will be assigned to the first property of
* the first item.
* - a numerically indexed array of items, each item being a property/value
......
......@@ -91,7 +91,6 @@ public function testCustomBlockTypeEditing() {
'label' => 'Bar',
);
$this->drupalPostForm('admin/structure/block/custom-blocks/manage/basic', $edit, t('Save'));
field_info_cache_clear();
$this->drupalGet('block/add');
$this->assertRaw('Bar', 'New name was displayed.');
......
......@@ -12,7 +12,6 @@ function comment_uninstall() {
// Remove the comment fields.
$fields = entity_load_multiple_by_properties('field_config', array('type' => 'comment'));
foreach ($fields as $field) {
entity_invoke_bundle_hook('delete', 'comment', $field->entity_type . '__' . $field->name);
$field->delete();
}
......
......@@ -13,6 +13,7 @@
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
......@@ -256,6 +257,16 @@ function comment_field_config_delete(FieldConfigInterface $field) {
}
}
/**
* Implements hook_ENTITY_TYPE_insert() for 'field_config'.
*/
function comment_field_config_insert(FieldConfigInterface $field) {
if ($field->getType() == 'comment') {
// Delete all fields and displays attached to the comment bundle.
entity_invoke_bundle_hook('insert', 'comment', $field->getTargetEntityTypeId() . '__' . $field->getName());
}
}
/**
* Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'.
*/
......@@ -300,7 +311,7 @@ function comment_permission() {
* Number of comments.
* @param int $new_replies
* Number of new replies.
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The first new comment entity.
* @param string $field_name
* The field name on the entity to which comments are attached to.
......@@ -308,10 +319,10 @@ function comment_permission() {
* @return array|null
* An array "page=X" if the page number is greater than zero; NULL otherwise.
*/
function comment_new_page_count($num_comments, $new_replies, EntityInterface $entity, $field_name = 'comment') {
$instance = \Drupal::service('field.info')->getInstance($entity->getEntityTypeId(), $entity->bundle(), $field_name);
$mode = $instance->getSetting('default_mode');
$comments_per_page = $instance->getSetting('per_page');
function comment_new_page_count($num_comments, $new_replies, ContentEntityInterface $entity, $field_name = 'comment') {
$field_definition = $entity->getFieldDefinition($field_name);
$mode = $field_definition->getSetting('default_mode');
$comments_per_page = $field_definition->getSetting('per_page');
$pagenum = NULL;
$flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE;
if ($num_comments <= $comments_per_page) {
......@@ -960,9 +971,9 @@ function comment_node_update_index(EntityInterface $node, $langcode) {
if (!$node->hasField($field_name)) {
continue;
}
$instance = \Drupal::service('field.info')->getInstance('node', $node->getType(), $field_name);
$mode = $instance->getSetting('default_mode');
$comments_per_page = $instance->getSetting('per_page');
$field_definition = $node->getFieldDefinition($field_name);
$mode = $field_definition->getSetting('default_mode');
$comments_per_page = $field_definition->getSetting('per_page');
if ($node->get($field_name)->status && $cids = comment_get_thread($node, $field_name, $mode, $comments_per_page)) {
$comments = entity_load_multiple('comment', $cids);
comment_prepare_thread($comments);
......
......@@ -45,8 +45,6 @@ public static function create(ContainerInterface $container) {
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\field\FieldInfo $field_info
* The field info service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
......
......@@ -59,8 +59,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
* The entity manager service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\field\FieldInfo $field_info
* The field info service.
* @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token
* The CSRF token manager service.
*/
......
......@@ -8,6 +8,8 @@
namespace Drupal\comment\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldInstanceConfig;
/**
* Tests fields on comments.
......@@ -39,13 +41,13 @@ function testCommentDefaultFields() {
$this->container->get('comment.manager')->addDefaultField('node', 'test_node_type');
// Check that the 'comment_body' field is present on the comment bundle.
$instance = $this->container->get('field.info')->getInstance('comment', 'node__comment', 'comment_body');
$instance = FieldInstanceConfig::loadByName('comment', 'node__comment', 'comment_body');
$this->assertTrue(!empty($instance), 'The comment_body field is added when a comment bundle is created');
$instance->delete();
// Check that the 'comment_body' field is deleted.
$field = $this->container->get('field.info')->getField('comment', 'comment_body');
$field = FieldConfig::loadByName('comment', 'comment_body');
$this->assertTrue(empty($field), 'The comment_body field was deleted');
// Create a new content type.
......@@ -55,10 +57,10 @@ function testCommentDefaultFields() {
// Check that the 'comment_body' field exists and has an instance on the
// new comment bundle.
$field = $this->container->get('field.info')->getField('comment', 'comment_body');
$field = FieldConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field, 'The comment_body field exists');
$instances = $this->container->get('field.info')->getInstances('comment');
$this->assertTrue(isset($instances['node__comment']['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
$instance = FieldInstanceConfig::loadByName('comment', 'node__comment', 'comment_body');
$this->assertTrue(isset($instance), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
// Test adding a field that defaults to CommentItemInterface::CLOSED.
$this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED);
......@@ -75,8 +77,8 @@ function testCommentInstallAfterContentModule() {
$this->drupalLogin($this->admin_user);
// Drop default comment field added in CommentTestBase::setup().
entity_load('field_config', 'node.comment')->delete();
if ($field = $this->container->get('field.info')->getField('node', 'comment_node_forum')) {
FieldConfig::loadByName('node', 'comment')->delete();
if ($field = FieldConfig::loadByName('node', 'comment_node_forum')) {
$field->delete();
}
......
......@@ -9,6 +9,7 @@
use Drupal\comment\CommentInterface;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Entity\EntityInterface;
......@@ -92,7 +93,7 @@ function postComment(EntityInterface $entity, $comment, $subject = '', $contact
$edit = array();
$edit['comment_body[0][value]'] = $comment;
$instance = $this->container->get('field.info')->getInstance('entity_test', 'entity_test', 'comment');
$instance = FieldInstanceConfig::loadByName('entity_test', 'entity_test', 'comment');
$preview_mode = $instance->getSetting('preview');
$subject_mode = $instance->getSetting('subject');
......
......@@ -261,6 +261,7 @@ function testCommentNewPageIndicator() {
6 => 0, // Page of comment 0
);
\Drupal::entityManager()->getStorage('node')->resetCache(array($node->id()));
$node = node_load($node->id());
foreach ($expected_pages as $new_replies => $expected_page) {
$returned = comment_new_page_count($node->get('comment')->comment_count, $new_replies, $node);
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Language\Language;
use Drupal\comment\CommentInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\simpletest\WebTestBase;
/**
......@@ -105,10 +106,10 @@ public function postComment($entity, $comment, $subject = '', $contact = NULL, $
$edit['comment_body[0][value]'] = $comment;
if ($entity !== NULL) {
$instance = $this->container->get('field.info')->getInstance('node', $entity->bundle(), $field_name);
$instance = FieldInstanceConfig::loadByName('node', $entity->bundle(), $field_name);
}
else {
$instance = $this->container->get('field.info')->getInstance('node', 'article', $field_name);
$instance = FieldInstanceConfig::loadByName('node', 'article', $field_name);
}
$preview_mode = $instance->settings['preview'];
$subject_mode = $instance->settings['subject'];
......@@ -295,7 +296,7 @@ public function setCommentsPerPage($number, $field_name = 'comment') {
* Defaults to 'comment'.
*/
public function setCommentSettings($name, $value, $message, $field_name = 'comment') {
$instance = $this->container->get('field.info')->getInstance('node', 'article', $field_name);
$instance = FieldInstanceConfig::loadByName('node', 'article', $field_name);
$instance->settings[$name] = $value;
$instance->save();
// Display status message.
......
......@@ -60,8 +60,6 @@ function setupBundle() {
$this->container->get('comment.manager')->addDefaultField('node', 'page', 'comment');
// Mark this bundle as translatable.
content_translation_set_config('comment', 'node__comment_article', 'enabled', TRUE);
// Refresh entity info.
entity_info_cache_clear();
}
/**
......
......@@ -66,11 +66,9 @@ public function testInstallUninstall() {
// Delete every field on the site so all modules can be uninstalled. For
// example, if a comment field exists then module becomes required and can
// not be uninstalled.
$fields = \Drupal::service('field.info')->getFields();
foreach ($fields as $field) {
entity_invoke_bundle_hook('delete', $field->entity_type, $field->entity_type . '__' . $field->name);
$field->delete();
}
$fields = \Drupal::entityManager()->getStorage('field_config')->loadMultiple();
\Drupal::entityManager()->getStorage('field_config')->delete($fields);
// Purge the data.
field_purge_batch(1000);
......
......@@ -816,7 +816,7 @@ function content_translation_language_configuration_element_submit(array $form,
if (content_translation_enabled($context['entity_type'], $context['bundle']) != $enabled) {
content_translation_set_config($context['entity_type'], $context['bundle'], 'enabled', $enabled);
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
}
}
......@@ -884,6 +884,6 @@ function content_translation_save_settings($settings) {
}
// Ensure entity and menu router information are correctly rebuilt.
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
}
......@@ -94,7 +94,6 @@ function testSettingsUI() {
'settings[comment][node__comment_article][fields][comment_body]' => TRUE,
);
$this->assertSettings('comment', 'node__comment_article', TRUE, $edit);
field_info_cache_clear();
$field = FieldConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field->isTranslatable(), 'Comment body is translatable.');
......@@ -143,8 +142,7 @@ function testSettingsUI() {
$translatable = !$translatable;
$edit = array('field[translatable]' => $translatable);
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.body/field', $edit, t('Save field settings'));
field_info_cache_clear();
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedFieldDefinitions();
$field = FieldConfig::loadByName('node', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.');
......@@ -171,8 +169,7 @@ protected function assertSettings($entity_type, $bundle, $enabled, $edit) {
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save'));
$args = array('@entity_type' => $entity_type, '@bundle' => $bundle, '@enabled' => $enabled ? 'enabled' : 'disabled');
$message = format_string('Translation for entity @entity_type (@bundle) is @enabled.', $args);
field_info_cache_clear();
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedDefinitions();
return $this->assertEqual(content_translation_enabled($entity_type, $bundle), $enabled, $message);
}
......
......@@ -165,7 +165,7 @@ protected function enableTranslation() {
// picked up.
content_translation_set_config($this->entityTypeId, $this->bundle, 'enabled', TRUE);
drupal_static_reset();
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->rebuild();
}
......
......@@ -245,7 +245,7 @@ function testDatelistWidget() {
),
))
->save();
field_cache_clear();
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Display creation form.
$this->drupalGet('entity_test/add');
......@@ -327,8 +327,8 @@ function testDefaultValue() {
$config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field->name)->get();
$this->assertEqual($config_entity['default_value'][0]['default_date'], 'now', 'Default value has been stored successfully');
// Clean field_info cache in order to avoid stale cache values.
field_info_cache_clear();
// Clear field cache in order to avoid stale cache values.
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is today.
$new_node = entity_create('node', array('type' => 'date_content'));
......@@ -349,8 +349,8 @@ function testDefaultValue() {
$config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field->name)->get();
$this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully');
// Clean field_info cache in order to avoid stale cache values.
field_info_cache_clear();
// Clear field cache in order to avoid stale cache values.
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is today.
$new_node = entity_create('node', array('type' => 'date_content'));
......
......@@ -184,7 +184,8 @@ public function processForm($element, $form_state, $form) {
}
// Hide extra fields.
$extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, 'form');
$extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle);
$extra_fields = isset($extra_fields['form']) ? $extra_fields['form'] : array();
foreach ($extra_fields as $extra_field => $info) {
if (!$this->getComponent($extra_field)) {
$element[$extra_field]['#access'] = FALSE;
......
......@@ -239,7 +239,9 @@ public function toArray() {
*/
protected function init() {
// Fill in defaults for extra fields.
$extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, ($this->displayContext == 'view' ? 'display' : $this->displayContext));
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
$extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle);
$extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array();
foreach ($extra_fields as $name => $definition) {
if (!isset($this->content[$name]) && !isset($this->hidden[$name])) {
// Extra fields are visible by default unless they explicitly say so.
......
......@@ -94,7 +94,7 @@ public function calculateDependencies() {
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::entityManager()->clearCachedFieldDefinitions();
}
/**
......@@ -102,7 +102,7 @@ public function preSave(EntityStorageInterface $storage) {
*/
public static function preDelete(EntityStorageInterface $storage, array $entities) {
parent::preDelete($storage, $entities);
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::entityManager()->clearCachedFieldDefinitions();
}
}
......@@ -54,7 +54,7 @@ public function submit(array $form, array &$form_state) {
$entity_type = $this->entity->getEntityType();
drupal_set_message(t('Deleted the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $entity_type->getLowercaseLabel())));
$this->entity->delete();
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedFieldDefinitions();
$form_state['redirect_route'] = $this->getCancelRoute();
}
......
......@@ -125,7 +125,7 @@ public function exists($entity_id, array $element, array $form_state) {
public function save(array $form, array &$form_state) {
drupal_set_message(t('Saved the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel())));
$this->entity->save();
entity_info_cache_clear();
\Drupal::entityManager()->clearCachedFieldDefinitions();
$form_state['redirect_route']['route_name'] = 'entity.' . $this->entity->getEntityTypeId() . '_list';
}
......
......@@ -206,11 +206,6 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query
* @see \Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase::settingsForm()
*/
function entity_reference_create_instance($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) {
// If a field type we know should exist isn't found, clear the field cache.
if (!\Drupal::service('plugin.manager.field.field_type')->hasDefinition('entity_reference')) {
field_cache_clear();
}
// Look for or add the specified field to the requested entity bundle.
$field = FieldConfig::loadByName($entity_type, $field_name);
$instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name);
......
......@@ -84,8 +84,8 @@ function testEntityReferenceDefaultValue() {
$this->assertTrue(isset($config_entity['default_value'][0]['target_uuid']), 'Default value contains target_uuid property');
$this->assertEqual($config_entity['default_value'][0]['target_uuid'], $referenced_node->uuid(), 'Content uuid and config entity uuid are the same');
// Clean field_info cache in order to avoid stale cache values.
field_info_cache_clear();
// Clear field definitions cache in order to avoid stale cache values.
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that UUID has been converted to numeric ID.
$new_node = entity_create('node', array('type' => 'reference_content'));
......
<?php
/**
* @file
* This file contains functions marked as deprecated.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\field\Field;
/**
* Returns a lightweight map of fields across bundles.
*
* The function only returns non-deleted fields.
*
* @return
* An array keyed by entity type. Each value is an array which keys are
* field names and value is an array with two entries:
* - type: The field type.
* - bundles: The bundles in which the field appears.
* Example:
* @code
* array(
* 'node' => array(
* 'body' => array(
* 'bundles' => array(
* 'page', 'article'
* ),
* 'type' => 'text_with_summary',
* ),
* ),
* );
* @endcode
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\field\Field::fieldInfo()->getFieldMap().
*/
function field_info_field_map() {
return Field::fieldInfo()->getFieldMap();
}
/**
* Returns data about an individual field.
*
* @param $entity_type
* The entity type.
* @param $field_name
* The name of the field to retrieve. $field_name can only refer to a
* non-deleted field. For deleted fields, use field_info_field_by_id().
*
* @return
* The \Drupal\field\FieldConfigInterface field definition, as returned by
* entity_load_multiple_by_properties(), NULL if the field was not found.
*
* @see field_info_field_by_id()
*