diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index b355cb5..ccbe113 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -85,8 +85,8 @@ 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\FieldConfig::preSave() and the methods it calls make - * sure that the storage tables are created or updated for the field + * \Drupal\field\Entity\FieldStorageConfig::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 diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index 2e29857..7a83390 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -18,7 +18,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Language\LanguageInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -1750,7 +1750,7 @@ public static function _fieldIndexName(FieldStorageDefinitionInterface $storage_ * unique among all other fields. */ public static function _fieldColumnName(FieldStorageDefinitionInterface $storage_definition, $column) { - return in_array($column, FieldConfig::getReservedColumns()) ? $column : $storage_definition->getName() . '_' . $column; + return in_array($column, FieldStorageConfig::getReservedColumns()) ? $column : $storage_definition->getName() . '_' . $column; } } diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index d5a6334..facca39 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -13,8 +13,8 @@ use Drupal\Core\Entity\ContentEntityDatabaseStorage; use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\FieldConfigInterface; +use Drupal\field\Entity\FieldStorageConfig; +use Drupal\field\FieldStorageConfigInterface; /** * Adds tables and fields to the SQL entity query. @@ -107,20 +107,20 @@ public function addField($field, $type, $langcode) { // field. $specifier = $specifiers[$key]; if (isset($field_storage_definitions[$specifier])) { - $field = $field_storage_definitions[$specifier]; + $field_storage = $field_storage_definitions[$specifier]; } else { - $field = FALSE; + $field_storage = FALSE; } // If we managed to retrieve a configurable field, process it. - if ($field instanceof FieldConfigInterface) { + if ($field_storage instanceof FieldStorageConfigInterface) { // Find the field column. - $column = $field->getMainPropertyName(); + $column = $field_storage->getMainPropertyName(); if ($key < $count) { $next = $specifiers[$key + 1]; // Is this a field column? - $columns = $field->getColumns(); - if (isset($columns[$next]) || in_array($next, FieldConfig::getReservedColumns())) { + $columns = $field_storage->getColumns(); + if (isset($columns[$next]) || in_array($next, FieldStorageConfig::getReservedColumns())) { // Use it. $column = $next; // Do not process it again. @@ -135,14 +135,14 @@ public function addField($field, $type, $langcode) { // also use the property definitions for column. if ($key < $count) { $relationship_specifier = $specifiers[$key + 1]; - $propertyDefinitions = $field->getPropertyDefinitions(); + $propertyDefinitions = $field_storage->getPropertyDefinitions(); // Prepare the next index prefix. $next_index_prefix = "$relationship_specifier.$column"; } } - $table = $this->ensureFieldTable($index_prefix, $field, $type, $langcode, $base_table, $entity_id_field, $field_id_field); - $sql_column = ContentEntityDatabaseStorage::_fieldColumnName($field, $column); + $table = $this->ensureFieldTable($index_prefix, $field_storage, $type, $langcode, $base_table, $entity_id_field, $field_id_field); + $sql_column = ContentEntityDatabaseStorage::_fieldColumnName($field_storage, $column); } // This is an entity base field (non-configurable field). else { @@ -161,16 +161,16 @@ public function addField($field, $type, $langcode) { $table = $this->ensureEntityTable($index_prefix, $specifier, $type, $langcode, $base_table, $entity_id_field, $entity_tables); } // If there are more specifiers to come, it's a relationship. - if ($field && $key < $count) { + if ($field_storage && $key < $count) { // Computed fields have prepared their property definition already, do // it for properties as well. if (!$propertyDefinitions) { - $propertyDefinitions = $field->getPropertyDefinitions(); + $propertyDefinitions = $field_storage->getPropertyDefinitions(); $relationship_specifier = $specifiers[$key + 1]; $next_index_prefix = $relationship_specifier; } // Check for a valid relationship. - if (isset($propertyDefinitions[$relationship_specifier]) && $field->getPropertyDefinition('entity')->getDataType() == 'entity_reference' ) { + if (isset($propertyDefinitions[$relationship_specifier]) && $field_storage->getPropertyDefinition('entity')->getDataType() == 'entity_reference' ) { // If it is, use the entity type. $entity_type_id = $propertyDefinitions[$relationship_specifier]->getTargetDefinition()->getEntityTypeId(); $entity_type = $this->entityManager->getDefinition($entity_type_id); diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php index be7f0fe..cf6947b 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -27,20 +27,20 @@ * It is up to the class implementing this interface to manage where the * information comes from. For example, field.module provides an implementation * based on two levels of configuration. It allows the site administrator to add - * custom fields to any entity type and bundle via the "field_config" and - * "field_instance_config" configuration entities. The former for storing + * custom fields to any entity type and bundle via the "field_storage_config" + * and "field_instance_config" configuration entities. The former for storing * configuration that is independent of which entity type and bundle the field * is added to, and the latter for storing configuration that is specific to the * entity type and bundle. The class that implements "field_instance_config" * configuration entities also implements this interface, returning information - * from either itself, or from the corresponding "field_config" configuration, - * as appropriate. + * from either itself, or from the corresponding "field_storage_config" + * configuration, as appropriate. * * However, entity base fields, such as $node->title, are not managed by - * field.module and its "field_config"/"field_instance_config" configuration - * entities. Therefore, their definitions are provided by different objects - * based on the class \Drupal\Core\Field\FieldDefinition, which implements this - * interface as well. + * field.module and its "field_storage_config"/"field_instance_config" + * configuration entities. Therefore, their definitions are provided by + * different objects based on the class \Drupal\Core\Field\FieldDefinition, + * which implements this interface as well. * * Field definitions may fully define a concrete data object (e.g., * $node_1->body), or may provide a best-guess definition for a data object that diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index ee27996..6489541 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -234,8 +234,8 @@ public static function defaultInstanceSettings(); /** * Returns a form for the field-level settings. * - * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow administrators to - * configure field-level settings. + * Invoked from \Drupal\field_ui\Form\FieldStorageEditForm to allow + * administrators to configure field-level settings. * * Field storage might reject field definition changes that affect the field * storage schema if the field already has data. When the $has_data parameter diff --git a/core/modules/block_content/block_content.module b/core/modules/block_content/block_content.module index 706fa69..dadcf4b 100644 --- a/core/modules/block_content/block_content.module +++ b/core/modules/block_content/block_content.module @@ -6,8 +6,8 @@ */ use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldInstanceConfig; +use Drupal\field\Entity\FieldStorageConfig; /** * Implements hook_help(). @@ -77,19 +77,19 @@ function block_content_entity_type_alter(array &$entity_types) { */ function block_content_add_body_field($block_type_id, $label = 'Body') { // Add or remove the body field, as needed. - $field = FieldConfig::loadByName('block_content', 'body'); + $field_storage = FieldStorageConfig::loadByName('block_content', 'body'); $instance = FieldInstanceConfig::loadByName('block_content', $block_type_id, 'body'); - if (empty($field)) { - $field = entity_create('field_config', array( + if (empty($field_storage)) { + $field_storage = entity_create('field_storage_config', array( 'name' => 'body', 'entity_type' => 'block_content', 'type' => 'text_with_summary', )); - $field->save(); + $field_storage->save(); } if (empty($instance)) { $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => $block_type_id, 'label' => $label, 'settings' => array('display_summary' => FALSE), diff --git a/core/modules/block_content/src/Tests/BlockContentFieldTest.php b/core/modules/block_content/src/Tests/BlockContentFieldTest.php index 65c08c5..35e1341 100644 --- a/core/modules/block_content/src/Tests/BlockContentFieldTest.php +++ b/core/modules/block_content/src/Tests/BlockContentFieldTest.php @@ -25,9 +25,9 @@ class BlockContentFieldTest extends BlockContentTestBase { /** * The created field. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $fieldStorage; /** * The created instance. @@ -64,15 +64,15 @@ public function testBlockFields() { $this->blockType = $this->createBlockContentType('link'); // Create a field with settings to validate. - $this->field = entity_create('field_config', array( + $this->fieldStorage = entity_create('field_storage_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'block_content', 'type' => 'link', 'cardinality' => 2, )); - $this->field->save(); + $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => 'link', 'settings' => array( 'title' => DRUPAL_OPTIONAL, @@ -80,12 +80,12 @@ public function testBlockFields() { )); $this->instance->save(); entity_get_form_display('block_content', 'link', 'default') - ->setComponent($this->field->getName(), array( + ->setComponent($this->fieldStorage->getName(), array( 'type' => 'link_default', )) ->save(); entity_get_display('block_content', 'link', 'default') - ->setComponent($this->field->getName(), array( + ->setComponent($this->fieldStorage->getName(), array( 'type' => 'link', 'label' => 'hidden', )) @@ -95,8 +95,8 @@ public function testBlockFields() { $this->drupalGet('block/add/link'); $edit = array( 'info[0][value]' => $this->randomName(8), - $this->field->getName() . '[0][url]' => 'http://example.com', - $this->field->getName() . '[0][title]' => 'Example.com' + $this->fieldStorage->getName() . '[0][url]' => 'http://example.com', + $this->fieldStorage->getName() . '[0][title]' => 'Example.com' ); $this->drupalPostForm(NULL, $edit, t('Save')); $block = entity_load('block_content', 1); diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 391a255..95fd135 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -5,14 +5,14 @@ * Install, update and uninstall functions for the Comment module. */ -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; /** * Implements hook_uninstall(). */ function comment_uninstall() { // Remove the comment fields. - $fields = entity_load_multiple_by_properties('field_config', array('type' => 'comment')); + $fields = entity_load_multiple_by_properties('field_storage_config', array('type' => 'comment')); foreach ($fields as $field) { $field->delete(); } @@ -55,7 +55,7 @@ function comment_schema() { 'type' => 'varchar', 'not null' => TRUE, 'default' => '', - 'length' => FieldConfig::NAME_MAX_LENGTH, + 'length' => FieldStorageConfig::NAME_MAX_LENGTH, 'description' => 'The field_name of the field that was used to add this comment.', ), 'cid' => array( diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 0d3d736..500e32c 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -23,9 +23,9 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; use Drupal\Core\Url; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\FieldInstanceConfigInterface; -use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; use Drupal\file\FileInterface; use Drupal\user\EntityOwnerInterface; use Drupal\node\NodeInterface; @@ -188,12 +188,12 @@ function comment_field_instance_config_update(FieldInstanceConfigInterface $inst } /** - * Implements hook_ENTITY_TYPE_insert() for 'field_config'. + * Implements hook_ENTITY_TYPE_insert() for 'field_storage_config'. */ -function comment_field_config_insert(FieldConfigInterface $field) { - if ($field->getType() == 'comment') { +function comment_field_storage_config_insert(FieldStorageConfigInterface $field_storage) { + if ($field_storage->getType() == 'comment') { // Check that the target entity type uses an integer ID. - $entity_type_id = $field->getTargetEntityTypeId(); + $entity_type_id = $field_storage->getTargetEntityTypeId(); if (!_comment_entity_uses_integer_id($entity_type_id)) { throw new \UnexpectedValueException('You cannot attach a comment field to an entity with a non-integer ID field'); } @@ -737,7 +737,7 @@ function comment_form_field_ui_display_overview_form_alter(&$form, $form_state) /** * Implements hook_form_FORM_ID_alter(). */ -function comment_form_field_ui_field_edit_form_alter(&$form, $form_state) { +function comment_form_field_ui_field_storage_edit_form_alter(&$form, $form_state) { if ($form['#field']->getType() == 'comment') { // We only support posting one comment at the time so it doesn't make sense // to let the site builder choose anything else. diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index 1bed270..1c7843d 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -19,7 +19,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldInstanceConfig; /** @@ -158,9 +158,9 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', ))->save(); } // Make sure the field doesn't already exist. - if (!FieldConfig::loadByName($entity_type, $field_name)) { + if (!FieldStorageConfig::loadByName($entity_type, $field_name)) { // Add a default comment field for existing node comments. - $field = $this->entityManager->getStorage('field_config')->create(array( + $field = $this->entityManager->getStorage('field_storage_config')->create(array( 'entity_type' => $entity_type, 'name' => $field_name, 'type' => 'comment', @@ -235,14 +235,14 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', */ public function addBodyField($comment_type_id) { // Create the field if needed. - $field = FieldConfig::loadByName('comment', 'comment_body'); - if (!$field) { - $field = $this->entityManager->getStorage('field_config')->create(array( + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + if (!$field_storage) { + $field_storage = $this->entityManager->getStorage('field_storage_config')->create(array( 'name' => 'comment_body', 'type' => 'text_long', 'entity_type' => 'comment', )); - $field->save(); + $field_storage->save(); } if (!FieldInstanceConfig::loadByName('comment', $comment_type_id, 'comment_body')) { // Attaches the body field by default. diff --git a/core/modules/comment/src/CommentPostRenderCache.php b/core/modules/comment/src/CommentPostRenderCache.php index 15831e0..24db82d 100644 --- a/core/modules/comment/src/CommentPostRenderCache.php +++ b/core/modules/comment/src/CommentPostRenderCache.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityFormBuilderInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; /** * Defines a service for comment post render cache callbacks. @@ -60,12 +60,12 @@ public function __construct(EntityManagerInterface $entity_manager, EntityFormBu public function renderForm(array $element, array $context) { $field_name = $context['field_name']; $entity = $this->entityManager->getStorage($context['entity_type'])->load($context['entity_id']); - $field = Fieldconfig::loadByName($entity->getEntityTypeId(), $field_name); + $field_storage = FieldStorageConfig::loadByName($entity->getEntityTypeId(), $field_name); $values = array( 'entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id(), 'field_name' => $field_name, - 'comment_type' => $field->getSetting('bundle'), + 'comment_type' => $field_storage->getSetting('bundle'), 'pid' => NULL, ); $comment = $this->entityManager->getStorage('comment')->create($values); diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 777d92b..ec442fe 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\FieldDefinition; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\user\UserInterface; /** @@ -493,8 +493,8 @@ public function getChangedTime() { */ public static function preCreate(EntityStorageInterface $storage, array &$values) { if (empty($values['comment_type']) && !empty($values['field_name']) && !empty($values['entity_type'])) { - $field = FieldConfig::loadByName($values['entity_type'], $values['field_name']); - $values['comment_type'] = $field->getSetting('comment_type'); + $field_storage = FieldStorageConfig::loadByName($values['entity_type'], $values['field_name']); + $values['comment_type'] = $field_storage->getSetting('comment_type'); } } diff --git a/core/modules/comment/src/Form/CommentTypeDeleteForm.php b/core/modules/comment/src/Form/CommentTypeDeleteForm.php index d653e56..b7178fc 100644 --- a/core/modules/comment/src/Form/CommentTypeDeleteForm.php +++ b/core/modules/comment/src/Form/CommentTypeDeleteForm.php @@ -12,7 +12,7 @@ use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Url; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -116,11 +116,11 @@ public function buildForm(array $form, array &$form_state) { $entity_type = $this->entity->getTargetEntityTypeId(); $caption = ''; foreach (array_keys($this->commentManager->getFields($entity_type)) as $field_name) { - /** @var \Drupal\field\FieldConfigInterface $field */ - if (($field = FieldConfig::loadByName($entity_type, $field_name)) && $field->getSetting('comment_type') == $this->entity->id() && !$field->deleted) { + /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */ + if (($field_storage = FieldStorageConfig::loadByName($entity_type, $field_name)) && $field_storage->getSetting('comment_type') == $this->entity->id() && !$field_storage->deleted) { $caption .= '
' . $this->t('%label is used by the %field field on your site. You can not remove this comment type until you have removed the field.', array( '%label' => $this->entity->label(), - '%field' => $field->label(), + '%field' => $field_storage->label(), )) . '
'; } } diff --git a/core/modules/comment/src/Tests/CommentFieldsTest.php b/core/modules/comment/src/Tests/CommentFieldsTest.php index 70b3ecd..76a87c4 100644 --- a/core/modules/comment/src/Tests/CommentFieldsTest.php +++ b/core/modules/comment/src/Tests/CommentFieldsTest.php @@ -8,7 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldInstanceConfig; /** @@ -47,8 +47,8 @@ function testCommentDefaultFields() { $instance->delete(); // Check that the 'comment_body' field is deleted. - $field = FieldConfig::loadByName('comment', 'comment_body'); - $this->assertTrue(empty($field), 'The comment_body field was deleted'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $this->assertTrue(empty($field_storage), 'The comment_body field was deleted'); // Create a new content type. $type_name = 'test_node_type_2'; @@ -57,15 +57,15 @@ function testCommentDefaultFields() { // Check that the 'comment_body' field exists and has an instance on the // new comment bundle. - $field = FieldConfig::loadByName('comment', 'comment_body'); - $this->assertTrue($field, 'The comment_body field exists'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $this->assertTrue($field_storage, 'The comment_body field exists'); $instance = FieldInstanceConfig::loadByName('comment', '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, 'who_likes_ponies'); - $field = entity_load('field_instance_config', 'node.test_node_type.who_likes_ponies'); - $this->assertEqual($field->default_value[0]['status'], CommentItemInterface::CLOSED); + $field_storage = entity_load('field_instance_config', 'node.test_node_type.who_likes_ponies'); + $this->assertEqual($field_storage->default_value[0]['status'], CommentItemInterface::CLOSED); } /** @@ -77,9 +77,9 @@ function testCommentInstallAfterContentModule() { $this->drupalLogin($this->admin_user); // Drop default comment field added in CommentTestBase::setup(). - FieldConfig::loadByName('node', 'comment')->delete(); - if ($field = FieldConfig::loadByName('node', 'comment_forum')) { - $field->delete(); + FieldStorageConfig::loadByName('node', 'comment')->delete(); + if ($field_storage = FieldStorageConfig::loadByName('node', 'comment_forum')) { + $field_storage->delete(); } // Purge field data now to allow comment module to be uninstalled once the diff --git a/core/modules/comment/src/Tests/CommentLanguageTest.php b/core/modules/comment/src/Tests/CommentLanguageTest.php index d139a38..103782a 100644 --- a/core/modules/comment/src/Tests/CommentLanguageTest.php +++ b/core/modules/comment/src/Tests/CommentLanguageTest.php @@ -9,7 +9,7 @@ use Drupal\comment\Entity\Comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; /** @@ -76,10 +76,10 @@ function setUp() { $this->container->get('comment.manager')->addDefaultField('node', 'article'); // Make comment body translatable. - $field = FieldConfig::loadByName('comment', 'comment_body'); - $field->translatable = TRUE; - $field->save(); - $this->assertTrue($field->isTranslatable(), 'Comment body is translatable.'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $field_storage->translatable = TRUE; + $field_storage->save(); + $this->assertTrue($field_storage->isTranslatable(), 'Comment body is translatable.'); } /** diff --git a/core/modules/comment/src/Tests/CommentNodeChangesTest.php b/core/modules/comment/src/Tests/CommentNodeChangesTest.php index 33c4813..9762065 100644 --- a/core/modules/comment/src/Tests/CommentNodeChangesTest.php +++ b/core/modules/comment/src/Tests/CommentNodeChangesTest.php @@ -33,11 +33,11 @@ function testNodeDeletion() { $this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.'); // Make sure the comment field and all its instances are deleted when node // type is deleted. - $this->assertNotNull(entity_load('field_config', 'node.comment'), 'Comment field exists'); + $this->assertNotNull(entity_load('field_storage_config', 'node.comment'), 'Comment field exists'); $this->assertNotNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance exists'); // Delete the node type. entity_delete_multiple('node_type', array($this->node->bundle())); - $this->assertNull(entity_load('field_config', 'node.comment'), 'Comment field deleted'); + $this->assertNull(entity_load('field_storage_config', 'node.comment'), 'Comment field deleted'); $this->assertNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance deleted'); } } diff --git a/core/modules/comment/src/Tests/CommentNonNodeTest.php b/core/modules/comment/src/Tests/CommentNonNodeTest.php index f4f6fec..d59efee 100644 --- a/core/modules/comment/src/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/src/Tests/CommentNonNodeTest.php @@ -402,9 +402,9 @@ function testCommentFunctionality() { $this->assertRaw(t('Saved %name configuration', array('%name' => 'Barfoo'))); // Check the field contains the correct comment type. - $field = entity_load('field_config', 'entity_test.field_barfoo'); - $this->assertTrue($field); - $this->assertEqual($field->getSetting('comment_type'), 'foobar'); + $field_storage = entity_load('field_storage_config', 'entity_test.field_barfoo'); + $this->assertTrue($field_storage); + $this->assertEqual($field_storage->getSetting('comment_type'), 'foobar'); // Test the new entity commenting inherits default. $random_label = $this->randomName(); diff --git a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php index e1be25d..71929ce 100644 --- a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php +++ b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php @@ -56,7 +56,7 @@ public function testCommentFieldNonStringId() { 'target_entity_type_id' => 'entity_test_string_id', )); $bundle->save(); - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'foo', 'entity_type' => 'entity_test_string_id', 'settings' => array( @@ -64,7 +64,7 @@ public function testCommentFieldNonStringId() { ), 'type' => 'comment', )); - $field->save(); + $field_storage->save(); $this->fail('Did not throw an exception as expected.'); } catch (\UnexpectedValueException $e) { diff --git a/core/modules/comment/src/Tests/CommentTranslationUITest.php b/core/modules/comment/src/Tests/CommentTranslationUITest.php index 7314c30..b87604c 100644 --- a/core/modules/comment/src/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/src/Tests/CommentTranslationUITest.php @@ -9,7 +9,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\content_translation\Tests\ContentTranslationUITest; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; /** * Tests the Comment Translation UI. @@ -74,9 +74,9 @@ protected function getTranslatorPermissions() { */ function setupTestFields() { parent::setupTestFields(); - $field = FieldConfig::loadByName('comment', 'comment_body'); - $field->translatable = TRUE; - $field->save(); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $field_storage->translatable = TRUE; + $field_storage->save(); } /** diff --git a/core/modules/comment/src/Tests/CommentTypeTest.php b/core/modules/comment/src/Tests/CommentTypeTest.php index fb040b7..24e7b75 100644 --- a/core/modules/comment/src/Tests/CommentTypeTest.php +++ b/core/modules/comment/src/Tests/CommentTypeTest.php @@ -9,7 +9,7 @@ use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\CommentType; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldInstanceConfig; use Drupal\node\Entity\Node; @@ -125,7 +125,7 @@ public function testCommentTypeDeletion() { $type = $this->createCommentType('foo'); $this->drupalCreateContentType(array('type' => 'page')); \Drupal::service('comment.manager')->addDefaultField('node', 'page', 'foo', CommentItemInterface::OPEN, 'foo'); - $field = FieldConfig::loadByName('node', 'foo'); + $field_storage = FieldStorageConfig::loadByName('node', 'foo'); $this->drupalLogin($this->adminUser); @@ -162,7 +162,7 @@ public function testCommentTypeDeletion() { // Delete the comment and the field. $comment->delete(); - $field->delete(); + $field_storage->delete(); // Attempt to delete the comment type, which should now be allowed. $this->drupalGet('admin/structure/comment/manage/' . $type->id() . '/delete'); $this->assertRaw( diff --git a/core/modules/comment/src/Tests/CommentUninstallTest.php b/core/modules/comment/src/Tests/CommentUninstallTest.php index 5be58c8..c56001a 100644 --- a/core/modules/comment/src/Tests/CommentUninstallTest.php +++ b/core/modules/comment/src/Tests/CommentUninstallTest.php @@ -7,7 +7,7 @@ namespace Drupal\comment\Tests; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; /** @@ -44,15 +44,15 @@ protected function setUp() { */ function testCommentUninstallWithField() { // Ensure that the field exists before uninstallation. - $field = FieldConfig::loadByName('comment', 'comment_body'); - $this->assertNotNull($field, 'The comment_body field exists.'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $this->assertNotNull($field_storage, 'The comment_body field exists.'); // Uninstall the comment module which should trigger field deletion. $this->container->get('module_handler')->uninstall(array('comment')); // Check that the field is now deleted. - $field = FieldConfig::loadByName('comment', 'comment_body'); - $this->assertNull($field, 'The comment_body field has been deleted.'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $this->assertNull($field_storage, 'The comment_body field has been deleted.'); } @@ -61,13 +61,13 @@ function testCommentUninstallWithField() { */ function testCommentUninstallWithoutField() { // Manually delete the comment_body field before module uninstallation. - $field = FieldConfig::loadByName('comment', 'comment_body'); - $this->assertNotNull($field, 'The comment_body field exists.'); - $field->delete(); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $this->assertNotNull($field_storage, 'The comment_body field exists.'); + $field_storage->delete(); // Check that the field is now deleted. - $field = FieldConfig::loadByName('comment', 'comment_body'); - $this->assertNull($field, 'The comment_body field has been deleted.'); + $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); + $this->assertNull($field_storage, 'The comment_body field has been deleted.'); // Ensure that uninstallation succeeds even if the field has already been // deleted manually beforehand. diff --git a/core/modules/comment/src/Tests/CommentValidationTest.php b/core/modules/comment/src/Tests/CommentValidationTest.php index b705b16..ccc3a1d 100644 --- a/core/modules/comment/src/Tests/CommentValidationTest.php +++ b/core/modules/comment/src/Tests/CommentValidationTest.php @@ -55,7 +55,7 @@ public function testValidation() { ))->save(); // Add comment field to content. - $this->entityManager->getStorage('field_config')->create(array( + $this->entityManager->getStorage('field_storage_config')->create(array( 'entity_type' => 'node', 'name' => 'comment', 'type' => 'comment', diff --git a/core/modules/config/src/Tests/ConfigExportImportUITest.php b/core/modules/config/src/Tests/ConfigExportImportUITest.php index baa12f5..f1b6378 100644 --- a/core/modules/config/src/Tests/ConfigExportImportUITest.php +++ b/core/modules/config/src/Tests/ConfigExportImportUITest.php @@ -72,27 +72,28 @@ public function testExportImport() { $this->content_type = $this->drupalCreateContentType(); // Create a field. - $this->field = entity_create('field_config', array( - 'name' => drupal_strtolower($this->randomName()), + $this->fieldName = drupal_strtolower($this->randomName()); + $this->fieldStorage = entity_create('field_storage_config', array( + 'name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text', )); - $this->field->save(); + $this->fieldStorage->save(); entity_create('field_instance_config', array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => $this->content_type->type, ))->save(); entity_get_form_display('node', $this->content_type->type, 'default') - ->setComponent($this->field->name, array( + ->setComponent($this->fieldName, array( 'type' => 'text_textfield', )) ->save(); entity_get_display('node', $this->content_type->type, 'full') - ->setComponent($this->field->name) + ->setComponent($this->fieldName) ->save(); $this->drupalGet('node/add/' . $this->content_type->type); - $this->assertFieldByName("{$this->field->name}[0][value]", '', 'Widget is displayed'); + $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed'); // Export the configuration. $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export'); @@ -106,18 +107,18 @@ public function testExportImport() { // Delete the custom field. $field_instances = entity_load_multiple('field_instance_config'); foreach ($field_instances as $field_instance) { - if ($field_instance->field_name == $this->field->name) { + if ($field_instance->field_name == $this->fieldName) { $field_instance->delete(); } } - $fields = entity_load_multiple('field_config'); - foreach ($fields as $field) { - if ($field->name == $this->field->name) { - $field->delete(); + $field_storages = entity_load_multiple('field_storage_config'); + foreach ($field_storages as $field_storage) { + if ($field_storage->name == $this->fieldName) { + $field_storage->delete(); } } $this->drupalGet('node/add/' . $this->content_type->type); - $this->assertNoFieldByName("{$this->field->name}[0][value]", '', 'Widget is not displayed'); + $this->assertNoFieldByName("{$this->fieldName}[0][value]", '', 'Widget is not displayed'); // Import the configuration. $filename = 'temporary://' . $this->randomName(); @@ -128,7 +129,7 @@ public function testExportImport() { $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->newSlogan); $this->drupalGet('node/add'); - $this->assertFieldByName("{$this->field->name}[0][value]", '', 'Widget is displayed'); + $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed'); } /** diff --git a/core/modules/config/src/Tests/ConfigImportAllTest.php b/core/modules/config/src/Tests/ConfigImportAllTest.php index 1624211..b25126f 100644 --- a/core/modules/config/src/Tests/ConfigImportAllTest.php +++ b/core/modules/config/src/Tests/ConfigImportAllTest.php @@ -67,8 +67,8 @@ public function testInstallUninstall() { // example, if a comment field exists then module becomes required and can // not be uninstalled. - $fields = \Drupal::entityManager()->getStorage('field_config')->loadMultiple(); - \Drupal::entityManager()->getStorage('field_config')->delete($fields); + $fields = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple(); + \Drupal::entityManager()->getStorage('field_storage_config')->delete($fields); // Purge the data. field_purge_batch(1000); diff --git a/core/modules/contact/src/Tests/Views/ContactFieldsTest.php b/core/modules/contact/src/Tests/Views/ContactFieldsTest.php index 4308ca7..4ddcf15 100644 --- a/core/modules/contact/src/Tests/Views/ContactFieldsTest.php +++ b/core/modules/contact/src/Tests/Views/ContactFieldsTest.php @@ -23,11 +23,11 @@ class ContactFieldsTest extends ViewTestBase { public static $modules = array('field', 'text', 'contact'); /** - * Contains the field definition array attached to contact used for this test. + * Contains the field storage definition for contact used for this test. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $field_storage; public static function getInfo() { return array( @@ -40,12 +40,12 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - $this->field = entity_create('field_config', array( + $this->field_storage = entity_create('field_storage_config', array( 'name' => strtolower($this->randomName()), 'entity_type' => 'contact_message', 'type' => 'text' )); - $this->field->save(); + $this->field_storage->save(); entity_create('contact_category', array( 'id' => 'contact_message', @@ -53,7 +53,7 @@ protected function setUp() { ))->save(); entity_create('field_instance_config', array( - 'field' => $this->field, + 'field_storage' => $this->field_storage, 'bundle' => 'contact_message', ))->save(); @@ -66,7 +66,7 @@ protected function setUp() { public function testViewsData() { // Test that the field is not exposed to views, since contact_message // entities have no storage. - $table_name = ContentEntityDatabaseStorage::_fieldTableName($this->field); + $table_name = ContentEntityDatabaseStorage::_fieldTableName($this->field_storage); $data = $this->container->get('views.views_data')->get($table_name); $this->assertFalse($data, 'The field is not exposed to Views.'); } diff --git a/core/modules/content_translation/content_translation.install b/core/modules/content_translation/content_translation.install index 383d043..06a355b 100644 --- a/core/modules/content_translation/content_translation.install +++ b/core/modules/content_translation/content_translation.install @@ -89,7 +89,7 @@ function content_translation_install() { module_set_weight('content_translation', 10); \Drupal::service('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0)); - $config_names = \Drupal::configFactory()->listAll('field.field.'); + $config_names = \Drupal::configFactory()->listAll(\Drupal::entityManager()->getDefinition('field_storage_config')->getConfigPrefix() . '.'); foreach ($config_names as $name) { \Drupal::config($name) ->set('settings.translation_sync', FALSE) @@ -123,7 +123,7 @@ function content_translation_enable() { * Implements hook_uninstall(). */ function content_translation_uninstall() { - $config_names = \Drupal::configFactory()->listAll('field.field.'); + $config_names = \Drupal::configFactory()->listAll(\Drupal::entityManager()->getDefinition('field_storage_config')->getConfigPrefix() . '.'); foreach ($config_names as $name) { \Drupal::config($name) ->clear('settings.translation_sync') diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 0d22898..287729b 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -679,7 +679,7 @@ function content_translation_form_field_ui_field_instance_edit_form_alter(array function content_translation_entity_presave(EntityInterface $entity) { // By default no column has to be synchronized. // @todo Replace with own storage in https://drupal.org/node/2224761 - if ($entity->getEntityTypeId() === 'field_config') { + if ($entity->getEntityTypeId() === 'field_storage_config') { $entity->settings += array('translation_sync' => FALSE); } // Synchronization can be enabled per instance. diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php index 0db6520..9028806 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php @@ -203,7 +203,7 @@ function testFieldTranslatableSettingsUI() { 'entity_type' => 'node', 'type' => 'text', ); - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field)->save(); $instance = array( 'field_name' => 'article_text', 'entity_type' => 'node', diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php index 5749baf..9a169c9 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php @@ -55,7 +55,7 @@ protected function setupTestFields() { $this->fieldName = 'field_test_et_ui_image'; $this->cardinality = 3; - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'image', diff --git a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php index b299b3f..bf6ea23 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php @@ -175,7 +175,7 @@ protected function enableTranslation() { protected function setupTestFields() { $this->fieldName = 'field_test_et_ui_test'; - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => $this->fieldName, 'type' => 'text', 'entity_type' => $this->entityTypeId, diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index 62b69cb..c240e73 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -24,11 +24,11 @@ class DateTimeFieldTest extends WebTestBase { public static $modules = array('node', 'entity_test', 'datetime', 'field_ui'); /** - * A field to use in this test class. + * A field storage to use in this test class. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $fieldStorage; /** * The instance used in this test class. @@ -58,22 +58,22 @@ function setUp() { $this->drupalLogin($web_user); // Create a field with settings to validate. - $this->field = entity_create('field_config', array( + $this->fieldStorage = entity_create('field_storage_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'entity_test', 'type' => 'datetime', 'settings' => array('datetime_type' => 'date'), )); - $this->field->save(); + $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'required' => TRUE, )); $this->instance->save(); entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') - ->setComponent($this->field->name, array( + ->setComponent($this->fieldStorage->name, array( 'type' => 'datetime_default', )) ->save(); @@ -84,7 +84,7 @@ function setUp() { 'settings' => array('format_type' => 'medium'), ); entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') - ->setComponent($this->field->name, $this->display_options) + ->setComponent($this->fieldStorage->name, $this->display_options) ->save(); } @@ -92,7 +92,7 @@ function setUp() { * Tests date field functionality. */ function testDateField() { - $field_name = $this->field->name; + $field_name = $this->fieldStorage->name; // Display creation form. $this->drupalGet('entity_test/add'); @@ -159,10 +159,10 @@ function testDateField() { * Tests date and time field. */ function testDatetimeField() { - $field_name = $this->field->name; + $field_name = $this->fieldStorage->name; // Change the field to a datetime field. - $this->field->settings['datetime_type'] = 'datetime'; - $this->field->save(); + $this->fieldStorage->settings['datetime_type'] = 'datetime'; + $this->fieldStorage->save(); // Display creation form. $this->drupalGet('entity_test/add'); @@ -226,10 +226,10 @@ function testDatetimeField() { * Tests Date List Widget functionality. */ function testDatelistWidget() { - $field_name = $this->field->name; + $field_name = $this->fieldStorage->name; // Change the field to a datetime field. - $this->field->settings['datetime_type'] = 'datetime'; - $this->field->save(); + $this->fieldStorage->settings['datetime_type'] = 'datetime'; + $this->fieldStorage->save(); // Change the widget to a datelist widget. entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') @@ -294,17 +294,17 @@ function testDefaultValue() { // Create a test content type. $this->drupalCreateContentType(array('type' => 'date_content')); - // Create a field with settings to validate. - $field = entity_create('field_config', array( + // Create a field storage with settings to validate. + $field_storage = entity_create('field_storage_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'node', 'type' => 'datetime', 'settings' => array('datetime_type' => 'date'), )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'date_content', )); $instance->save(); @@ -313,14 +313,14 @@ function testDefaultValue() { $instance_edit = array( 'default_value_input[default_date]' => 'now', ); - $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field->name, $instance_edit, t('Save settings')); + $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $instance_edit, t('Save settings')); // Check that default value is selected in default value form. - $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field->name); + $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name); $this->assertRaw('', 'The default value is selected in instance settings page'); // Check if default_date has been stored successfully. - $config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field->name)->get(); + $config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field_storage->name)->get(); $this->assertEqual($config_entity['default_value'][0]['default_date'], 'now', 'Default value has been stored successfully'); // Clear field cache in order to avoid stale cache values. @@ -329,20 +329,20 @@ function testDefaultValue() { // Create a new node to check that datetime field default value is today. $new_node = entity_create('node', array('type' => 'date_content')); $expected_date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE); - $this->assertEqual($new_node->get($field->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT)); + $this->assertEqual($new_node->get($field_storage->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT)); // Remove default value. $instance_edit = array( 'default_value_input[default_date]' => '', ); - $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field->name, $instance_edit, t('Save settings')); + $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $instance_edit, t('Save settings')); // Check that default value is selected in default value form. - $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field->name); + $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name); $this->assertRaw('', 'The default value is selected in instance settings page'); // Check if default_date has been stored successfully. - $config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field->name)->get(); + $config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field_storage->name)->get(); $this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully'); // Clear field cache in order to avoid stale cache values. @@ -350,7 +350,7 @@ function testDefaultValue() { // Create a new node to check that datetime field default value is today. $new_node = entity_create('node', array('type' => 'date_content')); - $this->assertNull($new_node->get($field->name)->offsetGet(0)->value, 'Default value is not set'); + $this->assertNull($new_node->get($field_storage->name)->offsetGet(0)->value, 'Default value is not set'); } /** @@ -359,9 +359,9 @@ function testDefaultValue() { function testInvalidField() { // Change the field to a datetime field. - $this->field->settings['datetime_type'] = 'datetime'; - $this->field->save(); - $field_name = $this->field->name; + $this->fieldStorage->settings['datetime_type'] = 'datetime'; + $this->fieldStorage->save(); + $field_name = $this->fieldStorage->name; // Display creation form. $this->drupalGet('entity_test/add'); diff --git a/core/modules/datetime/src/Tests/DateTimeItemTest.php b/core/modules/datetime/src/Tests/DateTimeItemTest.php index 79f0781..6f50ace 100644 --- a/core/modules/datetime/src/Tests/DateTimeItemTest.php +++ b/core/modules/datetime/src/Tests/DateTimeItemTest.php @@ -35,15 +35,15 @@ public function setUp() { parent::setUp(); // Create a field with settings to validate. - $this->field = entity_create('field_config', array( + $this->fieldStorage = entity_create('field_storage_config', array( 'name' => 'field_datetime', 'type' => 'datetime', 'entity_type' => 'entity_test', 'settings' => array('datetime_type' => 'date'), )); - $this->field->save(); + $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'settings' => array( 'default_value' => 'blank', diff --git a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php index dcaf31d..bc96764 100644 --- a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php +++ b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php @@ -150,8 +150,8 @@ public function testEditorSelection() { $this->assertEqual('editor', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality 1, and the full_html text format, the 'editor' editor is selected."); // Editor selection with text processing, cardinality >1 - $this->field_textarea_field->cardinality = 2; - $this->field_textarea_field->save(); + $this->field_textarea_field_storage->cardinality = 2; + $this->field_textarea_field_storage->save(); $this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected."); } diff --git a/core/modules/entity/src/Tests/EntityDisplayTest.php b/core/modules/entity/src/Tests/EntityDisplayTest.php index f0c8e0c..f812e05 100644 --- a/core/modules/entity/src/Tests/EntityDisplayTest.php +++ b/core/modules/entity/src/Tests/EntityDisplayTest.php @@ -146,15 +146,15 @@ public function testFieldComponent() { $this->enableModules(array('field_test')); $field_name = 'test_field'; - // Create a field and an instance. - $field = entity_create('field_config', array( + // Create a field storage and an instance. + $field_storage = entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', )); $instance->save(); @@ -167,7 +167,7 @@ public function testFieldComponent() { // Check that providing no options results in default values being used. $display->setComponent($field_name); - $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->type); + $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->type); $default_formatter = $field_type_info['default_formatter']; $formatter_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($default_formatter); $expected = array( @@ -323,15 +323,15 @@ public function testDeleteFieldInstance() { $this->enableModules(array('field_test')); $field_name = 'test_field'; - // Create a field and an instance. - $field = entity_create('field_config', array( + // Create a field storage and an instance. + $field_storage = entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', )); $instance->save(); diff --git a/core/modules/entity/src/Tests/EntityFormDisplayTest.php b/core/modules/entity/src/Tests/EntityFormDisplayTest.php index 6caf775..277605c 100644 --- a/core/modules/entity/src/Tests/EntityFormDisplayTest.php +++ b/core/modules/entity/src/Tests/EntityFormDisplayTest.php @@ -55,16 +55,16 @@ public function testEntityGetFromDisplay() { public function testFieldComponent() { $this->enableModules(array('field_test')); - // Create a field and an instance. + // Create a field storage and an instance. $field_name = 'test_field'; - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', )); $instance->save(); @@ -77,7 +77,7 @@ public function testFieldComponent() { // Check that providing no options results in default values being used. $form_display->setComponent($field_name); - $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->type); + $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->type); $default_widget = $field_type_info['default_widget']; $widget_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($default_widget); $expected = array( @@ -186,15 +186,15 @@ public function testDeleteFieldInstance() { $this->enableModules(array('field_sql_storage', 'field_test')); $field_name = 'test_field'; - // Create a field and an instance. - $field = entity_create('field_config', array( + // Create a field storage and an instance. + $field_storage = entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', )); $instance->save(); diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 48ffc92..7fcc560 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -7,13 +7,11 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Database\Query\AlterableInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldInstanceConfig; -use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; /** * Implements hook_help(). @@ -65,34 +63,34 @@ function entity_reference_field_widget_info_alter(&$info) { } /** - * Implements hook_ENTITY_TYPE_update() for 'field_config'. + * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'. * * Reset the instance handler settings, when the target type is changed. */ -function entity_reference_field_config_update(FieldConfigInterface $field) { - if ($field->type != 'entity_reference') { +function entity_reference_field_storage_config_update(FieldStorageConfigInterface $field_storage) { + if ($field_storage->type != 'entity_reference') { // Only act on entity reference fields. return; } - if ($field->isSyncing()) { + if ($field_storage->isSyncing()) { // Don't change anything during a configuration sync. return; } - if ($field->getSetting('target_type') == $field->original->getSetting('target_type')) { + if ($field_storage->getSetting('target_type') == $field_storage->original->getSetting('target_type')) { // Target type didn't change. return; } - if (empty($field->bundles)) { + if (empty($field_storage->bundles)) { // Field has no instances. return; } - $field_name = $field->getName(); + $field_name = $field_storage->getName(); - foreach ($field->bundles() as $entity_type => $bundles) { + foreach ($field_storage->bundles() as $entity_type => $bundles) { foreach ($bundles as $bundle) { $instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); $instance->settings['handler_settings'] = array(); @@ -207,11 +205,11 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query */ function entity_reference_create_instance($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) { // Look for or add the specified field to the requested entity bundle. - $field = FieldConfig::loadByName($entity_type, $field_name); + $field_storage = FieldStorageConfig::loadByName($entity_type, $field_name); $instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); - if (empty($field)) { - $field = array( + if (empty($field_storage)) { + $field_storage = array( 'name' => $field_name, 'type' => 'entity_reference', 'entity_type' => $entity_type, @@ -220,7 +218,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f 'target_type' => $target_entity_type, ), ); - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); } if (empty($instance)) { diff --git a/core/modules/entity_reference/entity_reference.views.inc b/core/modules/entity_reference/entity_reference.views.inc index 47f0179..e35884b 100644 --- a/core/modules/entity_reference/entity_reference.views.inc +++ b/core/modules/entity_reference/entity_reference.views.inc @@ -6,17 +6,17 @@ */ use Drupal\Core\Entity\ContentEntityDatabaseStorage; -use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; /** * Implements hook_field_views_data(). */ -function entity_reference_field_views_data(FieldConfigInterface $field) { - $data = field_views_field_default_views_data($field); +function entity_reference_field_views_data(FieldStorageConfigInterface $field_storage) { + $data = field_views_field_default_views_data($field_storage); $entity_manager = \Drupal::entityManager(); foreach ($data as $table_name => $table_data) { // Add a relationship to the target entity type. - $target_entity_type_id = $field->getSetting('target_type'); + $target_entity_type_id = $field_storage->getSetting('target_type'); $target_entity_type = $entity_manager->getDefinition($target_entity_type_id); $target_base_table = $target_entity_type->getBaseTable(); @@ -24,31 +24,31 @@ function entity_reference_field_views_data(FieldConfigInterface $field) { // field. $args = array( '@label' => $target_entity_type->getLabel(), - '@field_name' => $field->getName(), + '@field_name' => $field_storage->getName(), ); - $data[$table_name][$field->getName()]['relationship'] = array( + $data[$table_name][$field_storage->getName()]['relationship'] = array( 'id' => 'standard', 'base' => $target_base_table, 'entity type' => $target_entity_type_id, 'base field' => $target_entity_type->getKey('id'), - 'relationship field' => $field->getName() . '_target_id', + 'relationship field' => $field_storage->getName() . '_target_id', 'title' => t('@label referenced from @field_name', $args), 'label' => t('@field_name: @label', $args), ); // Provide a reverse relationship for the entity type that is referenced by // the field. - $pseudo_field_name = 'reverse__' . $field->getTargetEntityTypeId() . '__' . $field->getName(); + $pseudo_field_name = 'reverse__' . $field_storage->getTargetEntityTypeId() . '__' . $field_storage->getName(); $data[$target_base_table][$pseudo_field_name]['relationship'] = array( 'title' => t('@label using @field_name', $args), 'help' => t('Relate each @label with a @field_name.', $args), 'id' => 'entity_reverse', - 'field_name' => $field->getName(), - 'field table' => ContentEntityDatabaseStorage::_fieldTableName($field), - 'field field' => $field->getName() . '_target_id', + 'field_name' => $field_storage->getName(), + 'field table' => ContentEntityDatabaseStorage::_fieldTableName($field_storage), + 'field field' => $field_storage->getName() . '_target_id', 'base' => $target_entity_type->getBaseTable(), 'base field' => $target_entity_type->getKey('id'), - 'label' => t('@field_name', array('@field_name' => $field->getName())), + 'label' => t('@field_name', array('@field_name' => $field_storage->getName())), ); } diff --git a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php index cabf660..269ad8c 100644 --- a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php @@ -15,7 +15,7 @@ use Drupal\Core\TypedData\AllowedValuesInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Validation\Plugin\Validation\Constraint\AllowedValuesConstraint; -use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; /** * Alternative plugin implementation of the 'entity_reference' field type. @@ -144,7 +144,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) $target_type = $field_definition->getSetting('target_type'); $target_type_info = \Drupal::entityManager()->getDefinition($target_type); - if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') && $field_definition instanceof FieldConfigInterface) { + if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') && $field_definition instanceof FieldStorageConfigInterface) { $schema['columns']['revision_id'] = array( 'description' => 'The revision ID of the target entity.', 'type' => 'int', diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php index 61e3308..7e478da 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php @@ -35,7 +35,7 @@ function setUp() { $referenced = $this->drupalCreateContentType(); $this->referenced_type = $referenced->type; - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => 'test_field', 'entity_type' => 'node', 'translatable' => FALSE, diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php index ff29c03..a2a0a93 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php @@ -48,15 +48,15 @@ function testEntityReferenceDefaultValue() { // Create a node to be referenced. $referenced_node = $this->drupalCreateNode(array('type' => 'referenced_content')); - $this->field = entity_create('field_config', array( + $this->fieldStorage = entity_create('field_storage_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'node', 'type' => 'entity_reference', 'settings' => array('target_type' => 'node'), )); - $this->field->save(); + $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => 'reference_content', 'settings' => array( 'handler' => 'default', @@ -70,16 +70,16 @@ function testEntityReferenceDefaultValue() { // Set created node as default_value. $instance_edit = array( - 'default_value_input[' . $this->field->name . '][0][target_id]' => $referenced_node->getTitle() . ' (' .$referenced_node->id() . ')', + 'default_value_input[' . $this->fieldStorage->name . '][0][target_id]' => $referenced_node->getTitle() . ' (' .$referenced_node->id() . ')', ); - $this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->field->name, $instance_edit, t('Save settings')); + $this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name, $instance_edit, t('Save settings')); // Check that default value is selected in default value form. - $this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->field->name); - $this->assertRaw('name="default_value_input[' . $this->field->name . '][0][target_id]" value="' . $referenced_node->getTitle() .' (' .$referenced_node->id() . ')', 'The default value is selected in instance settings page'); + $this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name); + $this->assertRaw('name="default_value_input[' . $this->fieldStorage->name . '][0][target_id]" value="' . $referenced_node->getTitle() .' (' .$referenced_node->id() . ')', 'The default value is selected in instance settings page'); // Check if the ID has been converted to UUID in config entity. - $config_entity = $this->container->get('config.factory')->get('field.instance.node.reference_content.' . $this->field->name)->get(); + $config_entity = $this->container->get('config.factory')->get('field.instance.node.reference_content.' . $this->fieldStorage->name)->get(); $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'); @@ -88,7 +88,7 @@ function testEntityReferenceDefaultValue() { // Create a new node to check that UUID has been converted to numeric ID. $new_node = entity_create('node', array('type' => 'reference_content')); - $this->assertEqual($new_node->get($this->field->name)->offsetGet(0)->target_id, $referenced_node->id()); + $this->assertEqual($new_node->get($this->fieldStorage->name)->offsetGet(0)->target_id, $referenced_node->id()); } } diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFieldTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFieldTest.php index d5357ba..a494684 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceFieldTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceFieldTest.php @@ -7,10 +7,8 @@ namespace Drupal\entity_reference\Tests; -use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\Entity\FieldInstanceConfig; use Drupal\system\Tests\Entity\EntityUnitTestBase; +use Drupal\Core\Field\FieldStorageDefinitionInterface; /** * Tests for the entity reference field. @@ -46,20 +44,6 @@ class EntityReferenceFieldTest extends EntityUnitTestBase { protected $fieldName = 'field_test'; /** - * A field array. - * - * @var array - */ - protected $field; - - /** - * An associative array of field instance data. - * - * @var array - */ - protected $instance; - - /** * Modules to enable. * * @var array @@ -91,8 +75,6 @@ public function setUp() { FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ); - $this->field = FieldConfig::loadByName($this->entityType, $this->fieldName); - $this->instance = FieldInstanceConfig::loadByName($this->entityType, $this->bundle, $this->fieldName); } /** diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php index 61d0ee5..02fad12 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php @@ -64,7 +64,7 @@ public function setUp() { // Set up a field, so that the entity that'll be referenced bubbles up a // cache tag when rendering it entirely. - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => 'body', 'entity_type' => $this->entityType, 'type' => 'text', diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php index 368c1d2..a9de6e8 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionAccessTest.php @@ -61,8 +61,8 @@ protected function assertReferenceable(FieldDefinitionInterface $field_definitio * Test the node-specific overrides of the entity handler. */ public function testNodeHandler() { - // Create a field and instance. - $field = entity_create('field_config', array( + // Create a field storage and instance. + $field_storage = entity_create('field_storage_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -73,9 +73,9 @@ public function testNodeHandler() { 'type' => 'entity_reference', 'cardinality' => '1', )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'default', @@ -204,8 +204,8 @@ public function testNodeHandler() { * Test the user-specific overrides of the entity handler. */ public function testUserHandler() { - // Create a field and instance. - $field = entity_create('field_config', array( + // Create a field storage and instance. + $field_storage = entity_create('field_storage_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -215,9 +215,9 @@ public function testUserHandler() { 'type' => 'entity_reference', 'cardinality' => '1', )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'default', @@ -348,8 +348,8 @@ public function testUserHandler() { * Test the comment-specific overrides of the entity handler. */ public function testCommentHandler() { - // Create a field and instance. - $field = entity_create('field_config', array( + // Create a field storage and instance. + $field_storage = entity_create('field_storage_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -360,9 +360,9 @@ public function testCommentHandler() { 'type' => 'entity_reference', 'cardinality' => '1', )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'default', diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php index a0ab8db..e38fa73 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceSelectionSortTest.php @@ -37,7 +37,7 @@ function setUp() { */ public function testSort() { // Add text field to entity, to sort by. - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => 'field_text', 'entity_type' => 'node', 'type' => 'text', @@ -54,8 +54,8 @@ public function testSort() { ))->save(); - // Create a field and instance. - $field = entity_create('field_config', array( + // Create a field storage and instance. + $field_storage = entity_create('field_storage_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -65,9 +65,9 @@ public function testSort() { 'type' => 'entity_reference', 'cardinality' => 1, )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'entity_type' => 'entity_test', 'bundle' => 'test_bundle', 'settings' => array( diff --git a/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php b/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php index 4b8dd06..8d73a86 100644 --- a/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php +++ b/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php @@ -8,7 +8,7 @@ namespace Drupal\entity_reference\Tests\Views; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldInstanceConfig; use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewUnitTestBase; @@ -63,7 +63,7 @@ protected function setUp() { ViewTestData::createTestViews(get_class($this), array('entity_reference_test_views')); - $field = FieldConfig::create(array( + $field = FieldStorageConfig::create(array( 'settings' => array( 'target_type' => 'entity_test', ), diff --git a/core/modules/entity_reference/src/Tests/Views/SelectionTest.php b/core/modules/entity_reference/src/Tests/Views/SelectionTest.php index 56328a3..120ad5d 100644 --- a/core/modules/entity_reference/src/Tests/Views/SelectionTest.php +++ b/core/modules/entity_reference/src/Tests/Views/SelectionTest.php @@ -39,8 +39,8 @@ public function testSelectionHandler() { $nodes[$node->getType()][$node->id()] = $node->label(); } - // Create a field and instance. - $field = entity_create('field_config', array( + // Create a field storage and instance. + $field_storage = entity_create('field_storage_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -50,9 +50,9 @@ public function testSelectionHandler() { 'type' => 'entity_reference', 'cardinality' => '1', )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'test_bundle', 'settings' => array( 'handler' => 'views', diff --git a/core/modules/field/config/schema/field.schema.yml b/core/modules/field/config/schema/field.schema.yml index 7018b5f..f680f5a 100644 --- a/core/modules/field/config/schema/field.schema.yml +++ b/core/modules/field/config/schema/field.schema.yml @@ -8,7 +8,7 @@ field.settings: type: integer label: 'Maximum number of field data records to purge' -field.field.*.*: +field.storage.*.*: type: config_entity label: 'Field' mapping: diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index f364c51..49d59b0 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -237,7 +237,7 @@ function hook_field_info_max_weight($entity_type, $bundle, $context, $context_mo */ /** - * Forbid a field update from occurring. + * Forbid a field storage update from occurring. * * Any module may forbid any update for any reason. For example, the * field's storage module might forbid an update if it would change @@ -249,45 +249,45 @@ function hook_field_info_max_weight($entity_type, $bundle, $context, $context_mo * To forbid the update from occurring, throw a * \Drupal\Core\Entity\Exception\StorageDefinitionUpdateForbiddenException. * - * @param \Drupal\field\FieldConfigInterface $field - * The field as it will be post-update. - * @param \Drupal\field\FieldConfigInterface $prior_field - * The field as it is pre-update. + * @param \Drupal\field\FieldStorageConfigInterface $field_storage + * The field storage as it will be post-update. + * @param \Drupal\field\FieldStorageConfigInterface $prior_field_storage + * The field storage as it is pre-update. */ -function hook_field_config_update_forbid(\Drupal\field\FieldConfigInterface $field, \Drupal\field\FieldConfigInterface $prior_field) { +function hook_field_storage_config_update_forbid(\Drupal\field\FieldStorageConfigInterface $field_storage, \Drupal\field\FieldStorageConfigInterface $prior_field_storage) { // A 'list' field stores integer keys mapped to display values. If // the new field will have fewer values, and any data exists for the // abandoned keys, the field will have no way to display them. So, // forbid such an update. - if ($field->hasData() && count($field['settings']['allowed_values']) < count($prior_field['settings']['allowed_values'])) { + if ($field_storage->hasData() && count($field_storage['settings']['allowed_values']) < count($prior_field_storage['settings']['allowed_values'])) { // Identify the keys that will be lost. - $lost_keys = array_diff(array_keys($field['settings']['allowed_values']), array_keys($prior_field['settings']['allowed_values'])); + $lost_keys = array_diff(array_keys($field_storage['settings']['allowed_values']), array_keys($prior_field_storage['settings']['allowed_values'])); // If any data exist for those keys, forbid the update. $query = new EntityFieldQuery(); $found = $query - ->fieldCondition($prior_field['field_name'], 'value', $lost_keys) + ->fieldCondition($prior_field_storage['field_name'], 'value', $lost_keys) ->range(0, 1) ->execute(); if ($found) { - throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException("Cannot update a list field not to include keys with existing data"); + throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException("Cannot update a list field storage not to include keys with existing data"); } } } /** - * Acts when a field record is being purged. + * Acts when a field storage definition is being purged. * - * In field_purge_field(), after the field definition has been removed from the - * the system, the entity storage has purged stored field data, and the field - * info cache has been cleared, this hook is invoked on all modules to allow - * them to respond to the field being purged. + * In field_purge_field_storage(), after the storage definition has been removed + * from the the system, the entity storage has purged stored field data, and the + * field definitions cache has been cleared, this hook is invoked on all modules + * to allow them to respond to the field being purged. * - * @param $field - * The field being purged. + * @param $field_storage \Drupal\field\Entity\FieldStorageConfig + * The field storage being purged. */ -function hook_field_purge_field($field) { - db_delete('my_module_field_info') - ->condition('id', $field['id']) +function hook_field_purge_field_storage(\Drupal\field\Entity\FieldStorageConfig $field_storage) { + db_delete('my_module_field_storage_info') + ->condition('uuid', $field_storage->uuid()) ->execute(); } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 5695f40..576a48a 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -125,7 +125,7 @@ function field_system_info_alter(&$info, Extension $file, $type) { // It is not safe to call entity_load_multiple_by_properties() during // maintenance mode. if ($type == 'module' && !defined('MAINTENANCE_MODE')) { - $fields = entity_load_multiple_by_properties('field_config', array('module' => $file->getName(), 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_storage_config', array('module' => $file->getName(), 'include_deleted' => TRUE)); if ($fields) { $info['required'] = TRUE; @@ -162,15 +162,15 @@ function field_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface if ($entity_type->isFieldable()) { // Query by filtering on the ID as this is more efficient than filtering // on the entity_type property directly. - $ids = \Drupal::entityQuery('field_config') + $ids = \Drupal::entityQuery('field_storage_config') ->condition('id', $entity_type->id() . '.', 'STARTS_WITH') ->execute(); // Fetch all fields and key them by field name. - $field_configs = entity_load_multiple('field_config', $ids); + $field_storages = entity_load_multiple('field_storage_config', $ids); $result = array(); - foreach ($field_configs as $field_config) { - $result[$field_config->getName()] = $field_config; + foreach ($field_storages as $field_storage) { + $result[$field_storage->getName()] = $field_storage; } return $result; } @@ -323,11 +323,11 @@ function field_hook_info() { * Implements hook_config_import_steps_alter(). */ function field_config_import_steps_alter(&$sync_steps, ConfigImporter $config_importer) { - $fields = \Drupal\field\ConfigImporterFieldPurger::getFieldsToPurge( + $field_storages = \Drupal\field\ConfigImporterFieldPurger::getFieldStoragesToPurge( $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension'), $config_importer->getStorageComparer()->getChangelist('delete') ); - if ($fields) { + if ($field_storages) { // Add a step to the beginning of the configuration synchronization process // to purge field data where the module that provides the field is being // uninstalled. @@ -347,16 +347,16 @@ function field_form_config_admin_import_form_alter(&$form, &$form_state) { // Only display the message when there is a storage comparer available and the // form is not submitted. if (isset($form_state['storage_comparer']) && empty($form_state['input'])) { - $fields = \Drupal\field\ConfigImporterFieldPurger::getFieldsToPurge( + $field_storages = \Drupal\field\ConfigImporterFieldPurger::getFieldStoragesToPurge( $form_state['storage_comparer']->getSourceStorage()->read('core.extension'), $form_state['storage_comparer']->getChangelist('delete') ); - if ($fields) { - foreach ($fields as $field) { + if ($field_storages) { + foreach ($field_storages as $field) { $field_labels[] = $field->label(); } drupal_set_message(\Drupal::translation()->formatPlural( - count($fields), + count($field_storages), 'This synchronization will delete data from the field %fields.', 'This synchronization will delete data from the fields: %fields.', array('%fields' => implode(', ', $field_labels)) diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index 4a289cf..a17e6f2 100644 --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -5,7 +5,8 @@ * Provides support for field data purge after mass deletion. */ -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; +use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldException; /** @@ -68,18 +69,19 @@ * * @param $batch_size * The maximum number of field data records to purge before returning. - * @param string $field_uuid - * (optional) Limit the purge to a specific field. + * @param string $field_storage_uuid + * (optional) Limit the purge to a specific field storage. */ -function field_purge_batch($batch_size, $field_uuid = NULL) { - // Retrieve all deleted field instances. We cannot use field_info_instances() - // because that function does not return deleted instances. - if ($field_uuid) { - $instances = entity_load_multiple_by_properties('field_instance_config', array('deleted' => TRUE, 'include_deleted' => TRUE, 'field_uuid' => $field_uuid)); - } - else { - $instances = entity_load_multiple_by_properties('field_instance_config', array('deleted' => TRUE, 'include_deleted' => TRUE)); +function field_purge_batch($batch_size, $field_storage_uuid = NULL) { + $properties = array( + 'deleted' => TRUE, + 'include_deleted' => TRUE, + ); + if ($field_storage_uuid) { + $properties['field_storage_uuid'] = $field_storage_uuid; } + $instances = entity_load_multiple_by_properties('field_instance_config', $properties); + $info = \Drupal::entityManager()->getDefinitions(); foreach ($instances as $instance) { $entity_type = $instance->entity_type; @@ -103,11 +105,12 @@ function field_purge_batch($batch_size, $field_uuid = NULL) { } } - // Retrieve all deleted fields. Any that have no instances can be purged. - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - foreach ($deleted_fields as $field) { - $field = new FieldConfig($field); - if ($field_uuid && $field->uuid() != $field_uuid) { + // Retrieve all deleted field storages. Any that have no instances can be + // purged. + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + foreach ($deleted_storages as $field_storage) { + $field_storage = new FieldStorageConfig($field_storage); + if ($field_storage_uuid && $field_storage->uuid() != $field_storage_uuid) { // If a specific UUID is provided, only purge the corresponding field. continue; } @@ -115,13 +118,13 @@ function field_purge_batch($batch_size, $field_uuid = NULL) { // We cannot purge anything if the entity type is unknown (e.g. the // providing module was uninstalled). // @todo Revisit after https://drupal.org/node/2080823. - if (!isset($info[$field->entity_type])) { + if (!isset($info[$field_storage->entity_type])) { continue; } - $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); if (empty($instances)) { - field_purge_field($field); + field_purge_field_storage($field_storage); } } } @@ -151,25 +154,25 @@ function field_purge_instance($instance) { * This function assumes all instances for the field has already been purged, * and should only be called by field_purge_batch(). * - * @param $field - * The field record to purge. + * @param \Drupal\field\FieldStorageConfigInterface $field_storage + * The field storage to purge. */ -function field_purge_field($field) { - $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'include_deleted' => TRUE)); +function field_purge_field_storage(FieldStorageConfigInterface $field_storage) { + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); if (count($instances) > 0) { - throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field->getName()))); + throw new FieldException(t('Attempt to purge a field storage @field_name that still has instances.', array('@field_name' => $field_storage->getName()))); } $state = \Drupal::state(); - $deleted_fields = $state->get('field.field.deleted'); - unset($deleted_fields[$field->uuid()]); - $state->set('field.field.deleted', $deleted_fields); + $deleted_storages = $state->get('field.storage.deleted'); + unset($deleted_storages[$field_storage->uuid()]); + $state->set('field.storage.deleted', $deleted_storages); // Notify the storage layer. - \Drupal::entityManager()->getStorage($field->entity_type)->finalizePurge($field); + \Drupal::entityManager()->getStorage($field_storage->entity_type)->finalizePurge($field_storage); // Invoke external hooks after the cache is cleared for API consistency. - \Drupal::moduleHandler()->invokeAll('field_purge_field', array($field)); + \Drupal::moduleHandler()->invokeAll('field_purge_field_storage', array($field_storage)); } /** diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index f74e97c..f5f1b33 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -8,7 +8,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\ContentEntityDatabaseStorage; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldInstanceConfigInterface; /** @@ -21,7 +21,7 @@ function field_views_data() { $data = array(); $module_handler = \Drupal::moduleHandler(); - foreach (\Drupal::entityManager()->getStorage('field_config')->loadMultiple() as $field) { + foreach (\Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple() as $field) { if (_field_views_is_sql_entity_type($field)) { $result = (array) $module_handler->invoke($field->module, 'field_views_data', array($field)); if (empty($result)) { @@ -47,7 +47,7 @@ function field_views_data() { * in field_views_data. */ function field_views_data_alter(&$data) { - foreach (\Drupal::entityManager()->getStorage('field_config')->loadMultiple() as $field) { + foreach (\Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple() as $field) { if (_field_views_is_sql_entity_type($field)) { $function = $field->module . '_field_views_data_views_data_alter'; if (function_exists($function)) { @@ -60,15 +60,15 @@ function field_views_data_alter(&$data) { /** * Determines whether the entity type the field appears in is SQL based. * - * @param \Drupal\field\FieldConfigInterface $field - * The field definition. + * @param \Drupal\field\FieldStorageConfigInterface $field_storage + * The field storage definition. * * @return bool * True if the entity type uses ContentEntityDatabaseStorage. */ -function _field_views_is_sql_entity_type(FieldConfigInterface $field) { +function _field_views_is_sql_entity_type(FieldStorageConfigInterface $field_storage) { $entity_manager = \Drupal::entityManager(); - return $entity_manager->hasDefinition($field->entity_type) && $entity_manager->getStorage($field->entity_type) instanceof ContentEntityDatabaseStorage; + return $entity_manager->hasDefinition($field_storage->entity_type) && $entity_manager->getStorage($field_storage->entity_type) instanceof ContentEntityDatabaseStorage; } /** @@ -103,30 +103,30 @@ function field_views_field_label($entity_type, $field_name) { /** * Default views data implementation for a field. * - * @param \Drupal\field\FieldConfigInterface $field + * @param \Drupal\field\FieldStorageConfigInterface $field_storage * The field definition. * * @return array * The default views data for the field. */ -function field_views_field_default_views_data(FieldConfigInterface $field) { +function field_views_field_default_views_data(FieldStorageConfigInterface $field_storage) { $data = array(); // Check the field type is available. - if (!\Drupal::service('plugin.manager.field.field_type')->hasDefinition($field->getType())) { + if (!\Drupal::service('plugin.manager.field.field_type')->hasDefinition($field_storage->getType())) { return $data; } // Check the field has instances. - if (!$field->getBundles()) { + if (!$field_storage->getBundles()) { return $data; } - $field_name = $field->getName(); - $field_columns = $field->getColumns(); + $field_name = $field_storage->getName(); + $field_columns = $field_storage->getColumns(); // Grab information about the entity type tables. $entity_manager = \Drupal::entityManager(); - $entity_type_id = $field->entity_type; + $entity_type_id = $field_storage->entity_type; $entity_type = $entity_manager->getDefinition($entity_type_id); if (!$entity_table = $entity_type->getBaseTable()) { return $data; @@ -141,13 +141,13 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { // Description of the field tables. $field_tables = array( EntityStorageInterface::FIELD_LOAD_CURRENT => array( - 'table' => ContentEntityDatabaseStorage::_fieldTableName($field), + 'table' => ContentEntityDatabaseStorage::_fieldTableName($field_storage), 'alias' => "{$entity_type_id}__{$field_name}", ), ); if ($supports_revisions) { $field_tables[EntityStorageInterface::FIELD_LOAD_REVISION] = array( - 'table' => ContentEntityDatabaseStorage::_fieldRevisionTableName($field), + 'table' => ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage), 'alias' => "{$entity_type_id}_revision__{$field_name}", ); } @@ -174,11 +174,11 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { $group_name = $entity_type->getLabel(); // Get the list of bundles the field appears in. - $bundles_names = $field->getBundles(); + $bundles_names = $field_storage->getBundles(); // Build the list of additional fields to add to queries. $add_fields = array('delta', 'langcode', 'bundle'); foreach (array_keys($field_columns) as $column) { - $add_fields[] = ContentEntityDatabaseStorage::_fieldColumnName($field, $column); + $add_fields[] = ContentEntityDatabaseStorage::_fieldColumnName($field_storage, $column); } // Determine the label to use for the field. We don't have a label available // at the field level, so we just go through all instances and take the one @@ -302,10 +302,10 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { else { $group = t('@group (historical data)', array('@group' => $group_name)); } - $column_real_name = ContentEntityDatabaseStorage::_fieldColumnName($field, $column); + $column_real_name = ContentEntityDatabaseStorage::_fieldColumnName($field_storage, $column); // Load all the fields from the table by default. - $field_sql_schema = ContentEntityDatabaseStorage::_fieldSqlSchema($field); + $field_sql_schema = ContentEntityDatabaseStorage::_fieldSqlSchema($field_storage); $additional_fields = array_keys($field_sql_schema[$table]['fields']); $data[$table_alias][$column_real_name] = array( @@ -370,7 +370,7 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { } // Expose additional delta column for multiple value fields. - if ($field->isMultiple()) { + if ($field_storage->isMultiple()) { $title_delta = t('@label (!name:delta)', array('@label' => $label, '!name' => $field_name)); $title_short_delta = t('@label:delta', array('@label' => $label)); @@ -412,7 +412,7 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { } // Expose additional language column for translatable fields. - if ($field->isTranslatable()) { + if ($field_storage->isTranslatable()) { $title_language = t('@label (!name:language)', array('@label' => $label, '!name' => $field_name)); $title_short_language = t('@label:language', array('@label' => $label)); @@ -461,15 +461,15 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { /** * Have a different filter handler for lists. This should allow to select values of the list. */ -function list_field_views_data($field) { - $data = field_views_field_default_views_data($field); +function list_field_views_data(FieldStorageConfigInterface $field_storage) { + $data = field_views_field_default_views_data($field_storage); foreach ($data as $table_name => $table_data) { foreach ($table_data as $field_name => $field_data) { if (isset($field_data['filter']) && $field_name != 'delta') { $data[$table_name][$field_name]['filter']['id'] = 'field_list'; } if (isset($field_data['argument']) && $field_name != 'delta') { - if ($field->getType() == 'list_text') { + if ($field_storage->getType() == 'list_text') { $data[$table_name][$field_name]['argument']['id'] = 'field_list_string'; } else { diff --git a/core/modules/field/src/ConfigImporterFieldPurger.php b/core/modules/field/src/ConfigImporterFieldPurger.php index a33df39..fe2fbe6 100644 --- a/core/modules/field/src/ConfigImporterFieldPurger.php +++ b/core/modules/field/src/ConfigImporterFieldPurger.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\Entity\ConfigEntityStorage; +use Drupal\field\Entity\FieldStorageConfig; /** * Processes field purges before a configuration synchronization. @@ -31,27 +32,27 @@ public static function process(array &$context, ConfigImporter $config_importer) static::initializeSandbox($context, $config_importer); } - // Get the list of fields to purge. - $fields = static::getFieldsToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete')); - // Get the first field to process. - $field = reset($fields); - if (!isset($context['sandbox']['field']['current_field_id']) || $context['sandbox']['field']['current_field_id'] != $field->id()) { - $context['sandbox']['field']['current_field_id'] = $field->id(); - // If the field has not been deleted yet we need to do that. This is the + // Get the list of field storages to purge. + $field_storages = static::getFieldStoragesToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete')); + // Get the first field storage to process. + $field_storage = reset($field_storages); + if (!isset($context['sandbox']['field']['current_storage_id']) || $context['sandbox']['field']['current_storage_id'] != $field_storage->id()) { + $context['sandbox']['field']['current_storage_id'] = $field_storage->id(); + // If the storage has not been deleted yet we need to do that. This is the // case when the field deletion is staged. - if (!$field->deleted) { - $field->delete(); + if (!$field_storage->deleted) { + $field_storage->delete(); } } - field_purge_batch($context['sandbox']['field']['purge_batch_size'], $field->uuid()); + field_purge_batch($context['sandbox']['field']['purge_batch_size'], $field_storage->uuid()); $context['sandbox']['field']['current_progress']++; - $fields_to_delete_count = count(static::getFieldsToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete'))); + $fields_to_delete_count = count(static::getFieldStoragesToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete'))); if ($fields_to_delete_count == 0) { $context['finished'] = 1; } else { $context['finished'] = $context['sandbox']['field']['current_progress'] / $context['sandbox']['field']['steps_to_delete']; - $context['message'] = \Drupal::translation()->translate('Purging field @field_label', array('@field_label' => $field->label())); + $context['message'] = \Drupal::translation()->translate('Purging field @field_label', array('@field_label' => $field_storage->label())); } } @@ -73,7 +74,7 @@ protected static function initializeSandbox(array &$context, ConfigImporter $con $context['sandbox']['field']['extensions'] = $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension'); $context['sandbox']['field']['steps_to_delete'] = 0; - $fields = static::getFieldsToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete')); + $fields = static::getFieldStoragesToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete')); foreach ($fields as $field) { $row_count = \Drupal::entityManager()->getStorage($field->getTargetEntityTypeId()) ->countFieldData($field); @@ -108,41 +109,42 @@ protected static function initializeSandbox(array &$context, ConfigImporter $con * The configuration that will be deleted by the configuration * synchronization. * - * @return \Drupal\field\Entity\FieldConfig[] - * An array of fields that need purging before configuration can be + * @return \Drupal\field\Entity\FieldStorageConfig[] + * An array of field storages that need purging before configuration can be * synchronized. */ - public static function getFieldsToPurge(array $extensions, array $deletes) { + public static function getFieldStoragesToPurge(array $extensions, array $deletes) { $providers = array_keys($extensions['module']); $providers[] = 'Core'; - $fields_to_delete = array(); + $storages_to_delete = array(); // Gather fields that will be deleted during configuration synchronization // where the module that provides the field type is also being uninstalled. - $field_ids = array(); + $field_storage_ids = array(); foreach ($deletes as $config_name) { - if (strpos($config_name, 'field.field.') === 0) { - $field_ids[] = ConfigEntityStorage::getIDFromConfigName($config_name, 'field.field'); + $field_storage_config_prefix = \Drupal::entityManager()->getDefinition('field_storage_config')->getConfigPrefix(); + if (strpos($config_name, $field_storage_config_prefix . '.') === 0) { + $field_storage_ids[] = ConfigEntityStorage::getIDFromConfigName($config_name, $field_storage_config_prefix); } } - if (!empty($field_ids)) { - $fields = \Drupal::entityQuery('field_config') - ->condition('id', $field_ids, 'IN') + if (!empty($field_storage_ids)) { + $field_storages = \Drupal::entityQuery('field_storage_config') + ->condition('id', $field_storage_ids, 'IN') ->condition('module', $providers, 'NOT IN') ->execute(); - if (!empty($fields)) { - $fields_to_delete = entity_load_multiple('field_config', $fields); + if (!empty($field_storages)) { + $storages_to_delete = FieldStorageConfig::loadMultiple($field_storages); } } // Gather deleted fields from modules that are being uninstalled. - $fields = entity_load_multiple_by_properties('field_config', array('deleted' => TRUE, 'include_deleted' => TRUE)); - foreach ($fields as $field) { - if (!in_array($field->module, $providers)) { - $fields_to_delete[$field->id()] = $field; + $field_storages = entity_load_multiple_by_properties('field_storage_config', array('deleted' => TRUE, 'include_deleted' => TRUE)); + foreach ($field_storages as $field_storage) { + if (!in_array($field_storage->module, $providers)) { + $storages_to_delete[$field_storage->id()] = $field_storage; } } - return $fields_to_delete; + return $storages_to_delete; } } diff --git a/core/modules/field/src/Entity/FieldInstanceConfig.php b/core/modules/field/src/Entity/FieldInstanceConfig.php index 79830db..7a41fa2 100644 --- a/core/modules/field/src/Entity/FieldInstanceConfig.php +++ b/core/modules/field/src/Entity/FieldInstanceConfig.php @@ -14,7 +14,7 @@ use Drupal\Core\Field\FieldDefinition; use Drupal\Core\Field\TypedData\FieldItemDataDefinition; use Drupal\field\FieldException; -use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldInstanceConfigInterface; /** @@ -188,9 +188,9 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi /** * The field ConfigEntity object this is an instance of. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $fieldStorage; /** * Flag indicating whether the bundle name can be renamed or not. @@ -214,10 +214,11 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi * parameter as in this constructor. * * @param array $values - * An array of field instance properties, keyed by property name. The field - * this is an instance of can be specified either with: - * - field: the FieldConfigInterface object, - * or by referring to an existing field in the current configuration with: + * An array of field instance properties, keyed by property name. The + * storage associated to the instance can be specified either with: + * - field_storage: the FieldStorageConfigInterface object, + * or by referring to an existing field storage in the current configuration + * with: * - field_name: The field name. * - entity_type: The entity type. * Additionally, a 'bundle' property is required to indicate the entity @@ -228,28 +229,28 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi * @see entity_create() */ public function __construct(array $values, $entity_type = 'field_instance_config') { - // Allow either an injected FieldConfig object, or a field_name and + // Allow either an injected FieldStorageConfig object, or a field_name and // entity_type. - if (isset($values['field'])) { - if (!$values['field'] instanceof FieldConfigInterface) { - throw new FieldException('Attempt to create a configurable instance of a non-configurable field.'); + if (isset($values['field_storage'])) { + if (!$values['field_storage'] instanceof FieldStorageConfigInterface) { + throw new FieldException('Attempt to create a configurable field instance for a non-configurable field storage.'); } - $field = $values['field']; - $values['field_name'] = $field->getName(); - $values['entity_type'] = $field->getTargetEntityTypeId(); - $this->field = $field; + $field_storage = $values['field_storage']; + $values['field_name'] = $field_storage->getName(); + $values['entity_type'] = $field_storage->getTargetEntityTypeId(); + $this->fieldStorage = $field_storage; } else { if (empty($values['field_name'])) { - throw new FieldException('Attempt to create an instance of a field without a field_name.'); + throw new FieldException('Attempt to create a field instance without a field_name.'); } if (empty($values['entity_type'])) { - throw new FieldException(String::format('Attempt to create an instance of field @field_name without an entity_type.', array('@field_name' => $values['field_name']))); + throw new FieldException(String::format('Attempt to create a field instance @field_name without an entity_type.', array('@field_name' => $values['field_name']))); } } // 'bundle' is required in either case. if (empty($values['bundle'])) { - throw new FieldException(String::format('Attempt to create an instance of field @field_name without a bundle.', array('@field_name' => $values['field_name']))); + throw new FieldException(String::format('Attempt to create a field instance @field_name without a bundle.', array('@field_name' => $values['field_name']))); } // Discard the 'field_type' entry that is added in config records to ease @@ -297,8 +298,8 @@ public function toArray() { * {@inheritdoc} */ public function postCreate(EntityStorageInterface $storage) { - // Validate that we have a valid field for this instance. This throws an - // exception if the field is invalid. + // Validate that we have a valid storage for this instance. This throws an + // exception if the storage is invalid. $this->getFieldStorageDefinition(); // 'Label' defaults to the field name (mostly useful for field instances @@ -320,11 +321,11 @@ public function preSave(EntityStorageInterface $storage) { $entity_manager = \Drupal::entityManager(); $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); - $field = $this->getFieldStorageDefinition(); + $storage_definition = $this->getFieldStorageDefinition(); if ($this->isNew()) { // Set the default instance settings. - $this->settings += $field_type_manager->getDefaultInstanceSettings($field->type); + $this->settings += $field_type_manager->getDefaultInstanceSettings($storage_definition->type); // Notify the entity storage. $entity_manager->getStorage($this->entity_type)->onFieldDefinitionCreate($this); } @@ -336,11 +337,11 @@ public function preSave(EntityStorageInterface $storage) { if ($this->bundle != $this->original->bundle && empty($this->bundle_rename_allowed)) { throw new FieldException("Cannot change an existing instance's bundle."); } - if ($field->uuid() != $this->original->getFieldStorageDefinition()->uuid()) { - throw new FieldException("Cannot change an existing instance's field."); + if ($storage_definition->uuid() != $this->original->getFieldStorageDefinition()->uuid()) { + throw new FieldException("Cannot change an existing instance's storage."); } // Set the default instance settings. - $this->settings += $field_type_manager->getDefaultInstanceSettings($field->type); + $this->settings += $field_type_manager->getDefaultInstanceSettings($storage_definition->type); // Notify the entity storage. $entity_manager->getStorage($this->entity_type)->onFieldDefinitionUpdate($this, $this->original); } @@ -395,7 +396,7 @@ public static function preDelete(EntityStorageInterface $storage, array $instanc if (!$instance->deleted) { $config = $instance->toArray(); $config['deleted'] = TRUE; - $config['field_uuid'] = $instance->getFieldStorageDefinition()->uuid(); + $config['field_storage_uuid'] = $instance->getFieldStorageDefinition()->uuid(); $deleted_instances[$instance->uuid()] = $config; } } @@ -406,8 +407,6 @@ public static function preDelete(EntityStorageInterface $storage, array $instanc * {@inheritdoc} */ public static function postDelete(EntityStorageInterface $storage, array $instances) { - $field_storage = \Drupal::entityManager()->getStorage('field_config'); - // Clear the cache upfront, to refresh the results of getBundles(). \Drupal::entityManager()->clearCachedFieldDefinitions(); @@ -425,17 +424,17 @@ public static function postDelete(EntityStorageInterface $storage, array $instan return; } - // Delete fields that have no more instances. - $fields_to_delete = array(); + // Delete field storages that have no more instances. + $storages_to_delete = array(); foreach ($instances as $instance) { - $field = $instance->getFieldStorageDefinition(); - if (!$instance->deleted && empty($instance->noFieldDelete) && !$instance->isUninstalling() && count($field->getBundles()) == 0) { - // Key by field UUID to avoid deleting the same field twice. - $fields_to_delete[$field->uuid()] = $field; + $storage_definition = $instance->getFieldStorageDefinition(); + if (!$instance->deleted && empty($instance->noFieldDelete) && !$instance->isUninstalling() && count($storage_definition->getBundles()) == 0) { + // Key by field UUID to avoid deleting the same storage twice. + $storages_to_delete[$storage_definition->uuid()] = $storage_definition; } } - if ($fields_to_delete) { - $field_storage->delete($fields_to_delete); + if ($storages_to_delete) { + \Drupal::entityManager()->getStorage('field_storage_config')->delete($storages_to_delete); } // Cleanup entity displays. @@ -444,11 +443,11 @@ public static function postDelete(EntityStorageInterface $storage, array $instan if (!$instance->deleted) { $view_modes = \Drupal::entityManager()->getViewModeOptions($instance->entity_type, TRUE); foreach (array_keys($view_modes) as $mode) { - $displays_to_update['entity_view_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->field_name; + $displays_to_update['entity_view_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->getName(); } $form_modes = \Drupal::entityManager()->getFormModeOptions($instance->entity_type, TRUE); foreach (array_keys($form_modes) as $mode) { - $displays_to_update['entity_form_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->field_name; + $displays_to_update['entity_form_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->getName(); } } } @@ -466,18 +465,18 @@ public static function postDelete(EntityStorageInterface $storage, array $instan * {@inheritdoc} */ public function getFieldStorageDefinition() { - if (!$this->field) { - $fields = \Drupal::entityManager()->getFieldStorageDefinitions($this->entity_type); - if (!isset($fields[$this->field_name])) { - throw new FieldException(String::format('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); + if (!$this->fieldStorage) { + $storages = \Drupal::entityManager()->getFieldStorageDefinitions($this->entity_type); + if (!isset($storages[$this->field_name])) { + throw new FieldException(String::format('Attempt to create an instance @field_name while the storage does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); } - if (!$fields[$this->field_name] instanceof FieldConfigInterface) { - throw new FieldException(String::format('Attempt to create a configurable instance of non-configurable field @field_name.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); + if (!$storages[$this->field_name] instanceof FieldStorageConfigInterface) { + throw new FieldException(String::format('Attempt to create a configurable instance for a non-configurable storage @field_name.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); } - $this->field = $fields[$this->field_name]; + $this->fieldStorage = $storages[$this->field_name]; } - return $this->field; + return $this->fieldStorage; } /** @@ -522,7 +521,7 @@ protected function linkTemplates() { $link_templates = parent::linkTemplates(); if (\Drupal::moduleHandler()->moduleExists('field_ui')) { $link_templates['edit-form'] = 'field_ui.instance_edit_' . $this->entity_type; - $link_templates['field-settings-form'] = 'field_ui.field_edit_' . $this->entity_type; + $link_templates['storage-edit-form'] = 'field_ui.storage_edit_' . $this->entity_type; $link_templates['delete-form'] = 'field_ui.delete_' . $this->entity_type; if (isset($link_templates['drupal:config-translation-overview'])) { diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php similarity index 90% rename from core/modules/field/src/Entity/FieldConfig.php rename to core/modules/field/src/Entity/FieldStorageConfig.php index af025e3..2fd46c9 100644 --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field\Entity\FieldConfig. + * Contains \Drupal\field\Entity\FieldStorageConfig. */ namespace Drupal\field\Entity; @@ -13,25 +13,25 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\FieldException; -use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; /** - * Defines the Field entity. + * Defines the Field storage configuration entity. * * @ConfigEntityType( - * id = "field_config", + * id = "field_storage_config", * label = @Translation("Field"), * controllers = { - * "storage" = "Drupal\field\FieldConfigStorage" + * "storage" = "Drupal\field\FieldStorageConfigStorage" * }, - * config_prefix = "field", + * config_prefix = "storage", * entity_keys = { * "id" = "id", * "label" = "id" * } * ) */ -class FieldConfig extends ConfigEntityBase implements FieldConfigInterface { +class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigInterface { /** * The maximum length of the field name, in characters. @@ -181,7 +181,7 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface { protected $propertyDefinitions; /** - * Constructs a FieldConfig object. + * Constructs a FieldStorageConfig object. * * @param array $values * An array of field properties, keyed by property name. Most array @@ -194,24 +194,25 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface { * - type: required. * * In most cases, Field entities are created via - * entity_create('field_config', $values)), where $values is the same + * entity_create('field_storage_config', $values)), where $values is the same * parameter as in this constructor. * * @see entity_create() */ - public function __construct(array $values, $entity_type = 'field_config') { + public function __construct(array $values, $entity_type = 'field_storage_config') { // Check required properties. + // @todo update error messages... if (empty($values['name'])) { - throw new FieldException('Attempt to create an unnamed field.'); + throw new FieldException('Attempt to create an unnamed field storage.'); } if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['name'])) { - throw new FieldException(String::format('Attempt to create a field @field_name with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character', array('@field_name' => $values['name']))); + throw new FieldException(String::format('Attempt to create a field storage @field_name with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character', array('@field_name' => $values['name']))); } if (empty($values['type'])) { - throw new FieldException(String::format('Attempt to create field @field_name with no type.', array('@field_name' => $values['name']))); + throw new FieldException(String::format('Attempt to create a field storage @field_name with no type.', array('@field_name' => $values['name']))); } if (empty($values['entity_type'])) { - throw new FieldException(String::format('Attempt to create a field @field_name with no entity_type.', array('@field_name' => $values['name']))); + throw new FieldException(String::format('Attempt to create a field storage @field_name with no entity_type.', array('@field_name' => $values['name']))); } parent::__construct($values, $entity_type); @@ -263,12 +264,12 @@ protected function preSaveNew(EntityStorageInterface $storage) { // Assign the ID. $this->id = $this->id(); - // Field name cannot be longer than FieldConfig::NAME_MAX_LENGTH characters. + // Field name cannot be longer than FieldStorageConfig::NAME_MAX_LENGTH characters. // We use Unicode::strlen() because the DB layer assumes that column widths // are given in characters rather than bytes. if (Unicode::strlen($this->name) > static::NAME_MAX_LENGTH) { throw new FieldException(String::format( - 'Attempt to create a field with an ID longer than @max characters: %name', array( + 'Attempt to create a field storage with an name longer than @max characters: %name', array( '@max' => static::NAME_MAX_LENGTH, '%name' => $this->name, ) @@ -278,13 +279,13 @@ protected function preSaveNew(EntityStorageInterface $storage) { // Disallow reserved field names. $disallowed_field_names = array_keys($entity_manager->getBaseFieldDefinitions($this->entity_type)); if (in_array($this->name, $disallowed_field_names)) { - throw new FieldException(String::format('Attempt to create field %name which is reserved by entity type %type.', array('%name' => $this->name, '%type' => $this->entity_type))); + throw new FieldException(String::format('Attempt to create field storage %name which is reserved by entity type %type.', array('%name' => $this->name, '%type' => $this->entity_type))); } // Check that the field type is known. $field_type = $field_type_manager->getDefinition($this->type, FALSE); if (!$field_type) { - throw new FieldException(String::format('Attempt to create a field of unknown type %type.', array('%type' => $this->type))); + throw new FieldException(String::format('Attempt to create a field storage of unknown type %type.', array('%type' => $this->type))); } $this->module = $field_type['provider']; @@ -322,10 +323,10 @@ protected function preSaveUpdated(EntityStorageInterface $storage) { // Some updates are always disallowed. if ($this->type != $this->original->type) { - throw new FieldException("Cannot change an existing field's type."); + throw new FieldException("Cannot change the field type for an existing field storage."); } if ($this->entity_type != $this->original->entity_type) { - throw new FieldException("Cannot change an existing field's entity_type."); + throw new FieldException("Cannot change the entity type for an existing field storage."); } // Make sure all settings are present, so that a complete field @@ -333,8 +334,8 @@ protected function preSaveUpdated(EntityStorageInterface $storage) { $this->settings += $field_type_manager->getDefaultSettings($this->type); // See if any module forbids the update by throwing an exception. This - // invokes hook_field_config_update_forbid(). - $module_handler->invokeAll('field_config_update_forbid', array($this, $this->original)); + // invokes hook_field_storage_config_update_forbid(). + $module_handler->invokeAll('field_storage_config_update_forbid', array($this, $this->original)); // Notify the storage. The controller can reject the definition // update as invalid by raising an exception, which stops execution before @@ -388,17 +389,17 @@ public static function preDelete(EntityStorageInterface $storage, array $fields) // Keep the field definitions in the state storage so we can use them later // during field_purge_batch(). - $deleted_fields = $state->get('field.field.deleted') ?: array(); + $deleted_storages = $state->get('field.storage.deleted') ?: array(); foreach ($fields as $field) { if (!$field->deleted) { $config = $field->toArray(); $config['deleted'] = TRUE; $config['bundles'] = $field->getBundles(); - $deleted_fields[$field->uuid()] = $config; + $deleted_storages[$field->uuid()] = $config; } } - $state->set('field.field.deleted', $deleted_fields); + $state->set('field.storage.deleted', $deleted_storages); } /** @@ -739,7 +740,7 @@ protected function getFieldItemClass() { * otherwise NULL. */ public static function loadByName($entity_type_id, $field_name) { - return \Drupal::entityManager()->getStorage('field_config')->load($entity_type_id . '.' . $field_name); + return \Drupal::entityManager()->getStorage('field_storage_config')->load($entity_type_id . '.' . $field_name); } } diff --git a/core/modules/field/src/FieldConfigInterface.php b/core/modules/field/src/FieldConfigInterface.php deleted file mode 100644 index c6575ec..0000000 --- a/core/modules/field/src/FieldConfigInterface.php +++ /dev/null @@ -1,34 +0,0 @@ -state->get('field.instance.deleted') ?: array(); - $deleted_fields = $this->state->get('field.field.deleted') ?: array(); + $deleted_storages = $this->state->get('field.storage.deleted') ?: array(); foreach ($deleted_instances as $id => $config) { // If the field itself is deleted, inject it directly in the instance. - if (isset($deleted_fields[$config['field_uuid']])) { - $config['field'] = $this->entityManager->getStorage('field_config')->create($deleted_fields[$config['field_uuid']]); + if (isset($deleted_storages[$config['field_storage_uuid']])) { + $config['field_storage'] = $this->entityManager->getStorage('field_storage_config')->create($deleted_storages[$config['field_storage_uuid']]); } $instances[$id] = $this->create($config); } @@ -149,7 +147,7 @@ public function loadByProperties(array $conditions = array()) { break; case 'field_id': - case 'field_uuid': + case 'field_storage_uuid': $checked_value = $field->uuid(); break; diff --git a/core/modules/field/src/FieldStorageConfigInterface.php b/core/modules/field/src/FieldStorageConfigInterface.php new file mode 100644 index 0000000..4f4eb04 --- /dev/null +++ b/core/modules/field/src/FieldStorageConfigInterface.php @@ -0,0 +1,34 @@ +loadMultiple(array($id)); + $storages = $this->loadMultiple(array($id)); } else { - // No specific ID, we need to examine all existing fields. - $fields = $this->loadMultiple(); + // No specific ID, we need to examine all existing storages. + $storages = $this->loadMultiple(); } } - // Merge deleted fields (stored in state) if needed. + // Merge deleted field storages (living in state) if needed. if ($include_deleted || !empty($conditions['deleted'])) { - $deleted_fields = $this->state->get('field.field.deleted') ?: array(); - foreach ($deleted_fields as $id => $config) { - $fields[$id] = $this->create($config); + $deleted_storages = $this->state->get('field.storage.deleted') ?: array(); + foreach ($deleted_storages as $id => $config) { + $storages[$id] = $this->create($config); } } // Collect matching fields. - $matching_fields = array(); - foreach ($fields as $field) { + $matches = array(); + foreach ($storages as $field) { foreach ($conditions as $key => $value) { // Extract the actual value against which the condition is checked. switch ($key) { @@ -150,10 +148,10 @@ public function loadByProperties(array $conditions = array()) { // When returning deleted fields, key the results by UUID since they can // include several fields with the same ID. $key = $include_deleted ? $field->uuid() : $field->id(); - $matching_fields[$key] = $field; + $matches[$key] = $field; } - return $matching_fields; + return $matches; } } diff --git a/core/modules/field/src/FieldStorageConfigUpdateForbiddenException.php b/core/modules/field/src/FieldStorageConfigUpdateForbiddenException.php new file mode 100644 index 0000000..ef709ba --- /dev/null +++ b/core/modules/field/src/FieldStorageConfigUpdateForbiddenException.php @@ -0,0 +1,13 @@ +fieldDefinition) { - $field_config = $this->getFieldConfig(); - $this->fieldDefinition = FieldDefinition::createFromFieldStorageDefinition($field_config); + $field_storage_config = $this->getFieldStorageConfig(); + $this->fieldDefinition = FieldDefinition::createFromFieldStorageDefinition($field_storage_config); } return $this->fieldDefinition; } @@ -161,14 +163,14 @@ protected function getFieldDefinition() { /** * Gets the field configuration. * - * @return \Drupal\field\FieldConfigInterface + * @return \Drupal\field\FieldStorageConfigInterface */ - protected function getFieldConfig() { - if (!$this->fieldConfig) { + protected function getFieldStorageConfig() { + if (!$this->fieldStorageConfig) { $field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']); - $this->fieldConfig = $field_storage_definitions[$this->definition['field_name']]; + $this->fieldStorageConfig = $field_storage_definitions[$this->definition['field_name']]; } - return $this->fieldConfig; + return $this->fieldStorageConfig; } /** @@ -926,8 +928,8 @@ function field_langcode(EntityInterface $entity) { * {@inheritdoc} */ public function getDependencies() { - // Add the module providing the configured field as a dependency. - return array('entity' => array($this->getFieldConfig()->getConfigDependencyName())); + // Add the module providing the configured field storage as a dependency. + return array('entity' => array($this->getFieldStorageConfig()->getConfigDependencyName())); } diff --git a/core/modules/field/src/Tests/BulkDeleteTest.php b/core/modules/field/src/Tests/BulkDeleteTest.php index 8e96eab..c297e58 100644 --- a/core/modules/field/src/Tests/BulkDeleteTest.php +++ b/core/modules/field/src/Tests/BulkDeleteTest.php @@ -10,8 +10,6 @@ use Drupal\Core\Entity\ContentEntityDatabaseStorage; use Drupal\Core\Entity\EntityInterface; use Drupal\field\Entity\FieldInstanceConfig; -use Drupal\field\FieldConfigInterface; - /** * Unit test class for field bulk delete and batch purge functionality. @@ -23,7 +21,7 @@ class BulkDeleteTest extends FieldUnitTestBase { * * @var array */ - protected $fields; + protected $fieldStorages; /** * The entities to use in this test. @@ -103,7 +101,7 @@ function checkHooksInvocations($expected_hooks, $actual_hooks) { function setUp() { parent::setUp(); - $this->fields = array(); + $this->fieldStorages = array(); $this->entities = array(); $this->entities_by_bundles = array(); @@ -114,36 +112,36 @@ function setUp() { } // Create two fields. - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'bf_1', 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 1 )); - $field->save(); - $this->fields[] = $field; - $field = entity_create('field_config', array( + $field_storage->save(); + $this->fieldStorages[] = $field_storage; + $field_storage = entity_create('field_storage_config', array( 'name' => 'bf_2', 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4 )); - $field->save(); - $this->fields[] = $field; + $field_storage->save(); + $this->fieldStorages[] = $field_storage; // For each bundle, create an instance of each field, and 10 // entities with values for each field. foreach ($this->bundles as $bundle) { - foreach ($this->fields as $field) { + foreach ($this->fieldStorages as $field_storage) { entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => $bundle, ))->save(); } for ($i = 0; $i < 10; $i++) { $entity = entity_create($this->entity_type, array('type' => $bundle)); - foreach ($this->fields as $field) { - $entity->{$field->getName()}->setValue($this->_generateTestFieldValues($field->getCardinality())); + foreach ($this->fieldStorages as $field_storage) { + $entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality())); } $entity->save(); } @@ -165,8 +163,8 @@ function setUp() { */ function testDeleteFieldInstance() { $bundle = reset($this->bundles); - $field = reset($this->fields); - $field_name = $field->name; + $field_storage = reset($this->fieldStorages); + $field_name = $field_storage->name; $factory = \Drupal::service('entity.query'); // There are 10 entities of this bundle. @@ -176,24 +174,24 @@ function testDeleteFieldInstance() { $this->assertEqual(count($found), 10, 'Correct number of entities found before deleting'); // Delete the instance. - $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field_storage->name); $instance->delete(); // The instance still exists, deleted. - $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); $instance = $instances[$instance->uuid()]; $this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle'); // Check that the actual stored content did not change during delete. - $schema = ContentEntityDatabaseStorage::_fieldSqlSchema($field); - $table = ContentEntityDatabaseStorage::_fieldTableName($field); - $column = ContentEntityDatabaseStorage::_fieldColumnName($field, 'value'); + $schema = ContentEntityDatabaseStorage::_fieldSqlSchema($field_storage); + $table = ContentEntityDatabaseStorage::_fieldTableName($field_storage); + $column = ContentEntityDatabaseStorage::_fieldColumnName($field_storage, 'value'); $result = db_select($table, 't') ->fields('t', array_keys($schema[$table]['fields'])) ->execute(); foreach ($result as $row) { - $this->assertEqual($this->entities[$row->entity_id]->{$field->name}->value, $row->$column); + $this->assertEqual($this->entities[$row->entity_id]->{$field_storage->name}->value, $row->$column); } // There are 0 entities of this bundle with non-deleted data. @@ -223,10 +221,10 @@ function testPurgeInstance() { field_test_memorize(); $bundle = reset($this->bundles); - $field = reset($this->fields); + $field_storage = reset($this->fieldStorages); // Delete the instance. - $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field_storage->name); $instance->delete(); // No field hooks were called. @@ -241,7 +239,7 @@ function testPurgeInstance() { // There are $count deleted entities left. $found = \Drupal::entityQuery('entity_test') ->condition('type', $bundle) - ->condition($field->name . '.deleted', 1) + ->condition($field_storage->name . '.deleted', 1) ->execute(); $this->assertEqual(count($found), $count, 'Correct number of entities found after purging 2'); } @@ -258,34 +256,34 @@ function testPurgeInstance() { $this->checkHooksInvocations($hooks, $actual_hooks); // The instance still exists, deleted. - $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); // Purge the instance. field_purge_batch($batch_size); // The instance is gone. - $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 0, 'The instance is gone'); - // The field still exists, not deleted, because it has a second instance. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); - $this->assertTrue(isset($fields[$field->uuid()]), 'The field exists and is not deleted'); + // The field storage still exists, not deleted, because it has a second instance. + $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $this->assertTrue(isset($storages[$field_storage->uuid()]), 'The field storage exists and is not deleted'); } /** - * Verify that fields are preserved and purged correctly as multiple + * Verify that field storages are preserved and purged correctly as multiple * instances are deleted and purged. */ - function testPurgeField() { + function testPurgeFieldStorage() { // Start recording hook invocations. field_test_memorize(); - $field = reset($this->fields); + $field_storage = reset($this->fieldStorages); // Delete the first instance. $bundle = reset($this->bundles); - $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field_storage->name); $instance->delete(); // Assert that FieldItemInterface::delete() was not called yet. @@ -316,13 +314,13 @@ function testPurgeField() { // The instance is gone. $instances = entity_load_multiple_by_properties('field_instance_config', array('uuid' => $instance->uuid(), 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 0, 'The instance is purged.'); - // The field still exists, not deleted. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); - $this->assertTrue(isset($fields[$field->uuid()]) && !$fields[$field->uuid()]->deleted, 'The field exists and is not deleted'); + // The field storage still exists, not deleted. + $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $this->assertTrue(isset($storages[$field_storage->uuid()]) && !$storages[$field_storage->uuid()]->deleted, 'The field storage exists and is not deleted'); // Delete the second instance. $bundle = next($this->bundles); - $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field->name); + $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field_storage->name); $instance->delete(); // Assert that FieldItemInterface::delete() was not called yet. @@ -341,20 +339,20 @@ function testPurgeField() { } $this->checkHooksInvocations($hooks, $actual_hooks); - // The field and instance still exist, deleted. + // The field storage and instance still exist, deleted. $instances = entity_load_multiple_by_properties('field_instance_config', array('uuid' => $instance->uuid(), 'include_deleted' => TRUE)); $this->assertTrue(isset($instances[$instance->uuid()]) && $instances[$instance->uuid()]->deleted, 'The instance exists and is deleted'); - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); - $this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->deleted, 'The field exists and is deleted'); + $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $this->assertTrue(isset($storages[$field_storage->uuid()]) && $storages[$field_storage->uuid()]->deleted, 'The field storage exists and is deleted'); - // Purge again to purge the instance and the field. + // Purge again to purge the instance and the field storage. field_purge_batch(0); - // The field and instance are gone. + // The field storage and instance are gone. $instances = entity_load_multiple_by_properties('field_instance_config', array('uuid' => $instance->uuid(), 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 0, 'The instance is purged.'); - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); - $this->assertEqual(count($fields), 0, 'The field is purged.'); + $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $this->assertEqual(count($storages), 0, 'The field storage is purged.'); } } diff --git a/core/modules/field/src/Tests/CrudTest.php b/core/modules/field/src/Tests/CrudTest.php index 6a16101..9c7015b 100644 --- a/core/modules/field/src/Tests/CrudTest.php +++ b/core/modules/field/src/Tests/CrudTest.php @@ -9,11 +9,11 @@ use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\FieldException; /** - * Tests field CRUD operations. + * Tests field storage CRUD operations. */ class CrudTest extends FieldUnitTestBase { @@ -26,8 +26,8 @@ class CrudTest extends FieldUnitTestBase { public static function getInfo() { return array( - 'name' => 'Field CRUD tests', - 'description' => 'Test field create, read, update, and delete.', + 'name' => 'Field storage CRUD tests', + 'description' => 'Test field storage create, read, update, and delete.', 'group' => 'Field API', ); } @@ -38,42 +38,42 @@ public static function getInfo() { // defer actual $field comparison to a helper function, used for the two cases above /** - * Test the creation of a field. + * Test the creation of a field storage. */ - function testCreateField() { - $field_definition = array( + function testCreate() { + $field_storage_definition = array( 'name' => 'field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', ); field_test_memorize(); - $field = entity_create('field_config', $field_definition); - $field->save(); + $field_storage = entity_create('field_storage_config', $field_storage_definition); + $field_storage->save(); $mem = field_test_memorize(); - $this->assertIdentical($mem['field_test_field_config_create'][0][0]->getName(), $field_definition['name'], 'hook_entity_create() called with correct arguments.'); - $this->assertIdentical($mem['field_test_field_config_create'][0][0]->getType(), $field_definition['type'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_storage_config_create'][0][0]->getName(), $field_storage_definition['name'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_storage_config_create'][0][0]->getType(), $field_storage_definition['type'], 'hook_entity_create() called with correct arguments.'); // Read the configuration. Check against raw configuration data rather than // the loaded ConfigEntity, to be sure we check that the defaults are // applied on write. - $field_config = \Drupal::config('field.field.' . $field->id())->get(); + $field_storage_config = \Drupal::config('field.storage.' . $field_storage->id())->get(); // Ensure that basic properties are preserved. - $this->assertEqual($field_config['name'], $field_definition['name'], 'The field name is properly saved.'); - $this->assertEqual($field_config['entity_type'], $field_definition['entity_type'], 'The field entity type is properly saved.'); - $this->assertEqual($field_config['id'], $field_definition['entity_type'] . '.' . $field_definition['name'], 'The field id is properly saved.'); - $this->assertEqual($field_config['type'], $field_definition['type'], 'The field type is properly saved.'); + $this->assertEqual($field_storage_config['name'], $field_storage_definition['name'], 'The field name is properly saved.'); + $this->assertEqual($field_storage_config['entity_type'], $field_storage_definition['entity_type'], 'The field entity type is properly saved.'); + $this->assertEqual($field_storage_config['id'], $field_storage_definition['entity_type'] . '.' . $field_storage_definition['name'], 'The field id is properly saved.'); + $this->assertEqual($field_storage_config['type'], $field_storage_definition['type'], 'The field type is properly saved.'); // Ensure that cardinality defaults to 1. - $this->assertEqual($field_config['cardinality'], 1, 'Cardinality defaults to 1.'); + $this->assertEqual($field_storage_config['cardinality'], 1, 'Cardinality defaults to 1.'); // Ensure that default settings are present. $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); - $this->assertEqual($field_config['settings'], $field_type_manager->getDefaultSettings($field_definition['type']), 'Default field settings have been written.'); + $this->assertEqual($field_storage_config['settings'], $field_type_manager->getDefaultSettings($field_storage_definition['type']), 'Default field settings have been written.'); // Guarantee that the name is unique. try { - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail(t('Cannot create two fields with the same name.')); } catch (EntityStorageException $e) { @@ -82,11 +82,11 @@ function testCreateField() { // Check that field type is required. try { - $field_definition = array( + $field_storage_definition = array( 'name' => 'field_1', 'entity_type' => 'entity_type', ); - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail(t('Cannot create a field with no type.')); } catch (FieldException $e) { @@ -95,11 +95,11 @@ function testCreateField() { // Check that field name is required. try { - $field_definition = array( + $field_storage_definition = array( 'type' => 'test_field', 'entity_type' => 'entity_test', ); - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail(t('Cannot create an unnamed field.')); } catch (FieldException $e) { @@ -107,11 +107,11 @@ function testCreateField() { } // Check that entity type is required. try { - $field_definition = array( + $field_storage_definition = array( 'name' => 'test_field', 'type' => 'test_field' ); - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail('Cannot create a field without an entity type.'); } catch (FieldException $e) { @@ -120,12 +120,12 @@ function testCreateField() { // Check that field name must start with a letter or _. try { - $field_definition = array( + $field_storage_definition = array( 'name' => '2field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail(t('Cannot create a field with a name starting with a digit.')); } catch (FieldException $e) { @@ -134,12 +134,12 @@ function testCreateField() { // Check that field name must only contain lowercase alphanumeric or _. try { - $field_definition = array( + $field_storage_definition = array( 'name' => 'field#_3', 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail(t('Cannot create a field with a name containing an illegal character.')); } catch (FieldException $e) { @@ -148,12 +148,12 @@ function testCreateField() { // Check that field name cannot be longer than 32 characters long. try { - $field_definition = array( + $field_storage_definition = array( 'name' => '_12345678901234567890123456789012', 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail(t('Cannot create a field with a name longer than 32 characters.')); } catch (FieldException $e) { @@ -163,12 +163,12 @@ function testCreateField() { // Check that field name can not be an entity key. // "id" is known as an entity key from the "entity_test" type. try { - $field_definition = array( + $field_storage_definition = array( 'type' => 'test_field', 'name' => 'id', 'entity_type' => 'entity_test', ); - entity_create('field_config', $field_definition)->save(); + entity_create('field_storage_config', $field_storage_definition)->save(); $this->fail(t('Cannot create a field bearing the name of an entity key.')); } catch (FieldException $e) { @@ -177,50 +177,50 @@ function testCreateField() { } /** - * Tests that an explicit schema can be provided on creation of a field. + * Tests that an explicit schema can be provided on creation. * - * This behavior is needed to allow field creation within updates, since - * plugin classes (and thus the field type schema) cannot be accessed. + * This behavior is needed to allow field storage creation within updates, + * since plugin classes (and thus the field type schema) cannot be accessed. */ - function testCreateFieldWithExplicitSchema() { - $field_definition = array( + function testCreateWithExplicitSchema() { + $schema = array( + 'dummy' => 'foobar' + ); + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', - 'schema' => array( - 'dummy' => 'foobar' - ), - ); - $field = entity_create('field_config', $field_definition); - $this->assertEqual($field->getSchema(), $field_definition['schema']); + 'schema' => $schema, + )); + $this->assertEqual($field_storage->getSchema(), $schema); } /** - * Tests reading field definitions. + * Tests reading field storage definitions. */ - function testReadFields() { - $field_definition = array( + function testRead() { + $field_storage_definition = array( 'name' => 'field_1', 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $field = entity_create('field_config', $field_definition); - $field->save(); - $id = $field->id(); + $field_storage = entity_create('field_storage_config', $field_storage_definition); + $field_storage->save(); + $id = $field_storage->id(); // Check that 'single column' criteria works. - $fields = entity_load_multiple_by_properties('field_config', array('field_name' => $field_definition['name'])); + $fields = entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['name'])); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); // Check that 'multi column' criteria works. - $fields = entity_load_multiple_by_properties('field_config', array('field_name' => $field_definition['name'], 'type' => $field_definition['type'])); + $fields = entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['name'], 'type' => $field_storage_definition['type'])); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); - $fields = entity_load_multiple_by_properties('field_config', array('field_name' => $field_definition['name'], 'type' => 'foo')); + $fields = entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['name'], 'type' => 'foo')); $this->assertTrue(empty($fields), 'No field was found.'); // Create an instance of the field. $instance_definition = array( - 'field_name' => $field_definition['name'], + 'field_name' => $field_storage_definition['name'], 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); @@ -230,60 +230,57 @@ function testReadFields() { /** * Test creation of indexes on data column. */ - function testFieldIndexes() { + function testIndexes() { // Check that indexes specified by the field type are used by default. - $field_definition = array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_1', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); - $field = entity_create('field_config', $field_definition); - $field->save(); - $field = entity_load('field_config', $field->id()); - $schema = $field->getSchema(); + )); + $field_storage->save(); + $field_storage = entity_load('field_storage_config', $field_storage->id()); + $schema = $field_storage->getSchema(); $expected_indexes = array('value' => array('value')); $this->assertEqual($schema['indexes'], $expected_indexes, 'Field type indexes saved by default'); // Check that indexes specified by the field definition override the field // type indexes. - $field_definition = array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', 'indexes' => array( 'value' => array(), ), - ); - $field = entity_create('field_config', $field_definition); - $field->save(); - $field = entity_load('field_config', $field->id()); - $schema = $field->getSchema(); + )); + $field_storage->save(); + $field_storage = entity_load('field_storage_config', $field_storage->id()); + $schema = $field_storage->getSchema(); $expected_indexes = array('value' => array()); $this->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes override field type indexes'); // Check that indexes specified by the field definition add to the field // type indexes. - $field_definition = array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_3', 'entity_type' => 'entity_test', 'type' => 'test_field', 'indexes' => array( 'value_2' => array('value'), ), - ); - $field = entity_create('field_config', $field_definition); - $field->save(); - $id = $field->id(); - $field = entity_load('field_config', $id); - $schema = $field->getSchema(); + )); + $field_storage->save(); + $id = $field_storage->id(); + $field_storage = entity_load('field_storage_config', $id); + $schema = $field_storage->getSchema(); $expected_indexes = array('value' => array('value'), 'value_2' => array('value')); $this->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes are merged with field type indexes'); } /** - * Test the deletion of a field. + * Test the deletion of a field storage. */ - function testDeleteField() { + function testDelete() { // TODO: Also test deletion of the data stored in the field ? // Create two fields (so we can test that only one is deleted). @@ -292,13 +289,13 @@ function testDeleteField() { 'type' => 'test_field', 'entity_type' => 'entity_test', ); - entity_create('field_config', $this->field)->save(); + entity_create('field_storage_config', $this->field)->save(); $this->another_field = array( 'name' => 'field_2', 'type' => 'test_field', 'entity_type' => 'entity_test', ); - entity_create('field_config', $this->another_field)->save(); + entity_create('field_storage_config', $this->another_field)->save(); // Create instances for each. $this->instance_definition = array( @@ -312,14 +309,14 @@ function testDeleteField() { entity_create('field_instance_config', $another_instance_definition)->save(); // Test that the first field is not deleted, and then delete it. - $field = current(entity_load_multiple_by_properties('field_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); - $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); - FieldConfig::loadByName('entity_test', $this->field['name'])->delete(); + $field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); + $this->assertTrue(!empty($field_storage) && empty($field_storage->deleted), 'A new field is not marked for deletion.'); + FieldStorageConfig::loadByName('entity_test', $this->field['name'])->delete(); // Make sure that the field is marked as deleted when it is specifically // loaded. - $field = current(entity_load_multiple_by_properties('field_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); - $this->assertTrue(!empty($field->deleted), 'A deleted field is marked for deletion.'); + $field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); + $this->assertTrue(!empty($field_storage->deleted), 'A deleted field is marked for deletion.'); // Make sure that this field's instance is marked as deleted when it is // specifically loaded. @@ -327,53 +324,52 @@ function testDeleteField() { $this->assertTrue(!empty($instance->deleted), 'An instance for a deleted field is marked for deletion.'); // Try to load the field normally and make sure it does not show up. - $field = entity_load('field_config', 'entity_test.' . $this->field['name']); - $this->assertTrue(empty($field), 'A deleted field is not loaded by default.'); + $field_storage = entity_load('field_storage_config', 'entity_test.' . $this->field['name']); + $this->assertTrue(empty($field_storage), 'A deleted field is not loaded by default.'); // Try to load the instance normally and make sure it does not show up. $instance = entity_load('field_instance_config', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); $this->assertTrue(empty($instance), 'An instance for a deleted field is not loaded by default.'); // Make sure the other field (and its field instance) are not deleted. - $another_field = entity_load('field_config', 'entity_test.' . $this->another_field['name']); - $this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.'); + $another_field_storage = entity_load('field_storage_config', 'entity_test.' . $this->another_field['name']); + $this->assertTrue(!empty($another_field_storage) && empty($another_field_storage->deleted), 'A non-deleted field is not marked for deletion.'); $another_instance = entity_load('field_instance_config', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']); $this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'An instance of a non-deleted field is not marked for deletion.'); // Try to create a new field the same name as a deleted field and // write data into it. - entity_create('field_config', $this->field)->save(); + entity_create('field_storage_config', $this->field)->save(); entity_create('field_instance_config', $this->instance_definition)->save(); - $field = entity_load('field_config', 'entity_test.' . $this->field['name']); - $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field with a previously used name is created.'); + $field_storage = entity_load('field_storage_config', 'entity_test.' . $this->field['name']); + $this->assertTrue(!empty($field_storage) && empty($field_storage->deleted), 'A new field with a previously used name is created.'); $instance = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name'] ); $this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new instance for a previously used field name is created.'); // Save an entity with data for the field $entity = entity_create('entity_test'); $values[0]['value'] = mt_rand(1, 127); - $entity->{$field->getName()}->value = $values[0]['value']; + $entity->{$field_storage->getName()}->value = $values[0]['value']; $entity = $this->entitySaveReload($entity); // Verify the field is present on load - $this->assertIdentical(count($entity->{$field->getName()}), count($values), "Data in previously deleted field saves and loads correctly"); + $this->assertIdentical(count($entity->{$field_storage->getName()}), count($values), "Data in previously deleted field saves and loads correctly"); foreach ($values as $delta => $value) { - $this->assertEqual($entity->{$field->getName()}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly"); + $this->assertEqual($entity->{$field_storage->getName()}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly"); } } function testUpdateFieldType() { - $field_definition = array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_type', 'entity_type' => 'entity_test', 'type' => 'decimal', - ); - $field = entity_create('field_config', $field_definition); - $field->save(); + )); + $field_storage->save(); try { - $field->type = 'integer'; - $field->save(); + $field_storage->type = 'integer'; + $field_storage->save(); $this->fail(t('Cannot update a field to a different type.')); } catch (FieldException $e) { @@ -382,22 +378,22 @@ function testUpdateFieldType() { } /** - * Test updating a field. + * Test updating a field storage. */ - function testUpdateField() { + function testUpdate() { // Create a field with a defined cardinality, so that we can ensure it's // respected. Since cardinality enforcement is consistent across database // systems, it makes a good test case. $cardinality = 4; - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_update', 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => $cardinality, )); - $field->save(); + $field_storage->save(); $instance = entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', )); @@ -412,22 +408,22 @@ function testUpdateField() { } // Load back and assert there are $cardinality number of values. $entity = $this->entitySaveReload($entity); - $this->assertEqual(count($entity->field_update), $field->cardinality); + $this->assertEqual(count($entity->field_update), $field_storage->cardinality); // Now check the values themselves. for ($delta = 0; $delta < $cardinality; $delta++) { $this->assertEqual($entity->field_update[$delta]->value, $delta + 1); } // Increase $cardinality and set the field cardinality to the new value. - $field->cardinality = ++$cardinality; - $field->save(); + $field_storage->cardinality = ++$cardinality; + $field_storage->save(); } while ($cardinality < 6); } /** * Test field type modules forbidding an update. */ - function testUpdateFieldForbid() { - $field = entity_create('field_config', array( + function testUpdateForbid() { + $field_storage = entity_create('field_storage_config', array( 'name' => 'forbidden', 'entity_type' => 'entity_test', 'type' => 'test_field', @@ -435,18 +431,18 @@ function testUpdateFieldForbid() { 'changeable' => 0, 'unchangeable' => 0 ))); - $field->save(); - $field->settings['changeable']++; + $field_storage->save(); + $field_storage->settings['changeable']++; try { - $field->save(); + $field_storage->save(); $this->pass(t("A changeable setting can be updated.")); } catch (FieldStorageDefinitionUpdateForbiddenException $e) { $this->fail(t("An unchangeable setting cannot be updated.")); } - $field->settings['unchangeable']++; + $field_storage->settings['unchangeable']++; try { - $field->save(); + $field_storage->save(); $this->fail(t("An unchangeable setting can be updated.")); } catch (FieldStorageDefinitionUpdateForbiddenException $e) { diff --git a/core/modules/field/src/Tests/DisplayApiTest.php b/core/modules/field/src/Tests/DisplayApiTest.php index 9a9ed1e..56c4dc4 100644 --- a/core/modules/field/src/Tests/DisplayApiTest.php +++ b/core/modules/field/src/Tests/DisplayApiTest.php @@ -72,7 +72,7 @@ function setUp() { $this->label = $this->randomName(); $this->cardinality = 4; - $field = array( + $field_storage = array( 'name' => $this->field_name, 'entity_type' => 'entity_test', 'type' => 'test_field', @@ -100,7 +100,7 @@ function setUp() { ), ); - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $instance)->save(); // Create a display for the default view mode. entity_get_display($instance['entity_type'], $instance['bundle'], 'default') diff --git a/core/modules/field/src/Tests/Email/EmailFieldTest.php b/core/modules/field/src/Tests/Email/EmailFieldTest.php index e01d129..b6762b3 100644 --- a/core/modules/field/src/Tests/Email/EmailFieldTest.php +++ b/core/modules/field/src/Tests/Email/EmailFieldTest.php @@ -22,11 +22,11 @@ class EmailFieldTest extends WebTestBase { public static $modules = array('node', 'entity_test', 'field_ui'); /** - * A field to use in this test class. + * A field storage to use in this test class. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $fieldStorage; /** * The instance used in this test class. @@ -60,14 +60,14 @@ function setUp() { function testEmailField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomName()); - $this->field = entity_create('field_config', array( + $this->fieldStorage = entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'email', )); - $this->field->save(); + $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', )); $this->instance->save(); diff --git a/core/modules/field/src/Tests/Email/EmailItemTest.php b/core/modules/field/src/Tests/Email/EmailItemTest.php index dfeab31..0312af6 100644 --- a/core/modules/field/src/Tests/Email/EmailItemTest.php +++ b/core/modules/field/src/Tests/Email/EmailItemTest.php @@ -35,7 +35,7 @@ public function setUp() { parent::setUp(); // Create an email field and instance for validation. - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => 'field_email', 'entity_type' => 'entity_test', 'type' => 'email', diff --git a/core/modules/field/src/Tests/FieldAccessTest.php b/core/modules/field/src/Tests/FieldAccessTest.php index 59b0cba..9b59c09 100644 --- a/core/modules/field/src/Tests/FieldAccessTest.php +++ b/core/modules/field/src/Tests/FieldAccessTest.php @@ -51,14 +51,14 @@ function setUp() { $content_type_info = $this->drupalCreateContentType(); $content_type = $content_type_info->type; - $field = array( + $field_storage = array( 'name' => 'test_view_field', 'entity_type' => 'node', 'type' => 'text', ); - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); $instance = array( - 'field_name' => $field['name'], + 'field_name' => $field_storage['name'], 'entity_type' => 'node', 'bundle' => $content_type, ); @@ -67,7 +67,7 @@ function setUp() { // Assign display properties for the 'default' and 'teaser' view modes. foreach (array('default', 'teaser') as $view_mode) { entity_get_display('node', $content_type, $view_mode) - ->setComponent($field['name']) + ->setComponent($field_storage['name']) ->save(); } diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php index 73a3b1e..4a29ce0 100644 --- a/core/modules/field/src/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php @@ -54,9 +54,9 @@ function testEntityDisplayBuild() { $entity_init = entity_create($entity_type); // Populate values to be displayed. - $values = $this->_generateTestFieldValues($this->field->getCardinality()); + $values = $this->_generateTestFieldValues($this->field_storage->getCardinality()); $entity_init->{$this->field_name}->setValue($values); - $values_2 = $this->_generateTestFieldValues($this->field_2->getCardinality()); + $values_2 = $this->_generateTestFieldValues($this->field_storage_2->getCardinality()); $entity_init->{$this->field_name_2}->setValue($values_2); // Simple formatter, label displayed. @@ -71,7 +71,7 @@ function testEntityDisplayBuild() { 'test_formatter_setting' => $formatter_setting, ), ); - $display->setComponent($this->field->getName(), $display_options); + $display->setComponent($this->field_name, $display_options); $formatter_setting_2 = $this->randomName(); $display_options_2 = array( @@ -81,7 +81,7 @@ function testEntityDisplayBuild() { 'test_formatter_setting' => $formatter_setting_2, ), ); - $display->setComponent($this->field_2->getName(), $display_options_2); + $display->setComponent($this->field_name_2, $display_options_2); // View all fields. $content = $display->build($entity); @@ -98,14 +98,14 @@ function testEntityDisplayBuild() { // Label hidden. $entity = clone($entity_init); $display_options['label'] = 'hidden'; - $display->setComponent($this->field->getName(), $display_options); + $display->setComponent($this->field_name, $display_options); $content = $display->build($entity); $this->content = drupal_render($content); $this->assertNoRaw($this->instance->getLabel(), "Hidden label: label is not displayed."); // Field hidden. $entity = clone($entity_init); - $display->removeComponent($this->field->getName()); + $display->removeComponent($this->field_name); $content = $display->build($entity); $this->content = drupal_render($content); $this->assertNoRaw($this->instance->getLabel(), "Hidden field: label is not displayed."); @@ -116,7 +116,7 @@ function testEntityDisplayBuild() { // Multiple formatter. $entity = clone($entity_init); $formatter_setting = $this->randomName(); - $display->setComponent($this->field->getName(), array( + $display->setComponent($this->field_name, array( 'label' => 'above', 'type' => 'field_test_multiple', 'settings' => array( @@ -134,7 +134,7 @@ function testEntityDisplayBuild() { // Test a formatter that uses hook_field_formatter_prepare_view(). $entity = clone($entity_init); $formatter_setting = $this->randomName(); - $display->setComponent($this->field->getName(), array( + $display->setComponent($this->field_name, array( 'label' => 'above', 'type' => 'field_test_with_prepare_view', 'settings' => array( @@ -183,7 +183,7 @@ function testFieldAttachCache() { // Initialize random values and a test entity. $entity_init = entity_create('entity_test', array('type' => $this->instance->bundle)); $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED; - $values = $this->_generateTestFieldValues($this->field->getCardinality()); + $values = $this->_generateTestFieldValues($this->field_storage->getCardinality()); // Non-cacheable entity type. $entity_type = 'entity_test'; @@ -226,7 +226,7 @@ function testFieldAttachCache() { $this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load'); // Update with different values, and check that the cache entry is wiped. - $values = $this->_generateTestFieldValues($this->field_2->getCardinality()); + $values = $this->_generateTestFieldValues($this->field_storage_2->getCardinality()); $entity->{$this->field_name_2} = $values; $entity->save(); $this->assertFalse(\Drupal::cache('entity')->get($cid), 'Cached: no cache entry on update'); @@ -238,7 +238,7 @@ function testFieldAttachCache() { $this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load'); // Create a new revision, and check that the cache entry is wiped. - $values = $this->_generateTestFieldValues($this->field_2->getCardinality()); + $values = $this->_generateTestFieldValues($this->field_storage_2->getCardinality()); $entity->{$this->field_name_2} = $values; $entity->setNewRevision(); $entity->save(); @@ -275,11 +275,11 @@ function testEntityFormDisplayBuildForm() { $this->assertEqual($form[$this->field_name]['widget']['#title'], $this->instance->getLabel(), "First field's form title is {$this->instance->getLabel()}"); $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2->getLabel(), "Second field's form title is {$this->instance_2->getLabel()}"); - for ($delta = 0; $delta < $this->field->getCardinality(); $delta++) { + for ($delta = 0; $delta < $this->field_storage->getCardinality(); $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name]['widget'][$delta]['value']['#type'], 'textfield', "First field's form delta $delta widget is textfield"); } - for ($delta = 0; $delta < $this->field_2->getCardinality(); $delta++) { + for ($delta = 0; $delta < $this->field_storage_2->getCardinality(); $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } @@ -297,7 +297,7 @@ function testEntityFormDisplayBuildForm() { $this->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form'); $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2->getLabel(), "Second field's form title is {$this->instance_2->getLabel()}"); - for ($delta = 0; $delta < $this->field_2->getCardinality(); $delta++) { + for ($delta = 0; $delta < $this->field_storage_2->getCardinality(); $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } @@ -322,11 +322,11 @@ function testEntityFormDisplayExtractFormValues() { // First field. $values = array(); $weights = array(); - for ($delta = 0; $delta < $this->field->getCardinality(); $delta++) { + for ($delta = 0; $delta < $this->field_storage->getCardinality(); $delta++) { $values[$delta]['value'] = mt_rand(1, 127); // Assign random weight. do { - $weight = mt_rand(0, $this->field->getCardinality()); + $weight = mt_rand(0, $this->field_storage->getCardinality()); } while (in_array($weight, $weights)); $weights[$delta] = $weight; $values[$delta]['_weight'] = $weight; @@ -336,11 +336,11 @@ function testEntityFormDisplayExtractFormValues() { // Second field. $values_2 = array(); $weights_2 = array(); - for ($delta = 0; $delta < $this->field_2->getCardinality(); $delta++) { + for ($delta = 0; $delta < $this->field_storage_2->getCardinality(); $delta++) { $values_2[$delta]['value'] = mt_rand(1, 127); // Assign random weight. do { - $weight = mt_rand(0, $this->field_2->getCardinality()); + $weight = mt_rand(0, $this->field_storage_2->getCardinality()); } while (in_array($weight, $weights_2)); $weights_2[$delta] = $weight; $values_2[$delta]['_weight'] = $weight; diff --git a/core/modules/field/src/Tests/FieldAttachStorageTest.php b/core/modules/field/src/Tests/FieldAttachStorageTest.php index 9ec1d7c..f52b9b3 100644 --- a/core/modules/field/src/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/src/Tests/FieldAttachStorageTest.php @@ -51,7 +51,7 @@ public function setUp() { function testFieldAttachSaveLoad() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); - $cardinality = $this->field->getCardinality(); + $cardinality = $this->field_storage->getCardinality(); // TODO : test empty values filtering and "compression" (store consecutive deltas). // Preparation: create three revisions and store them in $revision array. @@ -115,13 +115,13 @@ function testFieldAttachLoadMultiple() { ); for ($i = 1; $i <= 3; $i++) { $field_names[$i] = 'field_' . $i; - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => $field_names[$i], 'entity_type' => $entity_type, 'type' => 'test_field', )); - $field->save(); - $field_ids[$i] = $field->uuid(); + $field_storage->save(); + $field_ids[$i] = $field_storage->uuid(); foreach ($field_bundles_map[$i] as $bundle) { entity_create('field_instance_config', array( 'field_name' => $field_names[$i], @@ -242,7 +242,7 @@ function testFieldAttachSaveEmptyDataDefaultValue() { function testFieldAttachDelete() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); - $cardinality = $this->field->getCardinality(); + $cardinality = $this->field_storage->getCardinality(); $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); $vids = array(); @@ -300,7 +300,7 @@ function testFieldAttachDelete() { function testEntityCreateRenameBundle() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); - $cardinality = $this->field->getCardinality(); + $cardinality = $this->field_storage->getCardinality(); // Create a new bundle. $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); @@ -351,13 +351,13 @@ function testEntityDeleteBundle() { // Create a second field for the test bundle $field_name = drupal_strtolower($this->randomName() . '_field_name'); - $field = array( + $field_storage = array( 'name' => $field_name, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => 1, ); - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); $instance = array( 'field_name' => $field_name, 'entity_type' => $entity_type, @@ -370,7 +370,7 @@ function testEntityDeleteBundle() { // Save an entity with data for both fields $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); - $values = $this->_generateTestFieldValues($this->field->getCardinality()); + $values = $this->_generateTestFieldValues($this->field_storage->getCardinality()); $entity->{$this->field_name} = $values; $entity->{$field_name} = $this->_generateTestFieldValues(1); $entity = $this->entitySaveReload($entity); diff --git a/core/modules/field/src/Tests/FieldDataCountTest.php b/core/modules/field/src/Tests/FieldDataCountTest.php index 3275b47..2c4edd9 100644 --- a/core/modules/field/src/Tests/FieldDataCountTest.php +++ b/core/modules/field/src/Tests/FieldDataCountTest.php @@ -13,7 +13,7 @@ * Tests counting field data records. * * @see \Drupal\Core\Entity\FieldableEntityStorageInterface::countFieldData() - * @see \Drupal\field\Entity\FieldConfig::hasData() + * @see \Drupal\field\Entity\FieldStorageConfig::hasData() */ class FieldDataCountTest extends FieldUnitTestBase { @@ -27,8 +27,8 @@ class FieldDataCountTest extends FieldUnitTestBase { */ public static function getInfo() { return array( - 'name' => 'Field config hasData() tests.', - 'description' => 'Tests counting field data records and the hasData() method on FieldConfig entity.', + 'name' => 'Field storage config hasData() tests.', + 'description' => 'Tests counting field data records and the hasData() method on FieldStorageConfig entity.', 'group' => 'Field API', ); } @@ -47,29 +47,29 @@ public function setUp() { public function testEntityCountAndHasData() { // Create a field with a cardinality of 2 to show that we are counting // entities and not rows in a table. - /** @var \Drupal\field\Entity\FieldConfig $field */ - $field = entity_create('field_config', array( + /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */ + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_int', 'entity_type' => 'entity_test', 'type' => 'integer', 'cardinality' => 2, )); - $field->save(); + $field_storage->save(); entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', ))->save(); - $this->assertIdentical($field->hasdata(), FALSE, 'There are no entities with field data.'); - $this->assertIdentical($this->storage->countFieldData($field), 0, 'There are 0 entities with field data.'); + $this->assertIdentical($field_storage->hasdata(), FALSE, 'There are no entities with field data.'); + $this->assertIdentical($this->storage->countFieldData($field_storage), 0, 'There are 0 entities with field data.'); // Create 1 entity without the field. $entity = entity_create('entity_test'); $entity->name->value = $this->randomName(); $entity->save(); - $this->assertIdentical($field->hasdata(), FALSE, 'There are no entities with field data.'); - $this->assertIdentical($this->storage->countFieldData($field), 0, 'There are 0 entities with field data.'); + $this->assertIdentical($field_storage->hasdata(), FALSE, 'There are no entities with field data.'); + $this->assertIdentical($this->storage->countFieldData($field_storage), 0, 'There are 0 entities with field data.'); // Create 12 entities to ensure that the purging works as expected. for ($i=0; $i < 12; $i++) { @@ -85,7 +85,7 @@ public function testEntityCountAndHasData() { $storage = \Drupal::entityManager()->getStorage('entity_test'); if ($storage instanceof ContentEntityDatabaseStorage) { // Count the actual number of rows in the field table. - $field_table_name = $storage->_fieldTableName($field); + $field_table_name = $storage->_fieldTableName($field_storage); $result = db_select($field_table_name, 't') ->fields('t') ->countQuery() @@ -94,17 +94,17 @@ public function testEntityCountAndHasData() { $this->assertEqual($result, 24, 'The field table has 24 rows.'); } - $this->assertIdentical($field->hasdata(), TRUE, 'There are entities with field data.'); - $this->assertEqual($this->storage->countFieldData($field), 12, 'There are 12 entities with field data.'); + $this->assertIdentical($field_storage->hasdata(), TRUE, 'There are entities with field data.'); + $this->assertEqual($this->storage->countFieldData($field_storage), 12, 'There are 12 entities with field data.'); // Ensure the methods work on deleted fields. - $field->delete(); - $this->assertIdentical($field->hasdata(), TRUE, 'There are entities with deleted field data.'); - $this->assertEqual($this->storage->countFieldData($field), 12, 'There are 12 entities with deleted field data.'); + $field_storage->delete(); + $this->assertIdentical($field_storage->hasdata(), TRUE, 'There are entities with deleted field data.'); + $this->assertEqual($this->storage->countFieldData($field_storage), 12, 'There are 12 entities with deleted field data.'); field_purge_batch(6); - $this->assertIdentical($field->hasdata(), TRUE, 'There are entities with deleted field data.'); - $this->assertEqual($this->storage->countFieldData($field), 6, 'There are 6 entities with deleted field data.'); + $this->assertIdentical($field_storage->hasdata(), TRUE, 'There are entities with deleted field data.'); + $this->assertEqual($this->storage->countFieldData($field_storage), 6, 'There are 6 entities with deleted field data.'); } } diff --git a/core/modules/field/src/Tests/FieldImportCreateTest.php b/core/modules/field/src/Tests/FieldImportCreateTest.php index 7a1c4fb..0989301 100644 --- a/core/modules/field/src/Tests/FieldImportCreateTest.php +++ b/core/modules/field/src/Tests/FieldImportCreateTest.php @@ -33,9 +33,9 @@ function testImportCreateDefault() { $instance_id_2b = "entity_test.test_bundle.$field_name_2"; // Check that the fields and instances do not exist yet. - $this->assertFalse(entity_load('field_config', $field_id)); + $this->assertFalse(entity_load('field_storage_config', $field_id)); $this->assertFalse(entity_load('field_instance_config', $instance_id)); - $this->assertFalse(entity_load('field_config', $field_id_2)); + $this->assertFalse(entity_load('field_storage_config', $field_id_2)); $this->assertFalse(entity_load('field_instance_config', $instance_id_2a)); $this->assertFalse(entity_load('field_instance_config', $instance_id_2b)); @@ -47,14 +47,14 @@ function testImportCreateDefault() { \Drupal::moduleHandler()->install(array('field_test_config')); // A field with one instance. - $field = entity_load('field_config', $field_id); - $this->assertTrue($field, 'The field was created.'); + $field_storage = entity_load('field_storage_config', $field_id); + $this->assertTrue($field_storage, 'The field was created.'); $instance = entity_load('field_instance_config', $instance_id); $this->assertTrue($instance, 'The field instance was deleted.'); // A field with multiple instances. - $field_2 = entity_load('field_config', $field_id_2); - $this->assertTrue($field_2, 'The second field was created.'); + $field_storage_2 = entity_load('field_storage_config', $field_id_2); + $this->assertTrue($field_storage_2, 'The second field was created.'); $this->assertTrue($instance->bundle, 'test_bundle', 'The second field instance was created on bundle test_bundle.'); $this->assertTrue($instance->bundle, 'test_bundle_2', 'The second field instance was created on bundle test_bundle_2.'); @@ -82,7 +82,7 @@ function testImportCreate() { $field_name = 'field_test_import_staging'; $field_id = "entity_test.$field_name"; $instance_id = "entity_test.entity_test.$field_name"; - $field_config_name = "field.field.$field_id"; + $field_config_name = "field.storage.$field_id"; $instance_config_name = "field.instance.$instance_id"; // One field with two field instances. @@ -90,7 +90,7 @@ function testImportCreate() { $field_id_2 = "entity_test.$field_name_2"; $instance_id_2a = "entity_test.test_bundle.$field_name_2"; $instance_id_2b = "entity_test.test_bundle_2.$field_name_2"; - $field_config_name_2 = "field.field.$field_id_2"; + $field_config_name_2 = "field.storage.$field_id_2"; $instance_config_name_2a = "field.instance.$instance_id_2a"; $instance_config_name_2b = "field.instance.$instance_id_2b"; @@ -111,12 +111,12 @@ function testImportCreate() { $this->configImporter()->import(); // Check that the field and instance were created. - $field = entity_load('field_config', $field_id); - $this->assertTrue($field, 'Test import field from staging exists'); + $field_storage = entity_load('field_storage_config', $field_id); + $this->assertTrue($field_storage, 'Test import field from staging exists'); $instance = entity_load('field_instance_config', $instance_id); $this->assertTrue($instance, 'Test import field instance from staging exists'); - $field = entity_load('field_config', $field_id_2); - $this->assertTrue($field, 'Test import field 2 from staging exists'); + $field_storage = entity_load('field_storage_config', $field_id_2); + $this->assertTrue($field_storage, 'Test import field 2 from staging exists'); $instance = entity_load('field_instance_config', $instance_id_2a); $this->assertTrue($instance, 'Test import field instance 2a from staging exists'); $instance = entity_load('field_instance_config', $instance_id_2b); diff --git a/core/modules/field/src/Tests/FieldImportDeleteTest.php b/core/modules/field/src/Tests/FieldImportDeleteTest.php index b0485c4..2885a70 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteTest.php @@ -35,21 +35,21 @@ public static function getInfo() { public function testImportDelete() { // At this point there are 5 field configuration objects in the active // storage. - // - field.field.entity_test.field_test_import - // - field.field.entity_test.field_test_import_2 + // - field.storage.entity_test.field_test_import + // - field.storage.entity_test.field_test_import_2 // - field.instance.entity_test.entity_test.field_test_import // - field.instance.entity_test.entity_test.field_test_import_2 // - field.instance.entity_test.test_bundle.field_test_import_2 $field_name = 'field_test_import'; - $field_id = "entity_test.$field_name"; + $field_storage_id = "entity_test.$field_name"; $field_name_2 = 'field_test_import_2'; - $field_id_2 = "entity_test.$field_name_2"; + $field_storage_id_2 = "entity_test.$field_name_2"; $instance_id = "entity_test.entity_test.$field_name"; $instance_id_2a = "entity_test.entity_test.$field_name_2"; $instance_id_2b = "entity_test.test_bundle.$field_name_2"; - $field_config_name = "field.field.$field_id"; - $field_config_name_2 = "field.field.$field_id_2"; + $field_storage_config_name = "field.storage.$field_storage_id"; + $field_storage_config_name_2 = "field.storage.$field_storage_id_2"; $instance_config_name = "field.instance.$instance_id"; $instance_config_name_2a = "field.instance.$instance_id_2a"; $instance_config_name_2b = "field.instance.$instance_id_2b"; @@ -60,15 +60,15 @@ public function testImportDelete() { // Import default config. $this->installConfig(array('field_test_config')); - // Get the uuid's for the fields. - $field_uuid = entity_load('field_config', $field_id)->uuid(); - $field_uuid_2 = entity_load('field_config', $field_id_2)->uuid(); + // Get the uuid's for the field storages. + $field_storage_uuid = entity_load('field_storage_config', $field_storage_id)->uuid(); + $field_storage_uuid_2 = entity_load('field_storage_config', $field_storage_id_2)->uuid(); $active = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); $this->copyConfig($active, $staging); - $this->assertTrue($staging->delete($field_config_name), String::format('Deleted field: !field', array('!field' => $field_config_name))); - $this->assertTrue($staging->delete($field_config_name_2), String::format('Deleted field: !field', array('!field' => $field_config_name_2))); + $this->assertTrue($staging->delete($field_storage_config_name), String::format('Deleted field: !field', array('!field' => $field_storage_config_name))); + $this->assertTrue($staging->delete($field_storage_config_name_2), String::format('Deleted field: !field', array('!field' => $field_storage_config_name_2))); $this->assertTrue($staging->delete($instance_config_name), String::format('Deleted field instance: !field_instance', array('!field_instance' => $instance_config_name))); $this->assertTrue($staging->delete($instance_config_name_2a), String::format('Deleted field instance: !field_instance', array('!field_instance' => $instance_config_name_2a))); $this->assertTrue($staging->delete($instance_config_name_2b), String::format('Deleted field instance: !field_instance', array('!field_instance' => $instance_config_name_2b))); @@ -80,10 +80,10 @@ public function testImportDelete() { $this->configImporter()->import(); // Check that the fields and instances are gone. - $field = entity_load('field_config', $field_id, TRUE); - $this->assertFalse($field, 'The field was deleted.'); - $field_2 = entity_load('field_config', $field_id_2, TRUE); - $this->assertFalse($field_2, 'The second field was deleted.'); + $field_storage = entity_load('field_storage_config', $field_storage_id, TRUE); + $this->assertFalse($field_storage, 'The field was deleted.'); + $field_storage_2 = entity_load('field_storage_config', $field_storage_id_2, TRUE); + $this->assertFalse($field_storage_2, 'The second field was deleted.'); $instance = entity_load('field_instance_config', $instance_id, TRUE); $this->assertFalse($instance, 'The field instance was deleted.'); $instance_2a = entity_load('field_instance_config', $instance_id_2a, TRUE); @@ -93,22 +93,22 @@ public function testImportDelete() { // Check that all config files are gone. $active = $this->container->get('config.storage'); - $this->assertIdentical($active->listAll($field_config_name), array()); - $this->assertIdentical($active->listAll($field_config_name_2), array()); + $this->assertIdentical($active->listAll($field_storage_config_name), array()); + $this->assertIdentical($active->listAll($field_storage_config_name_2), array()); $this->assertIdentical($active->listAll($instance_config_name), array()); $this->assertIdentical($active->listAll($instance_config_name_2a), array()); $this->assertIdentical($active->listAll($instance_config_name_2b), array()); - // Check that the field definition is preserved in state. - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - $this->assertTrue(isset($deleted_fields[$field_uuid])); - $this->assertTrue(isset($deleted_fields[$field_uuid_2])); + // Check that the storage definition is preserved in state. + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $this->assertTrue(isset($deleted_storages[$field_storage_uuid])); + $this->assertTrue(isset($deleted_storages[$field_storage_uuid_2])); - // Purge field data, and check that the field definition has been completely - // removed once the data is purged. + // Purge field data, and check that the storage definition has been + // completely removed once the data is purged. field_purge_batch(10); - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - $this->assertTrue(empty($deleted_fields), 'Fields are deleted'); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $this->assertTrue(empty($deleted_storages), 'Fields are deleted'); } } diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php index dd6fe61..322ed3d 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php @@ -46,28 +46,26 @@ public function testImportDeleteUninstall() { // Create a field to delete to prove that // \Drupal\field\ConfigImporterFieldPurger does not purge fields that are // not related to the configuration synchronization. - $unrelated_field = entity_create('field_config', array( + $unrelated_field_storage = entity_create('field_storage_config', array( 'name' => 'field_int', 'entity_type' => 'entity_test', 'type' => 'integer', )); - $unrelated_field->save(); - $unrelated_field_uuid = $unrelated_field->uuid(); + $unrelated_field_storage->save(); entity_create('field_instance_config', array( - 'field' => $unrelated_field, + 'field_storage' => $unrelated_field_storage, 'bundle' => 'entity_test', ))->save(); // Create a telephone field and instance for validation. - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'telephone', )); - $field->save(); - $field_uuid = $field->uuid(); + $field_storage->save(); entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', ))->save(); @@ -87,7 +85,7 @@ public function testImportDeleteUninstall() { // Delete unrelated field before copying configuration and running the // synchronization. - $unrelated_field->delete(); + $unrelated_field_storage->delete(); $active = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); @@ -99,7 +97,7 @@ public function testImportDeleteUninstall() { $staging->write('core.extension', $core_extension); // Stage the field deletion - $staging->delete('field.field.entity_test.field_test'); + $staging->delete('field.storage.entity_test.field_test'); $staging->delete('field.instance.entity_test.entity_test.field_test'); $steps = $this->configImporter()->initialize(); @@ -110,10 +108,10 @@ public function testImportDeleteUninstall() { $this->configImporter()->import(); $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone')); - $this->assertFalse(entity_load_by_uuid('field_config', $field_uuid), 'The test field has been deleted by the configuration synchronization'); - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - $this->assertFalse(isset($deleted_fields[$field_uuid]), 'Telephone field has been completed removed from the system.'); - $this->assertTrue(isset($deleted_fields[$unrelated_field_uuid]), 'Unrelated field not purged by configuration synchronization.'); + $this->assertFalse(entity_load_by_uuid('field_storage_config', $field_storage->uuid()), 'The test field has been deleted by the configuration synchronization'); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.'); + $this->assertTrue(isset($deleted_storages[$unrelated_field_storage->uuid()]), 'Unrelated field not purged by configuration synchronization.'); } /** @@ -121,15 +119,15 @@ public function testImportDeleteUninstall() { */ public function testImportAlreadyDeletedUninstall() { // Create a telephone field and instance for validation. - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'telephone', )); - $field->save(); - $field_uuid = $field->uuid(); + $field_storage->save(); + $field_storage_uuid = $field_storage->uuid(); entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', ))->save(); @@ -148,7 +146,7 @@ public function testImportAlreadyDeletedUninstall() { } // Delete the field. - $field->delete(); + $field_storage->delete(); $active = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); @@ -159,8 +157,8 @@ public function testImportAlreadyDeletedUninstall() { unset($core_extension['module']['telephone']); $staging->write('core.extension', $core_extension); - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - $this->assertTrue(isset($deleted_fields[$field_uuid]), 'Field has been deleted and needs purging before configuration synchronization.'); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $this->assertTrue(isset($deleted_storages[$field_storage_uuid]), 'Field has been deleted and needs purging before configuration synchronization.'); $steps = $this->configImporter()->initialize(); $this->assertIdentical($steps[0], array('\Drupal\field\ConfigImporterFieldPurger', 'process'), 'The additional process configuration synchronization step has been added.'); @@ -170,8 +168,8 @@ public function testImportAlreadyDeletedUninstall() { $this->configImporter()->import(); $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone')); - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - $this->assertFalse(isset($deleted_fields[$field_uuid]), 'Field has been completed removed from the system.'); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $this->assertFalse(isset($deleted_storages[$field_storage_uuid]), 'Field has been completed removed from the system.'); } } diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php index c8f6db0..333c917 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php @@ -43,28 +43,26 @@ function setUp() { */ public function testImportDeleteUninstall() { // Create a telephone field and instance. - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_tel', 'entity_type' => 'entity_test', 'type' => 'telephone', )); - $field->save(); - $tel_field_uuid = $field->uuid(); + $field_storage->save(); entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'entity_test', ))->save(); // Create a text field and instance. - $text_field = entity_create('field_config', array( + $text_field_storage = entity_create('field_storage_config', array( 'name' => 'field_text', 'entity_type' => 'entity_test', 'type' => 'text', )); - $text_field->save(); - $text_field_uuid = $field->uuid(); + $text_field_storage->save(); entity_create('field_instance_config', array( - 'field' => $text_field, + 'field_storage' => $text_field_storage, 'bundle' => 'entity_test', ))->save(); @@ -79,7 +77,7 @@ public function testImportDeleteUninstall() { // Delete the text field before exporting configuration so that we can test // that deleted fields that are provided by modules that will be uninstalled // are also purged and that the UI message includes such fields. - $text_field->delete(); + $text_field_storage->delete(); // Verify entity has been created properly. $id = $entity->id(); @@ -97,7 +95,7 @@ public function testImportDeleteUninstall() { $staging->write('core.extension', $core_extension); // Stage the field deletion - $staging->delete('field.field.entity_test.field_tel'); + $staging->delete('field.storage.entity_test.field_tel'); $staging->delete('field.instance.entity_test.entity_test.field_tel'); $this->drupalGet('admin/config/development/configuration'); // Test that the message for one field being purged during a configuration @@ -117,10 +115,10 @@ public function testImportDeleteUninstall() { $this->assertNoText('Field data will be deleted by this synchronization.'); $this->rebuildContainer(); $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone')); - $this->assertFalse(entity_load_by_uuid('field_config', $tel_field_uuid), 'The telephone field has been deleted by the configuration synchronization'); - $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); - $this->assertFalse(isset($deleted_fields[$tel_field_uuid]), 'Telephone field has been completed removed from the system.'); - $this->assertFalse(isset($deleted_fields[$text_field_uuid]), 'Text field has been completed removed from the system.'); + $this->assertFalse(entity_load_by_uuid('field_storage_config', $field_storage->uuid()), 'The telephone field has been deleted by the configuration synchronization'); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.'); + $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Text field has been completed removed from the system.'); } } diff --git a/core/modules/field/src/Tests/FieldInstanceCrudTest.php b/core/modules/field/src/Tests/FieldInstanceCrudTest.php index 2b867e5..bc116d4 100644 --- a/core/modules/field/src/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/src/Tests/FieldInstanceCrudTest.php @@ -8,7 +8,7 @@ namespace Drupal\field\Tests; use Drupal\Core\Entity\EntityStorageException; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\FieldException; @@ -18,25 +18,25 @@ class FieldInstanceCrudTest extends FieldUnitTestBase { /** - * The field entity. + * The field storage entity. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $fieldStorage; /** * The field entity definition. * * @var array */ - protected $field_definition; + protected $fieldStorageDefinition; /** * The field instance entity definition. * * @var array */ - protected $instance_definition; + protected $instanceDefinition; public static function getInfo() { return array( @@ -49,15 +49,15 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->field_definition = array( + $this->fieldStorageDefinition = array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $this->field = entity_create('field_config', $this->field_definition); - $this->field->save(); - $this->instance_definition = array( - 'field_name' => $this->field->getName(), + $this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition); + $this->fieldStorage->save(); + $this->instanceDefinition = array( + 'field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); @@ -73,7 +73,7 @@ function setUp() { * Test the creation of a field instance. */ function testCreateFieldInstance() { - $instance = entity_create('field_instance_config', $this->instance_definition); + $instance = entity_create('field_instance_config', $this->instanceDefinition); $instance->save(); // Read the configuration. Check against raw configuration data rather than @@ -84,18 +84,18 @@ function testCreateFieldInstance() { // Check that default values are set. $this->assertEqual($config['required'], FALSE, 'Required defaults to false.'); - $this->assertIdentical($config['label'], $this->instance_definition['field_name'], 'Label defaults to field name.'); + $this->assertIdentical($config['label'], $this->instanceDefinition['field_name'], 'Label defaults to field name.'); $this->assertIdentical($config['description'], '', 'Description defaults to empty string.'); // Check that default settings are set. - $this->assertEqual($config['settings'], $field_type_manager->getDefaultInstanceSettings($this->field_definition['type']) , 'Default instance settings have been written.'); + $this->assertEqual($config['settings'], $field_type_manager->getDefaultInstanceSettings($this->fieldStorageDefinition['type']) , 'Default instance settings have been written.'); // Check that the denormalized 'field_type' was properly written. - $this->assertEqual($config['field_type'], $this->field_definition['type']); + $this->assertEqual($config['field_type'], $this->fieldStorageDefinition['type']); // Guarantee that the field/bundle combination is unique. try { - entity_create('field_instance_config', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instanceDefinition)->save(); $this->fail(t('Cannot create two instances with the same field / bundle combination.')); } catch (EntityStorageException $e) { @@ -104,8 +104,8 @@ function testCreateFieldInstance() { // Check that the specified field exists. try { - $this->instance_definition['field_name'] = $this->randomName(); - entity_create('field_instance_config', $this->instance_definition)->save(); + $this->instanceDefinition['field_name'] = $this->randomName(); + entity_create('field_instance_config', $this->instanceDefinition)->save(); $this->fail(t('Cannot create an instance of a non-existing field.')); } catch (FieldException $e) { @@ -119,30 +119,30 @@ function testCreateFieldInstance() { * Test reading back an instance definition. */ function testReadFieldInstance() { - entity_create('field_instance_config', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instanceDefinition)->save(); // Read the instance back. - $instance = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); - $this->assertTrue($this->instance_definition['field_name'] == $instance->getName(), 'The field was properly read.'); - $this->assertTrue($this->instance_definition['entity_type'] == $instance->entity_type, 'The field was properly read.'); - $this->assertTrue($this->instance_definition['bundle'] == $instance->bundle, 'The field was properly read.'); + $instance = entity_load('field_instance_config', 'entity_test.' . $this->instanceDefinition['bundle'] . '.' . $this->instanceDefinition['field_name']); + $this->assertTrue($this->instanceDefinition['field_name'] == $instance->getName(), 'The field was properly read.'); + $this->assertTrue($this->instanceDefinition['entity_type'] == $instance->entity_type, 'The field was properly read.'); + $this->assertTrue($this->instanceDefinition['bundle'] == $instance->bundle, 'The field was properly read.'); } /** * Test the update of a field instance. */ function testUpdateFieldInstance() { - entity_create('field_instance_config', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instanceDefinition)->save(); // Check that basic changes are saved. - $instance = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance = entity_load('field_instance_config', 'entity_test.' . $this->instanceDefinition['bundle'] . '.' . $this->instanceDefinition['field_name']); $instance->required = !$instance->isRequired(); $instance->label = $this->randomName(); $instance->description = $this->randomName(); $instance->settings['test_instance_setting'] = $this->randomName(); $instance->save(); - $instance_new = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance_new = entity_load('field_instance_config', 'entity_test.' . $this->instanceDefinition['bundle'] . '.' . $this->instanceDefinition['field_name']); $this->assertEqual($instance->isRequired(), $instance_new->isRequired(), '"required" change is saved'); $this->assertEqual($instance->getLabel(), $instance_new->getLabel(), '"label" change is saved'); $this->assertEqual($instance->getDescription(), $instance_new->getDescription(), '"description" change is saved'); @@ -160,24 +160,24 @@ function testDeleteFieldInstance() { // Create two instances for the same field so we can test that only one // is deleted. - entity_create('field_instance_config', $this->instance_definition)->save(); - $another_instance_definition = $this->instance_definition; + entity_create('field_instance_config', $this->instanceDefinition)->save(); + $another_instance_definition = $this->instanceDefinition; $another_instance_definition['bundle'] .= '_another_bundle'; entity_test_create_bundle($another_instance_definition['bundle']); entity_create('field_instance_config', $another_instance_definition)->save(); // Test that the first instance is not deleted, and then delete it. - $instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); + $instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instanceDefinition['field_name'], 'bundle' => $this->instanceDefinition['bundle'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new field instance is not marked for deletion.'); $instance->delete(); // Make sure the instance is marked as deleted when the instance is // specifically loaded. - $instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); + $instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instanceDefinition['field_name'], 'bundle' => $this->instanceDefinition['bundle'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($instance->deleted), 'A deleted field instance is marked for deletion.'); // Try to load the instance normally and make sure it does not show up. - $instance = entity_load('field_instance_config', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance = entity_load('field_instance_config', 'entity_test.' . '.' . $this->instanceDefinition['bundle'] . '.' . $this->instanceDefinition['field_name']); $this->assertTrue(empty($instance), 'A deleted field instance is not loaded by default.'); // Make sure the other field instance is not deleted. @@ -189,41 +189,40 @@ function testDeleteFieldInstance() { * Tests the cross deletion behavior between fields and instances. */ function testDeleteFieldInstanceCrossDeletion() { - $instance_definition_2 = $this->instance_definition; + $instance_definition_2 = $this->instanceDefinition; $instance_definition_2['bundle'] .= '_another_bundle'; entity_test_create_bundle($instance_definition_2['bundle']); // Check that deletion of a field deletes its instances. - $field = $this->field; - entity_create('field_instance_config', $this->instance_definition)->save(); + $field_storage = $this->fieldStorage; + entity_create('field_instance_config', $this->instanceDefinition)->save(); entity_create('field_instance_config', $instance_definition_2)->save(); - $field->delete(); - $this->assertFalse(FieldInstanceConfig::loadByName('entity_test', $this->instance_definition['bundle'], $field->name)); - $this->assertFalse(FieldInstanceConfig::loadByName('entity_test', $instance_definition_2['bundle'], $field->name)); + $field_storage->delete(); + $this->assertFalse(FieldInstanceConfig::loadByName('entity_test', $this->instanceDefinition['bundle'], $field_storage->name)); + $this->assertFalse(FieldInstanceConfig::loadByName('entity_test', $instance_definition_2['bundle'], $field_storage->name)); // Chack that deletion of the last instance deletes the field. - $field = entity_create('field_config', $this->field_definition); - $field->save(); - $instance = entity_create('field_instance_config', $this->instance_definition); + $field_storage = entity_create('field_storage_config', $this->fieldStorageDefinition); + $field_storage->save(); + $instance = entity_create('field_instance_config', $this->instanceDefinition); $instance->save(); $instance_2 = entity_create('field_instance_config', $instance_definition_2); $instance_2->save(); $instance->delete(); - $this->assertTrue(FieldConfig::loadByName('entity_test', $field->name)); + $this->assertTrue(FieldStorageConfig::loadByName('entity_test', $field_storage->name)); $instance_2->delete(); - $this->assertFalse(FieldConfig::loadByName('entity_test', $field->name)); + $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->name)); // Check that deletion of all instances of the same field simultaneously // deletes the field. - $field = entity_create('field_config', $this->field_definition); - $field->save(); - $instance = entity_create('field_instance_config', $this->instance_definition); + $field_storage = entity_create('field_storage_config', $this->fieldStorageDefinition); + $field_storage->save(); + $instance = entity_create('field_instance_config', $this->instanceDefinition); $instance->save(); $instance_2 = entity_create('field_instance_config', $instance_definition_2); $instance_2->save(); - $instance_storage = $this->container->get('entity.manager')->getStorage('field_instance_config'); - $instance_storage->delete(array($instance, $instance_2)); - $this->assertFalse(FieldConfig::loadByName('entity_test', $field->name)); + $this->container->get('entity.manager')->getStorage('field_instance_config')->delete(array($instance, $instance_2)); + $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->name)); } } diff --git a/core/modules/field/src/Tests/FieldUnitTestBase.php b/core/modules/field/src/Tests/FieldUnitTestBase.php index 2100833..63c9269 100644 --- a/core/modules/field/src/Tests/FieldUnitTestBase.php +++ b/core/modules/field/src/Tests/FieldUnitTestBase.php @@ -62,22 +62,22 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu $bundle = $entity_type; } $field_name = 'field_name' . $suffix; - $field = 'field' . $suffix; - $field_id = 'field_id' . $suffix; + $field_storage = 'field_storage' . $suffix; + $field_storage_uuid = 'field_storage_uuid' . $suffix; $instance = 'instance' . $suffix; $instance_definition = 'instance_definition' . $suffix; $this->$field_name = drupal_strtolower($this->randomName() . '_field_name' . $suffix); - $this->$field = entity_create('field_config', array( + $this->$field_storage = entity_create('field_storage_config', array( 'name' => $this->$field_name, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => 4, )); - $this->$field->save(); - $this->$field_id = $this->{$field}->uuid(); + $this->$field_storage->save(); + $this->$field_storage_uuid = $this->{$field_storage}->uuid(); $this->$instance_definition = array( - 'field' => $this->$field, + 'field_storage' => $this->$field_storage, 'bundle' => $bundle, 'label' => $this->randomName() . '_label', 'description' => $this->randomName() . '_description', diff --git a/core/modules/field/src/Tests/FieldValidationTest.php b/core/modules/field/src/Tests/FieldValidationTest.php index 1a57a4c..9ebdb31 100644 --- a/core/modules/field/src/Tests/FieldValidationTest.php +++ b/core/modules/field/src/Tests/FieldValidationTest.php @@ -41,7 +41,7 @@ public function setUp() { * Tests that the number of values is validated against the field cardinality. */ function testCardinalityConstraint() { - $cardinality = $this->field->cardinality; + $cardinality = $this->field_storage->cardinality; $entity = $this->entity; for ($delta = 0; $delta < $cardinality + 1; $delta++) { @@ -61,7 +61,7 @@ function testCardinalityConstraint() { * Tests that constraints defined by the field type are validated. */ function testFieldConstraints() { - $cardinality = $this->field->getCardinality(); + $cardinality = $this->field_storage->getCardinality(); $entity = $this->entity; // The test is only valid if the field cardinality is greater than 2. diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index 255c19d..c38b9d7 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -27,21 +27,21 @@ class FormTest extends FieldTestBase { * * @var array */ - protected $field_single; + protected $fieldStorageSingle; /** * An array of values defining a field multiple. * * @var array */ - protected $field_multiple; + protected $fieldStorageMultiple; /** * An array of values defining a field with unlimited cardinality. * * @var array */ - protected $field_unlimited; + protected $fieldStorageUnlimited; /** * An array of values defining a field instance. @@ -64,18 +64,18 @@ function setUp() { $web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); $this->drupalLogin($web_user); - $this->field_single = array( + $this->fieldStorageSingle = array( 'name' => 'field_single', 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $this->field_multiple = array( + $this->fieldStorageMultiple = array( 'name' => 'field_multiple', 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => 4, ); - $this->field_unlimited = array( + $this->fieldStorageUnlimited = array( 'name' => 'field_unlimited', 'entity_type' => 'entity_test', 'type' => 'test_field', @@ -95,10 +95,10 @@ function setUp() { } function testFieldFormSingle() { - $field = $this->field_single; - $field_name = $field['name']; + $field_storage = $this->fieldStorageSingle; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) @@ -177,12 +177,12 @@ function testFieldFormSingle() { * Tests field widget default values on entity forms. */ function testFieldFormDefaultValue() { - $field = $this->field_single; - $field_name = $field['name']; + $field_storage = $this->fieldStorageSingle; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; $default = rand(1, 127); $this->instance['default_value'] = array(array('value' => $default)); - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) @@ -208,11 +208,11 @@ function testFieldFormDefaultValue() { } function testFieldFormSingleRequired() { - $field = $this->field_single; - $field_name = $field['name']; + $field_storage = $this->fieldStorageSingle; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; $this->instance['required'] = TRUE; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) @@ -252,15 +252,15 @@ function testFieldFormSingleRequired() { // $this->field = $this->field_multiple; // $field_name = $this->field['field_name']; // $this->instance['field_name'] = $field_name; -// entity_create('field_config', $this->field)->save(); +// entity_create('field_storage_config', $this->field)->save(); // entity_create('field_instance_config', $this->instance)->save(); // } function testFieldFormUnlimited() { - $field = $this->field_unlimited; - $field_name = $field['name']; + $field_storage = $this->fieldStorageUnlimited; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) @@ -343,17 +343,17 @@ function testFieldFormUnlimited() { */ function testFieldFormMultivalueWithRequiredRadio() { // Create a multivalue test field. - $field = $this->field_unlimited; - $field_name = $field['name']; + $field_storage = $this->fieldStorageUnlimited; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); // Add a required radio field. - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => 'required_radio_test', 'entity_type' => 'entity_test', 'type' => 'list_text', @@ -390,10 +390,10 @@ function testFieldFormMultivalueWithRequiredRadio() { } function testFieldFormJSAddMore() { - $field = $this->field_unlimited; - $field_name = $field['name']; + $field_storage = $this->fieldStorageUnlimited; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) @@ -451,10 +451,10 @@ function testFieldFormJSAddMore() { function testFieldFormMultipleWidget() { // Create a field with fixed cardinality and an instance using a multiple // widget. - $field = $this->field_multiple; - $field_name = $field['name']; + $field_storage = $this->fieldStorageMultiple; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name, array( @@ -498,14 +498,14 @@ function testFieldFormMultipleWidget() { function testFieldFormAccess() { $entity_type = 'entity_test_rev'; // Create a "regular" field. - $field = $this->field_single; - $field['entity_type'] = $entity_type; - $field_name = $field['name']; + $field_storage = $this->fieldStorageSingle; + $field_storage['entity_type'] = $entity_type; + $field_name = $field_storage['name']; $instance = $this->instance; $instance['field_name'] = $field_name; $instance['entity_type'] = $entity_type; $instance['bundle'] = $entity_type; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $instance)->save(); entity_get_form_display($entity_type, $entity_type, 'default') ->setComponent($field_name) @@ -513,19 +513,19 @@ function testFieldFormAccess() { // Create a field with no edit access. See // field_test_entity_field_access(). - $field_no_access = array( + $field_storage_no_access = array( 'name' => 'field_no_edit_access', 'entity_type' => $entity_type, 'type' => 'test_field', ); - $field_name_no_access = $field_no_access['name']; + $field_name_no_access = $field_storage_no_access['name']; $instance_no_access = array( 'field_name' => $field_name_no_access, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'default_value' => array(0 => array('value' => 99)), ); - entity_create('field_config', $field_no_access)->save(); + entity_create('field_storage_config', $field_storage_no_access)->save(); entity_create('field_instance_config', $instance_no_access)->save(); entity_get_form_display($instance_no_access['entity_type'], $instance_no_access['bundle'], 'default') ->setComponent($field_name_no_access) @@ -587,14 +587,14 @@ function testFieldFormAccess() { */ function testHiddenField() { $entity_type = 'entity_test_rev'; - $field = $this->field_single; - $field['entity_type'] = $entity_type; - $field_name = $field['name']; + $field_storage = $this->fieldStorageSingle; + $field_storage['entity_type'] = $entity_type; + $field_name = $field_storage['name']; $this->instance['field_name'] = $field_name; $this->instance['default_value'] = array(0 => array('value' => 99)); $this->instance['entity_type'] = $entity_type; $this->instance['bundle'] = $entity_type; - entity_create('field_config', $field)->save(); + entity_create('field_storage_config', $field_storage)->save(); $this->instance = entity_create('field_instance_config', $this->instance); $this->instance->save(); // We explicitly do not assign a widget in a form display, so the field diff --git a/core/modules/field/src/Tests/NestedFormTest.php b/core/modules/field/src/Tests/NestedFormTest.php index b7f0708..0445137 100644 --- a/core/modules/field/src/Tests/NestedFormTest.php +++ b/core/modules/field/src/Tests/NestedFormTest.php @@ -34,12 +34,12 @@ public function setUp() { $web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); $this->drupalLogin($web_user); - $this->field_single = array( + $this->fieldStorageSingle = array( 'name' => 'field_single', 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $this->field_unlimited = array( + $this->fieldStorageUnlimited = array( 'name' => 'field_unlimited', 'entity_type' => 'entity_test', 'type' => 'test_field', @@ -63,8 +63,8 @@ public function setUp() { */ function testNestedFieldForm() { // Add two instances on the 'entity_test' - entity_create('field_config', $this->field_single)->save(); - entity_create('field_config', $this->field_unlimited)->save(); + entity_create('field_storage_config', $this->fieldStorageSingle)->save(); + entity_create('field_storage_config', $this->fieldStorageUnlimited)->save(); $this->instance['field_name'] = 'field_single'; $this->instance['label'] = 'Single field'; entity_create('field_instance_config', $this->instance)->save(); diff --git a/core/modules/field/src/Tests/Number/NumberFieldTest.php b/core/modules/field/src/Tests/Number/NumberFieldTest.php index f9efa00..2c5767c 100644 --- a/core/modules/field/src/Tests/Number/NumberFieldTest.php +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php @@ -22,20 +22,6 @@ class NumberFieldTest extends WebTestBase { public static $modules = array('node', 'entity_test', 'field_ui'); /** - * A field to use in this class. - * - * @var \Drupal\field\Entity\FieldConfig - */ - protected $field; - - /** - * A field instance to use in this test class. - * - * @var \Drupal\field\Entity\FieldInstanceConfig - */ - protected $instance; - - /** * A user with permission to view and manage entities and content types. * * @var \Drupal\user\UserInterface @@ -63,7 +49,7 @@ function setUp() { function testNumberDecimalField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomName()); - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'decimal', @@ -155,7 +141,7 @@ function testNumberIntegerField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomName()); - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'integer', @@ -259,7 +245,7 @@ function testNumberIntegerField() { function testNumberFloatField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomName()); - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'float', @@ -358,13 +344,13 @@ function testNumberFormatter() { // Create a content type containing float and integer fields. $this->drupalCreateContentType(array('type' => $type)); - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => $float_field, 'entity_type' => 'node', 'type' => 'float', ))->save(); - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => $integer_field, 'entity_type' => 'node', 'type' => 'integer', diff --git a/core/modules/field/src/Tests/Number/NumberItemTest.php b/core/modules/field/src/Tests/Number/NumberItemTest.php index 011bf09..94c6ebe 100644 --- a/core/modules/field/src/Tests/Number/NumberItemTest.php +++ b/core/modules/field/src/Tests/Number/NumberItemTest.php @@ -36,7 +36,7 @@ public function setUp() { // Create number fields and instances for validation. foreach (array('integer', 'float', 'decimal') as $type) { - entity_create('field_config', array( + entity_create('field_storage_config', array( 'name' => 'field_' . $type, 'entity_type' => 'entity_test', 'type' => $type, diff --git a/core/modules/field/src/Tests/ShapeItemTest.php b/core/modules/field/src/Tests/ShapeItemTest.php index d3afd9a..3641a99 100644 --- a/core/modules/field/src/Tests/ShapeItemTest.php +++ b/core/modules/field/src/Tests/ShapeItemTest.php @@ -41,18 +41,16 @@ public function setUp() { parent::setUp(); // Create an field field and instance for validation. - $field = array( + entity_create('field_storage_config', array( 'name' => $this->field_name, 'entity_type' => 'entity_test', 'type' => 'shape', - ); - entity_create('field_config', $field)->save(); - $instance = array( + ))->save(); + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test', - ); - entity_create('field_instance_config', $instance)->save(); + ))->save(); } /** diff --git a/core/modules/field/src/Tests/TestItemTest.php b/core/modules/field/src/Tests/TestItemTest.php index a7680d3..aae5ea8 100644 --- a/core/modules/field/src/Tests/TestItemTest.php +++ b/core/modules/field/src/Tests/TestItemTest.php @@ -42,18 +42,16 @@ public function setUp() { parent::setUp(); // Create an field field and instance for validation. - $field = array( + entity_create('field_storage_config', array( 'name' => $this->field_name, 'entity_type' => 'entity_test', 'type' => 'test_field', - ); - entity_create('field_config', $field)->save(); - $instance = array( + ))->save(); + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test', - ); - entity_create('field_instance_config', $instance)->save(); + ))->save(); } /** diff --git a/core/modules/field/src/Tests/TranslationTest.php b/core/modules/field/src/Tests/TranslationTest.php index 618d8a5..58f22f1 100644 --- a/core/modules/field/src/Tests/TranslationTest.php +++ b/core/modules/field/src/Tests/TranslationTest.php @@ -55,11 +55,11 @@ class TranslationTest extends FieldUnitTestBase { protected $instance_definition; /** - * The field to use in this test. + * The field storage to use in this test. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $fieldStorage; /** * The field instance to use in this test. @@ -92,11 +92,11 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - $this->field = entity_create('field_config', $this->field_definition); - $this->field->save(); + $this->fieldStorage = entity_create('field_storage_config', $this->field_definition); + $this->fieldStorage->save(); $this->instance_definition = array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', ); $this->instance = entity_create('field_instance_config', $this->instance_definition); @@ -128,7 +128,7 @@ function testTranslatableFieldSaveLoad() { $available_langcodes = array_keys($this->container->get('language_manager')->getLanguages()); $entity->langcode->value = reset($available_langcodes); foreach ($available_langcodes as $langcode) { - $field_translations[$langcode] = $this->_generateTestFieldValues($this->field->getCardinality()); + $field_translations[$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality()); $entity->getTranslation($langcode)->{$this->field_name}->setValue($field_translations[$langcode]); } @@ -148,11 +148,11 @@ function testTranslatableFieldSaveLoad() { $field_name_default = drupal_strtolower($this->randomName() . '_field_name'); $field_definition = $this->field_definition; $field_definition['name'] = $field_name_default; - $field = entity_create('field_config', $field_definition); - $field->save(); + $field_storage = entity_create('field_storage_config', $field_definition); + $field_storage->save(); $instance_definition = $this->instance_definition; - $instance_definition['field'] = $field; + $instance_definition['field_storage'] = $field_storage; $instance_definition['default_value'] = array(array('value' => rand(1, 127))); $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); @@ -164,7 +164,7 @@ function testTranslatableFieldSaveLoad() { $values = array('type' => $instance->bundle, 'langcode' => $translation_langcodes[0]); $entity = entity_create($entity_type_id, $values); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field->getCardinality()); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality()); $entity->getTranslation($langcode, FALSE)->{$this->field_name}->setValue($values[$this->field_name][$langcode]); } @@ -182,7 +182,7 @@ function testTranslatableFieldSaveLoad() { $values = array('type' => $instance->bundle, 'langcode' => $translation_langcodes[0]); $entity = entity_create($entity_type_id, $values); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field->getCardinality()); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality()); $entity->getTranslation($langcode)->{$this->field_name}->setValue($values[$this->field_name][$langcode]); $entity->getTranslation($langcode)->{$field_name_default}->setValue($empty_items); $values[$field_name_default][$langcode] = $empty_items; diff --git a/core/modules/field/src/Tests/TranslationWebTest.php b/core/modules/field/src/Tests/TranslationWebTest.php index 18b9ef2..2577ddc 100644 --- a/core/modules/field/src/Tests/TranslationWebTest.php +++ b/core/modules/field/src/Tests/TranslationWebTest.php @@ -36,11 +36,11 @@ class TranslationWebTest extends FieldTestBase { protected $entity_type = 'entity_test_mulrev'; /** - * The field to use in this test. + * The field storage to use in this test. * - * @var \Drupal\field\Entity\FieldConfig + * @var \Drupal\field\Entity\FieldStorageConfig */ - protected $field; + protected $fieldStorage; /** * The field instance to use in this test. @@ -69,11 +69,11 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - entity_create('field_config', $field)->save(); - $this->field = entity_load('field_config', $this->entity_type . '.' . $this->field_name); + entity_create('field_storage_config', $field)->save(); + $this->fieldStorage = entity_load('field_storage_config', $this->entity_type . '.' . $this->field_name); $instance = array( - 'field' => $this->field, + 'field_storage' => $this->fieldStorage, 'bundle' => $this->entity_type, ); entity_create('field_instance_config', $instance)->save(); @@ -103,7 +103,7 @@ function testFieldFormTranslationRevisions() { field_test_entity_info_translatable($this->entity_type, TRUE); $entity = entity_create($this->entity_type); $available_langcodes = array_flip(array_keys($this->container->get('language_manager')->getLanguages())); - $field_name = $this->field->getName(); + $field_name = $this->fieldStorage->getName(); // Store the field translations. ksort($available_langcodes); @@ -132,7 +132,7 @@ function testFieldFormTranslationRevisions() { * by the passed arguments were correctly stored. */ private function checkTranslationRevisions($id, $revision_id, $available_langcodes) { - $field_name = $this->field->getName(); + $field_name = $this->fieldStorage->getName(); $entity = entity_revision_load($this->entity_type, $revision_id); foreach ($available_langcodes as $langcode => $value) { $passed = $entity->getTranslation($langcode)->{$field_name}->value == $value + 1; diff --git a/core/modules/field/src/Tests/Views/ApiDataTest.php b/core/modules/field/src/Tests/Views/ApiDataTest.php index be0d496..bd7e75b 100644 --- a/core/modules/field/src/Tests/Views/ApiDataTest.php +++ b/core/modules/field/src/Tests/Views/ApiDataTest.php @@ -13,11 +13,6 @@ */ class ApiDataTest extends FieldTestBase { - /** - * Stores the fields for this test case. - */ - var $fields; - public static function getInfo() { return array( 'name' => 'Field: Views Data', @@ -61,9 +56,9 @@ function testViewsData() { // Check the table and the joins of the first field. // Attached to node only. - $field = $this->fields[0]; - $current_table = ContentEntityDatabaseStorage::_fieldTableName($field); - $revision_table = ContentEntityDatabaseStorage::_fieldRevisionTableName($field); + $field_storage = $this->fieldStorages[0]; + $current_table = ContentEntityDatabaseStorage::_fieldTableName($field_storage); + $revision_table = ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage); $data[$current_table] = $views_data->get($current_table); $data[$revision_table] = $views_data->get($revision_table); diff --git a/core/modules/field/src/Tests/Views/FieldTestBase.php b/core/modules/field/src/Tests/Views/FieldTestBase.php index e5af4ab..43222e0 100644 --- a/core/modules/field/src/Tests/Views/FieldTestBase.php +++ b/core/modules/field/src/Tests/Views/FieldTestBase.php @@ -39,7 +39,7 @@ * * @var array */ - public $fields; + public $fieldStorages; /** * Stores the instances of the fields. They have @@ -66,25 +66,22 @@ function setUpFields($amount = 3) { $field_names = array(); for ($i = 0; $i < $amount; $i++) { $field_names[$i] = 'field_name_' . $i; - $field = array( + $this->fieldStorages[$i] = entity_create('field_storage_config', array( 'name' => $field_names[$i], 'entity_type' => 'node', 'type' => 'text', - ); - - $this->fields[$i] = $field = entity_create('field_config', $field); - $field->save(); + )); + $this->fieldStorages[$i]->save(); } return $field_names; } function setUpInstances($bundle = 'page') { - foreach ($this->fields as $key => $field) { - $instance = array( - 'field' => $field, - 'bundle' => 'page', - ); - $this->instances[$key] = entity_create('field_instance_config', $instance); + foreach ($this->fieldStorages as $key => $field_storage) { + $this->instances[$key] = entity_create('field_instance_config', array( + 'field_storage' => $field_storage, + 'bundle' => $bundle, + )); $this->instances[$key]->save(); } } diff --git a/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php index 15a4914..a9d2555 100644 --- a/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php @@ -48,21 +48,21 @@ protected function setUp() { $this->setUpFields(3); // Setup a field with cardinality > 1. - $this->fields[3] = $field = entity_create('field_config', array( + $this->fieldStorages[3] = entity_create('field_storage_config', array( 'name' => 'field_name_3', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, )); - $field->save(); + $this->fieldStorages[3]->save(); // Setup a field that will have no value. - $this->fields[4] = $field = entity_create('field_config', array( + $this->fieldStorages[4] = entity_create('field_storage_config', array( 'name' => 'field_name_4', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, )); - $field->save(); + $this->fieldStorages[4]->save(); $this->setUpInstances(); @@ -72,14 +72,14 @@ protected function setUp() { $edit = array('type' => 'page'); for ($key = 0; $key < 3; $key++) { - $field = $this->fields[$key]; - $edit[$field->getName()][0]['value'] = $this->randomName(8); + $field_storage = $this->fieldStorages[$key]; + $edit[$field_storage->getName()][0]['value'] = $this->randomName(8); } for ($j = 0; $j < 5; $j++) { - $edit[$this->fields[3]->getName()][$j]['value'] = $this->randomName(8); + $edit[$this->fieldStorages[3]->getName()][$j]['value'] = $this->randomName(8); } // Set this field to be empty. - $edit[$this->fields[4]->getName()] = array(array('value' => NULL)); + $edit[$this->fieldStorages[4]->getName()] = array(array('value' => NULL)); $this->nodes[$i] = $this->drupalCreateNode($edit); } @@ -95,8 +95,8 @@ protected function setUp() { */ protected function prepareView(ViewExecutable $view) { $view->initDisplay(); - foreach ($this->fields as $field) { - $field_name = $field->getName(); + foreach ($this->fieldStorages as $field_storage) { + $field_name = $field_storage->getName(); $view->display_handler->options['fields'][$field_name]['id'] = $field_name; $view->display_handler->options['fields'][$field_name]['table'] = 'node__' . $field_name; $view->display_handler->options['fields'][$field_name]['field'] = $field_name; @@ -117,7 +117,7 @@ public function _testSimpleFieldRender() { // Tests that the rendered fields match the actual value of the fields. for ($i = 0; $i < 3; $i++) { for ($key = 0; $key < 2; $key++) { - $field_name = $this->fields[$key]->getName(); + $field_name = $this->fieldStorages[$key]->getName(); $rendered_field = $view->style_plugin->getField($i, $field_name); $expected_field = $this->nodes[$i]->$field_name->value; $this->assertEqual($rendered_field, $expected_field); @@ -131,8 +131,8 @@ public function _testSimpleFieldRender() { public function _testFormatterSimpleFieldRender() { $view = Views::getView('test_view_fieldapi'); $this->prepareView($view); - $view->displayHandlers->get('default')->options['fields'][$this->fields[0]->getName()]['type'] = 'text_trimmed'; - $view->displayHandlers->get('default')->options['fields'][$this->fields[0]->getName()]['settings'] = array( + $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[0]->getName()]['type'] = 'text_trimmed'; + $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[0]->getName()]['settings'] = array( 'trim_length' => 3, ); $this->executeView($view); @@ -140,14 +140,14 @@ public function _testFormatterSimpleFieldRender() { // Make sure that the formatter works as expected. // @TODO: actually there should be a specific formatter. for ($i = 0; $i < 2; $i++) { - $rendered_field = $view->style_plugin->getField($i, $this->fields[0]->getName()); + $rendered_field = $view->style_plugin->getField($i, $this->fieldStorages[0]->getName()); $this->assertEqual(strlen($rendered_field), 3); } } public function _testMultipleFieldRender() { $view = Views::getView('test_view_fieldapi'); - $field_name = $this->fields[3]->getName(); + $field_name = $this->fieldStorages[3]->getName(); // Test delta limit. $this->prepareView($view); @@ -167,7 +167,7 @@ public function _testMultipleFieldRender() { } // Test that an empty field is rendered without error. - $view->style_plugin->getField(4, $this->fields[4]->getName()); + $view->style_plugin->getField(4, $this->fieldStorages[4]->getName()); $view->destroy(); // Test delta limit + offset diff --git a/core/modules/field/src/Tests/reEnableModuleFieldTest.php b/core/modules/field/src/Tests/reEnableModuleFieldTest.php index 81242db..1e4bf28 100644 --- a/core/modules/field/src/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/src/Tests/reEnableModuleFieldTest.php @@ -49,14 +49,14 @@ function setUp() { function testReEnabledField() { // Add a telephone field to the article content type. - $field = entity_create('field_config', array( + $field_storage = entity_create('field_storage_config', array( 'name' => 'field_telephone', 'entity_type' => 'node', 'type' => 'telephone', )); - $field->save(); + $field_storage->save(); entity_create('field_instance_config', array( - 'field' => $field, + 'field_storage' => $field_storage, 'bundle' => 'article', 'label' => 'Telephone Number', ))->save(); @@ -96,7 +96,7 @@ function testReEnabledField() { $this->drupalLogin($admin_user); $this->drupalGet('admin/modules'); $this->assertText('Fields type(s) in use'); - $field->delete(); + $field_storage->delete(); $this->drupalGet('admin/modules'); $this->assertText('Fields pending deletion'); $this->cronRun(); diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index 93e090b..6ebda87 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -6,11 +6,11 @@ */ use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\field\FieldConfigInterface; -use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException; +use Drupal\field\FieldStorageConfigInterface; /** * Implements hook_field_widget_info_alter(). @@ -20,10 +20,10 @@ function field_test_field_widget_info_alter(&$info) { } /** - * Implements hook_field_config_update_forbid(). + * Implements hook_field_storage_config_update_forbid(). */ -function field_test_field_config_update_forbid(FieldConfigInterface $field, FieldConfigInterface $prior_field) { - if ($field->getType() == 'test_field' && $field->getSetting('unchangeable') != $prior_field->getSetting('unchangeable')) { +function field_test_field_storage_config_update_forbid(FieldStorageConfigInterface $field_storage, FieldStorageConfigInterface $prior_field_storage) { + if ($field_storage->getType() == 'test_field' && $field_storage->getSetting('unchangeable') != $prior_field_storage->getSetting('unchangeable')) { throw new FieldStorageDefinitionUpdateForbiddenException("field_test 'unchangeable' setting cannot be changed'"); } } diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 6c9b7d4..13c846d 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -1,7 +1,7 @@ save(); + * entity_create('field_storage_config', $field_definition)->save(); * * // retrieve and reset the memorized hook call data * $mem = field_test_memorize(); * - * // make sure hook_field_config_create() is invoked correctly - * assertEqual(count($mem['field_test_field_config_create']), 1); - * assertEqual($mem['field_test_field_config_create'][0], array($field)); + * // make sure hook_field_storage_config_create() is invoked correctly + * assertEqual(count($mem['field_test_field_storage_config_create']), 1); + * assertEqual($mem['field_test_field_storage_config_create'][0], array($field)); * @endcode * * @param $key @@ -91,9 +91,9 @@ function field_test_memorize($key = NULL, $value = NULL) { } /** - * Memorize calls to field_test_field_config_create() for field creation. + * Memorize calls to field_test_field_storage_config_create(). */ -function field_test_field_config_create(FieldConfigInterface $field) { +function field_test_field_storage_config_create(FieldStorageConfigInterface $field_storage) { $args = func_get_args(); field_test_memorize(__FUNCTION__, $args); } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php index e21b180..45302e3 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php @@ -29,9 +29,9 @@ class TestItem extends FieldItemBase { */ public static function defaultSettings() { return array( - 'test_field_setting' => 'dummy test string', - 'changeable' => 'a changeable field setting', - 'unchangeable' => 'an unchangeable field setting', + 'test_field_storage_setting' => 'dummy test string', + 'changeable' => 'a changeable field storage setting', + 'unchangeable' => 'an unchangeable field storage setting', ) + parent::defaultSettings(); } @@ -77,12 +77,12 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) * {@inheritdoc} */ public function settingsForm(array &$form, array &$form_state, $has_data) { - $form['test_field_setting'] = array( + $form['test_field_storage_setting'] = array( '#type' => 'textfield', - '#title' => t('Field test field setting'), - '#default_value' => $this->getSetting('test_field_setting'), + '#title' => t('Field test field storage setting'), + '#default_value' => $this->getSetting('test_field_storage_setting'), '#required' => FALSE, - '#description' => t('A dummy form element to simulate field setting.'), + '#description' => t('A dummy form element to simulate field storage setting.'), ); return $form; diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml index c1537bf..d1fd117 100644 --- a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml +++ b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml @@ -11,3 +11,6 @@ default_value_function: '' settings: text_processing: 0 field_type: text +dependencies: + entity: + - field.storage.entity_test.field_test_import_2 diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml index 35d694a..ea2b33a 100644 --- a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml +++ b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml @@ -11,3 +11,6 @@ default_value_function: '' settings: text_processing: 0 field_type: text +dependencies: + entity: + - field.storage.entity_test.field_test_import diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml index 440536e..50f76c1 100644 --- a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml +++ b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml @@ -11,3 +11,6 @@ default_value_function: '' settings: text_processing: 0 field_type: text +dependencies: + entity: + - field.storage.entity_test.field_test_import_2 diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.storage.entity_test.field_test_import.yml similarity index 100% rename from core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.field_test_import.yml rename to core/modules/field/tests/modules/field_test_config/config/install/field.storage.entity_test.field_test_import.yml diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.field_test_import_2.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.storage.entity_test.field_test_import_2.yml similarity index 100% rename from core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.field_test_import_2.yml rename to core/modules/field/tests/modules/field_test_config/config/install/field.storage.entity_test.field_test_import_2.yml diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml index faf3e18..c69e8ba 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml @@ -12,3 +12,6 @@ default_value_function: '' settings: text_processing: '0' field_type: text +dependencies: + entity: + - field.storage.entity_test.field_test_import_staging diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml index dbe30a7..2bf3bb7 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml @@ -12,3 +12,6 @@ default_value_function: '' settings: text_processing: '0' field_type: text +dependencies: + entity: + - field.storage.entity_test.field_test_import_staging_2 diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml index ccc0c13..9e04777 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml @@ -12,3 +12,6 @@ default_value_function: '' settings: text_processing: '0' field_type: text +dependencies: + entity: + - field.storage.entity_test.field_test_import_staging_2 diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging.yml b/core/modules/field/tests/modules/field_test_config/staging/field.storage.entity_test.field_test_import_staging.yml similarity index 100% rename from core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging.yml rename to core/modules/field/tests/modules/field_test_config/staging/field.storage.entity_test.field_test_import_staging.yml diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging_2.yml b/core/modules/field/tests/modules/field_test_config/staging/field.storage.entity_test.field_test_import_staging_2.yml similarity index 100% rename from core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging_2.yml rename to core/modules/field/tests/modules/field_test_config/staging/field.storage.entity_test.field_test_import_staging_2.yml diff --git a/core/modules/field/tests/src/FieldInstanceConfigEntityUnitTest.php b/core/modules/field/tests/src/FieldInstanceConfigEntityUnitTest.php index 1d2b2ca..6a11a15 100644 --- a/core/modules/field/tests/src/FieldInstanceConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/FieldInstanceConfigEntityUnitTest.php @@ -49,6 +49,13 @@ class FieldInstanceConfigEntityUnitTest extends UnitTestCase { protected $uuid; /** + * The mock field storage. + * + * @var \Drupal\field\FieldStorageConfigInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $fieldStorage; + + /** * {@inheritdoc} */ public static function getInfo() { @@ -78,12 +85,12 @@ public function setUp() { $container->set('config.typed', $this->typedConfigManager); \Drupal::setContainer($container); - // Create a mock FieldConfig object. - $this->field = $this->getMock('\Drupal\field\FieldConfigInterface'); - $this->field->expects($this->any()) + // Create a mock FieldStorageConfig object. + $this->fieldStorage = $this->getMock('\Drupal\field\FieldStorageConfigInterface'); + $this->fieldStorage->expects($this->any()) ->method('getType') ->will($this->returnValue('test_field')); - $this->field->expects($this->any()) + $this->fieldStorage->expects($this->any()) ->method('getName') ->will($this->returnValue('field_test')); @@ -92,7 +99,7 @@ public function setUp() { ->method('getFieldStorageDefinitions') ->with('test_entity_type') ->will($this->returnValue(array( - $this->field->getName() => $this->field, + $this->fieldStorage->getName() => $this->fieldStorage, ))); } @@ -127,14 +134,14 @@ public function testCalculateDependencies() { ->with('test_entity_type') ->will($this->returnValue($target_entity_type)); - $this->field->expects($this->once()) + $this->fieldStorage->expects($this->once()) ->method('getConfigDependencyName') - ->will($this->returnValue('field.field.test_entity_type.test_field')); + ->will($this->returnValue('field.storage.test_entity_type.test_field')); - $values = array('field_name' => $this->field->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle'); + $values = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle'); $entity = new FieldInstanceConfig($values, $this->entityTypeId); $dependencies = $entity->calculateDependencies(); - $this->assertContains('field.field.test_entity_type.test_field', $dependencies['entity']); + $this->assertContains('field.storage.test_entity_type.test_field', $dependencies['entity']); $this->assertContains('test.test_entity_type.id', $dependencies['entity']); } @@ -142,7 +149,7 @@ public function testCalculateDependencies() { * @covers ::toArray() */ public function testToArray() { - $values = array('field_name' => $this->field->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle'); + $values = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle'); $instance = new FieldInstanceConfig($values, $this->entityTypeId); $expected = array( diff --git a/core/modules/field/tests/src/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/FieldStorageConfigEntityUnitTest.php similarity index 85% rename from core/modules/field/tests/src/FieldConfigEntityUnitTest.php rename to core/modules/field/tests/src/FieldStorageConfigEntityUnitTest.php index 0e1c723..59671d1 100644 --- a/core/modules/field/tests/src/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/FieldStorageConfigEntityUnitTest.php @@ -2,22 +2,22 @@ /** * @file - * Contains \Drupal\field\Tests\FieldConfigEntityUnitTest. + * Contains \Drupal\field\Tests\FieldStorageConfigEntityUnitTest. */ namespace Drupal\field\Tests; use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\Tests\UnitTestCase; /** - * @coversDefaultClass \Drupal\field\Entity\FieldConfig + * @coversDefaultClass \Drupal\field\Entity\FieldStorageConfig * * @group Drupal * @group Config */ -class FieldConfigEntityUnitTest extends UnitTestCase { +class FieldStorageConfigEntityUnitTest extends UnitTestCase { /** * The entity type used for testing. @@ -53,7 +53,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { public static function getInfo() { return array( 'description' => '', - 'name' => '\Drupal\field\Entity\FieldConfig unit test', + 'name' => '\Drupal\field\Entity\FieldStorageConfig unit test', 'group' => 'Entity', ); } @@ -90,7 +90,7 @@ public function testCalculateDependencies() { // Get definition is called three times. Twice in // ConfigEntityBase::addDependency() to get the provider of the field config - // entity type and once in FieldConfig::calculateDependencies() to get the + // entity type and once in FieldStorageConfig::calculateDependencies() to get the // provider of the entity type that field is attached to. $this->entityManager->expects($this->at(0)) ->method('getDefinition') @@ -106,9 +106,9 @@ public function testCalculateDependencies() { ->will($this->returnValue($fieldConfigentityType)); $values = array('name' => 'test_field', 'type' => 'test_field_type', 'entity_type' => $attached_entity_type_id, 'module' => 'test_module'); - $field = new FieldConfig($values, 'fieldConfig'); + $field_storage = new FieldStorageConfig($values, 'fieldConfig'); - $dependencies = $field->calculateDependencies(); + $dependencies = $field_storage->calculateDependencies(); $this->assertContains('test_module', $dependencies['module']); $this->assertContains('entity_provider_module', $dependencies['module']); } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 1dbee70..9fd1efb 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -110,7 +110,7 @@ function field_ui_entity_type_build(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ $entity_types['field_instance_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldInstanceConfigDeleteForm'); $entity_types['field_instance_config']->setListBuilderClass('Drupal\field_ui\FieldInstanceConfigListBuilder'); - $entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); + $entity_types['field_storage_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); foreach ($entity_types as $entity_type) { if ($bundle = $entity_type->getBundleOf()) { diff --git a/core/modules/field_ui/field_ui.routing.yml b/core/modules/field_ui/field_ui.routing.yml index 826150b..2b3672f 100644 --- a/core/modules/field_ui/field_ui.routing.yml +++ b/core/modules/field_ui/field_ui.routing.yml @@ -1,7 +1,7 @@ field_ui.list: path: '/admin/reports/fields' defaults: - _entity_list: 'field_config' + _entity_list: 'field_storage_config' _title: 'Field list' requirements: _permission: 'administer content types' diff --git a/core/modules/field_ui/src/FieldInstanceConfigListBuilder.php b/core/modules/field_ui/src/FieldInstanceConfigListBuilder.php index b801f4c..74252e0 100644 --- a/core/modules/field_ui/src/FieldInstanceConfigListBuilder.php +++ b/core/modules/field_ui/src/FieldInstanceConfigListBuilder.php @@ -62,11 +62,11 @@ public function getDefaultOperations(EntityInterface $entity) { /** @var \Drupal\field\FieldInstanceConfigInterface $entity */ $operations = parent::getDefaultOperations($entity); - $operations['field-settings'] = array( + $operations['storage-settings'] = array( 'title' => $this->t('Field settings'), 'weight' => 20, 'attributes' => array('title' => $this->t('Edit field settings.')), - ) + $entity->urlInfo('field-settings-form')->toArray(); + ) + $entity->urlInfo('storage-edit-form')->toArray(); $operations['edit']['attributes']['title'] = $this->t('Edit instance settings.'); $operations['delete']['attributes']['title'] = $this->t('Delete instance.'); diff --git a/core/modules/field_ui/src/FieldOverview.php b/core/modules/field_ui/src/FieldOverview.php index 300b317..6d0cf27e 100644 --- a/core/modules/field_ui/src/FieldOverview.php +++ b/core/modules/field_ui/src/FieldOverview.php @@ -15,7 +15,7 @@ use Drupal\Core\Render\Element; use Drupal\field_ui\OverviewBase; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\FieldInstanceConfigInterface; /** @@ -134,7 +134,7 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL 'type' => array( '#type' => 'link', '#title' => $field_types[$field->getType()]['label'], - '#route_name' => 'field_ui.field_edit_' . $this->entity_type, + '#route_name' => 'field_ui.storage_edit_' . $this->entity_type, '#route_parameters' => $route_parameters, '#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))), ), @@ -186,7 +186,7 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL '#description' => $this->t('A unique machine-readable name containing letters, numbers, and underscores.'), // Calculate characters depending on the length of the field prefix // setting. Maximum length is 32. - '#maxlength' => FieldConfig::NAME_MAX_LENGTH - strlen($field_prefix), + '#maxlength' => FieldStorageConfig::NAME_MAX_LENGTH - strlen($field_prefix), '#prefix' => '