Issue #2287727 by yched, swentel, alexpott: Rename Field[instance]Config classes and entity types (again).
parent
9c86984c3c
commit
a57630c83d
|
|
@ -85,12 +85,12 @@ interface ConfigEntityInterface extends EntityInterface {
|
|||
* 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
|
||||
* configuration entity, which is not a configuration change, and it must be
|
||||
* done whether due to an import or not. So, the first method should check
|
||||
* $entity->isSyncing() and skip executing if it returns TRUE, and the second
|
||||
* should not perform this check.
|
||||
* \Drupal\field\Entity\FieldStorageConfig::preSave() and the methods it calls
|
||||
* make sure that the storage tables are created or updated for the field
|
||||
* storage configuration entity, which is not a configuration change, and it
|
||||
* must be done whether due to an import or not. So, the first method should
|
||||
* check $entity->isSyncing() and skip executing if it returns TRUE, and the
|
||||
* second should not perform this check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the configuration entity is being created, updated, or deleted
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -1934,7 +1934,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
|
|||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
|||
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 @@ class Tables implements TablesInterface {
|
|||
// 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 @@ class Tables implements TablesInterface {
|
|||
// 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 @@ class Tables implements TablesInterface {
|
|||
$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);
|
||||
|
|
|
|||
|
|
@ -27,20 +27,20 @@ use Drupal\Core\TypedData\ListDataDefinitionInterface;
|
|||
* 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
|
||||
|
|
|
|||
|
|
@ -234,8 +234,8 @@ interface FieldItemInterface extends ComplexDataInterface {
|
|||
/**
|
||||
* 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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -26,9 +26,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.
|
||||
|
|
@ -54,15 +54,15 @@ class BlockContentFieldTest extends BlockContentTestBase {
|
|||
$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,
|
||||
|
|
@ -70,12 +70,12 @@ class BlockContentFieldTest extends BlockContentTestBase {
|
|||
));
|
||||
$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',
|
||||
))
|
||||
|
|
@ -85,8 +85,8 @@ class BlockContentFieldTest extends BlockContentTestBase {
|
|||
$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);
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
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();
|
||||
}
|
||||
|
|
@ -56,7 +56,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(
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
|||
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;
|
||||
|
|
@ -174,12 +174,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');
|
||||
}
|
||||
|
|
@ -646,7 +646,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.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use Drupal\Core\Routing\UrlGeneratorInterface;
|
|||
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 @@ class CommentManager implements CommentManagerInterface {
|
|||
))->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_storage = $this->entityManager->getStorage('field_storage_config')->create(array(
|
||||
'entity_type' => $entity_type,
|
||||
'name' => $field_name,
|
||||
'type' => 'comment',
|
||||
|
|
@ -170,7 +170,7 @@ class CommentManager implements CommentManagerInterface {
|
|||
),
|
||||
));
|
||||
// Create the field.
|
||||
$field->save();
|
||||
$field_storage->save();
|
||||
}
|
||||
// Make sure the instance doesn't already exist.
|
||||
if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) {
|
||||
|
|
@ -235,14 +235,14 @@ class CommentManager implements CommentManagerInterface {
|
|||
*/
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Drupal\comment;
|
|||
|
||||
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 @@ class CommentPostRenderCache {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use Drupal\comment\CommentInterface;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -302,7 +302,7 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
$fields['field_name'] = FieldDefinition::create('string')
|
||||
->setLabel(t('Comment field name'))
|
||||
->setDescription(t('The field name through which this comment was added.'))
|
||||
->setSetting('max_length', FieldConfig::NAME_MAX_LENGTH);
|
||||
->setSetting('max_length', FieldStorageConfig::NAME_MAX_LENGTH);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
@ -509,8 +509,8 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Drupal\Core\Entity\EntityConfirmFormBase;
|
|||
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 @@ class CommentTypeDeleteForm extends EntityConfirmFormBase {
|
|||
$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 .= '<p>' . $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(),
|
||||
)) . '</p>';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -41,8 +41,8 @@ class CommentFieldsTest extends CommentTestBase {
|
|||
$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';
|
||||
|
|
@ -51,15 +51,15 @@ class CommentFieldsTest extends CommentTestBase {
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -71,9 +71,9 @@ class CommentFieldsTest extends CommentTestBase {
|
|||
$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
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Drupal\comment\Tests;
|
|||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -70,10 +70,10 @@ class CommentLanguageTest extends WebTestBase {
|
|||
$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.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ class CommentNodeChangesTest extends CommentTestBase {
|
|||
$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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,9 +397,9 @@ class CommentNonNodeTest extends WebTestBase {
|
|||
$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();
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
|
|||
'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(
|
||||
|
|
@ -58,7 +58,7 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
|
|||
),
|
||||
'type' => 'comment',
|
||||
));
|
||||
$field->save();
|
||||
$field_storage->save();
|
||||
$this->fail('Did not throw an exception as expected.');
|
||||
}
|
||||
catch (\UnexpectedValueException $e) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Drupal\comment\Tests;
|
|||
|
||||
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.
|
||||
|
|
@ -68,9 +68,9 @@ class CommentTranslationUITest extends ContentTranslationUITest {
|
|||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Drupal\comment\Tests;
|
|||
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;
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ class CommentTypeTest extends CommentTestBase {
|
|||
$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);
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ class CommentTypeTest extends CommentTestBase {
|
|||
|
||||
// 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(
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
|
|
@ -38,15 +38,15 @@ class CommentUninstallTest extends WebTestBase {
|
|||
*/
|
||||
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.');
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -55,13 +55,13 @@ class CommentUninstallTest extends WebTestBase {
|
|||
*/
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class CommentValidationTest extends EntityUnitTestBase {
|
|||
))->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',
|
||||
|
|
|
|||
|
|
@ -63,27 +63,28 @@ class ConfigExportImportUITest extends WebTestBase {
|
|||
$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');
|
||||
|
|
@ -97,18 +98,18 @@ class ConfigExportImportUITest extends WebTestBase {
|
|||
// 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();
|
||||
|
|
@ -119,7 +120,7 @@ class ConfigExportImportUITest extends WebTestBase {
|
|||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -71,8 +71,8 @@ class ConfigImportAllTest extends ModuleTestBase {
|
|||
// 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);
|
||||
$field_storages = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple();
|
||||
\Drupal::entityManager()->getStorage('field_storage_config')->delete($field_storages);
|
||||
// Purge the data.
|
||||
field_purge_batch(1000);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,21 +25,21 @@ 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;
|
||||
|
||||
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',
|
||||
|
|
@ -47,7 +47,7 @@ class ContactFieldsTest extends ViewTestBase {
|
|||
))->save();
|
||||
|
||||
entity_create('field_instance_config', array(
|
||||
'field' => $this->field,
|
||||
'field_storage' => $this->field_storage,
|
||||
'bundle' => 'contact_message',
|
||||
))->save();
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ class ContactFieldsTest extends ViewTestBase {
|
|||
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.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -683,7 +683,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.
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ class ContentTranslationSettingsTest extends WebTestBase {
|
|||
'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',
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
|
|||
$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',
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ abstract class ContentTranslationTestBase extends WebTestBase {
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -26,11 +26,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.
|
||||
|
|
@ -52,22 +52,22 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
$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();
|
||||
|
|
@ -78,7 +78,7 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
'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();
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
* Tests date field functionality.
|
||||
*/
|
||||
function testDateField() {
|
||||
$field_name = $this->field->name;
|
||||
$field_name = $this->fieldStorage->name;
|
||||
|
||||
// Display creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
|
|
@ -153,10 +153,10 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
* 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');
|
||||
|
|
@ -220,10 +220,10 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
* 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')
|
||||
|
|
@ -288,17 +288,17 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
// 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();
|
||||
|
|
@ -307,14 +307,14 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
$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('<option value="now" selected="selected">The current date</option>', '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.
|
||||
|
|
@ -323,20 +323,20 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
// 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('<option value="" selected="selected">' . t('- None -') . '</option>', '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.
|
||||
|
|
@ -344,7 +344,7 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
|
||||
// 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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -353,9 +353,9 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
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');
|
||||
|
|
|
|||
|
|
@ -29,15 +29,15 @@ class DateTimeItemTest extends FieldUnitTestBase {
|
|||
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',
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
$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.");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,15 +140,15 @@ class EntityDisplayTest extends DrupalUnitTestBase {
|
|||
$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();
|
||||
|
|
@ -161,7 +161,7 @@ class EntityDisplayTest extends DrupalUnitTestBase {
|
|||
|
||||
// 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(
|
||||
|
|
@ -317,15 +317,15 @@ class EntityDisplayTest extends DrupalUnitTestBase {
|
|||
$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();
|
||||
|
|
|
|||
|
|
@ -49,16 +49,16 @@ class EntityFormDisplayTest extends DrupalUnitTestBase {
|
|||
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();
|
||||
|
|
@ -71,7 +71,7 @@ class EntityFormDisplayTest extends DrupalUnitTestBase {
|
|||
|
||||
// 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(
|
||||
|
|
@ -180,15 +180,15 @@ class EntityFormDisplayTest extends DrupalUnitTestBase {
|
|||
$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();
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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())),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Drupal\Core\Session\AccountInterface;
|
|||
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 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
|
|||
$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',
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
|
|||
$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,
|
||||
|
|
|
|||
|
|
@ -42,15 +42,15 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
|
|||
// 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',
|
||||
|
|
@ -64,16 +64,16 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
|
|||
|
||||
// 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');
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
|
|||
|
||||
// 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -47,20 +45,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.
|
||||
*
|
||||
|
|
@ -85,8 +69,6 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
|
|||
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
|
||||
);
|
||||
|
||||
$this->field = FieldConfig::loadByName($this->entityType, $this->fieldName);
|
||||
$this->instance = FieldInstanceConfig::loadByName($this->entityType, $this->bundle, $this->fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
|
|||
|
||||
// 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',
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
|
|||
* 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,
|
||||
|
|
@ -67,9 +67,9 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
|
|||
'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',
|
||||
|
|
@ -198,8 +198,8 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
|
|||
* 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,
|
||||
|
|
@ -209,9 +209,9 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
|
|||
'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',
|
||||
|
|
@ -342,8 +342,8 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
|
|||
* 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,
|
||||
|
|
@ -354,9 +354,9 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
|
|||
'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',
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
|
|||
*/
|
||||
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',
|
||||
|
|
@ -48,8 +48,8 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
|
|||
))->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,
|
||||
|
|
@ -59,9 +59,9 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
|
|||
'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(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -53,7 +53,7 @@ class EntityReferenceRelationshipTest extends ViewUnitTestBase {
|
|||
|
||||
ViewTestData::createTestViews(get_class($this), array('entity_reference_test_views'));
|
||||
|
||||
$field = FieldConfig::create(array(
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'settings' => array(
|
||||
'target_type' => 'entity_test',
|
||||
),
|
||||
|
|
@ -62,7 +62,7 @@ class EntityReferenceRelationshipTest extends ViewUnitTestBase {
|
|||
'type' => 'entity_reference',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
));
|
||||
$field->save();
|
||||
$field_storage->save();
|
||||
|
||||
$instance = FieldInstanceConfig::create(array(
|
||||
'entity_type' => 'entity_test',
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ class SelectionTest extends WebTestBase {
|
|||
$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,
|
||||
|
|
@ -44,9 +44,9 @@ class SelectionTest extends WebTestBase {
|
|||
'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',
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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,47 +249,47 @@ 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.
|
||||
*
|
||||
* @see entity_crud
|
||||
*/
|
||||
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 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 storage 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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,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;
|
||||
|
||||
|
|
@ -163,15 +163,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;
|
||||
}
|
||||
|
|
@ -324,11 +324,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.
|
||||
|
|
@ -348,16 +348,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))
|
||||
|
|
|
|||
|
|
@ -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 @@ use Drupal\field\FieldException;
|
|||
*
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace Drupal\field;
|
|||
|
||||
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 @@ class ConfigImporterFieldPurger {
|
|||
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
|
||||
// case when the field deletion is staged.
|
||||
if (!$field->deleted) {
|
||||
$field->delete();
|
||||
// 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 storage deletion is staged.
|
||||
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 @@ class ConfigImporterFieldPurger {
|
|||
$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 @@ class ConfigImporterFieldPurger {
|
|||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
|||
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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
* {@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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
$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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
* {@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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
* {@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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
|
|||
$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'])) {
|
||||
|
|
|
|||
|
|
@ -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\Config\Entity\ConfigEntityBase;
|
|||
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,24 @@ 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.
|
||||
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 +263,12 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
|
|||
// 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 +278,13 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
|
|||
// 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 +322,10 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
|
|||
|
||||
// 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 +333,8 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
|
|||
$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 +388,17 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
|
|||
|
||||
// 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 +739,7 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
|
|||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\FieldConfigInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\field;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a field entity.
|
||||
*/
|
||||
interface FieldConfigInterface extends ConfigEntityInterface, FieldStorageDefinitionInterface {
|
||||
|
||||
/**
|
||||
* Returns the list of bundles where the field has instances.
|
||||
*
|
||||
* @return array
|
||||
* An array of bundle names.
|
||||
*/
|
||||
public function getBundles();
|
||||
|
||||
/**
|
||||
* Returns whether the field is locked or not.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the field is locked.
|
||||
*/
|
||||
public function isLocked();
|
||||
|
||||
}
|
||||
|
|
@ -18,8 +18,8 @@ interface FieldInstanceConfigInterface extends ConfigEntityInterface, FieldDefin
|
|||
/**
|
||||
* Returns the field entity for this instance.
|
||||
*
|
||||
* @return \Drupal\field\FieldConfigInterface
|
||||
* The field entity for this instance.
|
||||
* @return \Drupal\field\FieldStorageConfigInterface
|
||||
* The field storage entity for this instance.
|
||||
*/
|
||||
public function getFieldStorageDefinition();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,11 @@ use Drupal\Core\Config\Config;
|
|||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
use Drupal\Core\Extension\ModuleHandler;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -124,11 +122,11 @@ class FieldInstanceConfigStorage extends ConfigEntityStorage {
|
|||
// Merge deleted instances (stored in state) if needed.
|
||||
if ($include_deleted || !empty($conditions['deleted'])) {
|
||||
$deleted_instances = $this->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);
|
||||
}
|
||||
|
|
@ -138,19 +136,19 @@ class FieldInstanceConfigStorage extends ConfigEntityStorage {
|
|||
$matching_instances = array();
|
||||
foreach ($instances as $instance) {
|
||||
// Some conditions are checked against the field.
|
||||
$field = $instance->getFieldStorageDefinition();
|
||||
$field_storage = $instance->getFieldStorageDefinition();
|
||||
|
||||
// Only keep the instance if it matches all conditions.
|
||||
foreach ($conditions as $key => $value) {
|
||||
// Extract the actual value against which the condition is checked.
|
||||
switch ($key) {
|
||||
case 'field_name':
|
||||
$checked_value = $field->name;
|
||||
$checked_value = $field_storage->name;
|
||||
break;
|
||||
|
||||
case 'field_id':
|
||||
case 'field_uuid':
|
||||
$checked_value = $field->uuid();
|
||||
case 'field_storage_uuid':
|
||||
$checked_value = $field_storage->uuid();
|
||||
break;
|
||||
|
||||
case 'uuid';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\FieldStorageConfigInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\field;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a field storage entity.
|
||||
*/
|
||||
interface FieldStorageConfigInterface extends ConfigEntityInterface, FieldStorageDefinitionInterface {
|
||||
|
||||
/**
|
||||
* Returns the list of bundles where the field storage has fields.
|
||||
*
|
||||
* @return array
|
||||
* An array of bundle names.
|
||||
*/
|
||||
public function getBundles();
|
||||
|
||||
/**
|
||||
* Returns whether the field storage is locked or not.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the field storage is locked.
|
||||
*/
|
||||
public function isLocked();
|
||||
|
||||
}
|
||||
|
|
@ -2,17 +2,15 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\FieldConfigStorage.
|
||||
* Contains \Drupal\field\FieldStorageConfigStorage.
|
||||
*/
|
||||
|
||||
namespace Drupal\field;
|
||||
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Config\Config;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
|
|
@ -21,9 +19,9 @@ use Drupal\Core\Extension\ModuleHandler;
|
|||
use Drupal\Core\State\StateInterface;
|
||||
|
||||
/**
|
||||
* Controller class for fields.
|
||||
* Controller class for "field storage" configuration entities.
|
||||
*/
|
||||
class FieldConfigStorage extends ConfigEntityStorage {
|
||||
class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
|
|
@ -47,7 +45,7 @@ class FieldConfigStorage extends ConfigEntityStorage {
|
|||
protected $state;
|
||||
|
||||
/**
|
||||
* Constructs a FieldConfigStorage object.
|
||||
* Constructs a FieldStorageConfigStorage object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type definition.
|
||||
|
|
@ -97,34 +95,34 @@ class FieldConfigStorage extends ConfigEntityStorage {
|
|||
$include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE;
|
||||
unset($conditions['include_deleted']);
|
||||
|
||||
$fields = array();
|
||||
$storages = array();
|
||||
|
||||
// Get fields stored in configuration. If we are explicitly looking for
|
||||
// deleted fields only, this can be skipped, because they will be retrieved
|
||||
// from state below.
|
||||
// Get field storages living in configuration. If we are explicitly looking
|
||||
// for deleted storages only, this can be skipped, because they will be
|
||||
// retrieved from state below.
|
||||
if (empty($conditions['deleted'])) {
|
||||
if (isset($conditions['entity_type']) && isset($conditions['field_name'])) {
|
||||
// Optimize for the most frequent case where we do have a specific ID.
|
||||
$id = $conditions['entity_type'] . $conditions['field_name'];
|
||||
$fields = $this->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 @@ class FieldConfigStorage extends ConfigEntityStorage {
|
|||
// 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\FieldStorageConfigUpdateForbiddenException.
|
||||
*/
|
||||
|
||||
namespace Drupal\field;
|
||||
|
||||
/**
|
||||
* Exception class thrown by hook_field_storage_config_update_forbid().
|
||||
*/
|
||||
class FieldStorageConfigUpdateForbiddenException extends FieldException {}
|
||||
|
|
@ -36,8 +36,8 @@ class FieldList extends Numeric {
|
|||
parent::init($view, $display, $options);
|
||||
|
||||
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
|
||||
$field = $field_storage_definitions[$this->definition['field_name']];
|
||||
$this->allowed_values = options_allowed_values($field);
|
||||
$field_storage = $field_storage_definitions[$this->definition['field_name']];
|
||||
$this->allowed_values = options_allowed_values($field_storage);
|
||||
}
|
||||
|
||||
protected function defineOptions() {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ class ListString extends String {
|
|||
parent::init($view, $display, $options);
|
||||
|
||||
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
|
||||
$field = $field_storage_definitions[$this->definition['field_name']];
|
||||
$this->allowed_values = options_allowed_values($field);
|
||||
$field_storage = $field_storage_definitions[$this->definition['field_name']];
|
||||
$this->allowed_values = options_allowed_values($field_storage);
|
||||
}
|
||||
|
||||
protected function defineOptions() {
|
||||
|
|
|
|||
|
|
@ -55,8 +55,10 @@ class Field extends FieldPluginBase {
|
|||
|
||||
/**
|
||||
* The field config.
|
||||
*
|
||||
* @var \Drupal\field\FieldStorageConfigInterface
|
||||
*/
|
||||
protected $fieldConfig;
|
||||
protected $fieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Does the field supports multiple field values.
|
||||
|
|
@ -153,8 +155,8 @@ class Field extends FieldPluginBase {
|
|||
*/
|
||||
protected function getFieldDefinition() {
|
||||
if (!$this->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;
|
||||
}
|
||||
|
|
@ -162,14 +164,14 @@ class Field extends FieldPluginBase {
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -351,8 +353,8 @@ class Field extends FieldPluginBase {
|
|||
|
||||
$this->ensureMyTable();
|
||||
$field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->definition['entity_type']);
|
||||
$field = $field_storage_definitions[$this->definition['field_name']];
|
||||
$column = ContentEntityDatabaseStorage::_fieldColumnName($field, $this->options['click_sort_column']);
|
||||
$field_storage = $field_storage_definitions[$this->definition['field_name']];
|
||||
$column = ContentEntityDatabaseStorage::_fieldColumnName($field_storage, $this->options['click_sort_column']);
|
||||
if (!isset($this->aliases[$column])) {
|
||||
// Column is not in query; add a sort on it (without adding the column).
|
||||
$this->aliases[$column] = $this->tableAlias . '.' . $column;
|
||||
|
|
@ -364,9 +366,9 @@ class Field extends FieldPluginBase {
|
|||
$options = parent::defineOptions();
|
||||
|
||||
$field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->definition['entity_type']);
|
||||
$field = $field_storage_definitions[$this->definition['field_name']];
|
||||
$field_type = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType());
|
||||
$column_names = array_keys($field->getColumns());
|
||||
$field_storage = $field_storage_definitions[$this->definition['field_name']];
|
||||
$field_type = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->getType());
|
||||
$column_names = array_keys($field_storage->getColumns());
|
||||
$default_column = '';
|
||||
// Try to determine a sensible default.
|
||||
if (count($column_names) == 1) {
|
||||
|
|
@ -401,7 +403,7 @@ class Field extends FieldPluginBase {
|
|||
// If we know the exact number of allowed values, then that can be
|
||||
// the default. Otherwise, default to 'all'.
|
||||
$options['delta_limit'] = array(
|
||||
'default' => ($field->getCardinality() > 1) ? $field->getCardinality() : 'all',
|
||||
'default' => ($field_storage->getCardinality() > 1) ? $field_storage->getCardinality() : 'all',
|
||||
);
|
||||
$options['delta_offset'] = array(
|
||||
'default' => 0,
|
||||
|
|
@ -937,8 +939,8 @@ class Field extends FieldPluginBase {
|
|||
* {@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()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ class FieldList extends ManyToOne {
|
|||
|
||||
public function getValueOptions() {
|
||||
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
|
||||
$field = $field_storage_definitions[$this->definition['field_name']];
|
||||
$this->value_options = list_allowed_values($field);
|
||||
$field_storage = $field_storage_definitions[$this->definition['field_name']];
|
||||
$this->value_options = list_allowed_values($field_storage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\field\Tests\Boolean;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldInstanceConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ class BooleanFieldTest extends WebTestBase {
|
|||
/**
|
||||
* A field to use in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldConfig
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ class BooleanFieldTest extends WebTestBase {
|
|||
|
||||
// Create a field with settings to validate.
|
||||
$field_name = drupal_strtolower($this->randomName());
|
||||
$this->field = FieldConfig::create(array(
|
||||
$this->field = FieldStorageConfig::create(array(
|
||||
'name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'boolean',
|
||||
|
|
@ -169,7 +169,7 @@ class BooleanFieldTest extends WebTestBase {
|
|||
);
|
||||
|
||||
// Test the boolean field settings.
|
||||
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/field');
|
||||
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/storage');
|
||||
$this->assertFieldById('edit-field-settings-on-label', $on);
|
||||
$this->assertFieldById('edit-field-settings-off-label', $off);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class BooleanItemTest extends FieldUnitTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create an boolean field and instance for validation.
|
||||
entity_create('field_config', array(
|
||||
entity_create('field_storage_config', array(
|
||||
'name' => 'field_boolean',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'boolean',
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ namespace Drupal\field\Tests;
|
|||
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\field\Entity\FieldInstanceConfig;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Bulk delete fields and instances, and clean up afterwards.
|
||||
|
|
@ -25,7 +23,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fields;
|
||||
protected $fieldStorages;
|
||||
|
||||
/**
|
||||
* The entities to use in this test.
|
||||
|
|
@ -97,7 +95,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fields = array();
|
||||
$this->fieldStorages = array();
|
||||
$this->entities = array();
|
||||
$this->entities_by_bundles = array();
|
||||
|
||||
|
|
@ -108,36 +106,36 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
|
@ -159,8 +157,8 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
*/
|
||||
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.
|
||||
|
|
@ -170,24 +168,24 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
$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.
|
||||
|
|
@ -217,10 +215,10 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
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.
|
||||
|
|
@ -235,7 +233,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
// 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');
|
||||
}
|
||||
|
|
@ -252,34 +250,35 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
$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.
|
||||
|
|
@ -310,13 +309,13 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
// 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.
|
||||
|
|
@ -335,20 +334,20 @@ class BulkDeleteTest extends FieldUnitTestBase {
|
|||
}
|
||||
$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.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ namespace Drupal\field\Tests;
|
|||
|
||||
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 create, read, update, and delete.
|
||||
* Tests field storage create, read, update, and delete.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
|
|
@ -32,42 +32,42 @@ class CrudTest extends FieldUnitTestBase {
|
|||
// 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) {
|
||||
|
|
@ -76,11 +76,11 @@ class CrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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) {
|
||||
|
|
@ -89,11 +89,11 @@ class CrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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) {
|
||||
|
|
@ -101,11 +101,11 @@ class CrudTest extends FieldUnitTestBase {
|
|||
}
|
||||
// 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) {
|
||||
|
|
@ -114,12 +114,12 @@ class CrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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) {
|
||||
|
|
@ -128,12 +128,12 @@ class CrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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) {
|
||||
|
|
@ -142,12 +142,12 @@ class CrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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) {
|
||||
|
|
@ -157,12 +157,12 @@ class CrudTest extends FieldUnitTestBase {
|
|||
// 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) {
|
||||
|
|
@ -171,50 +171,50 @@ class CrudTest extends FieldUnitTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
);
|
||||
|
|
@ -224,60 +224,57 @@ class CrudTest extends FieldUnitTestBase {
|
|||
/**
|
||||
* 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).
|
||||
|
|
@ -286,13 +283,13 @@ class CrudTest extends FieldUnitTestBase {
|
|||
'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(
|
||||
|
|
@ -306,14 +303,14 @@ class CrudTest extends FieldUnitTestBase {
|
|||
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.
|
||||
|
|
@ -321,53 +318,52 @@ class CrudTest extends FieldUnitTestBase {
|
|||
$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) {
|
||||
|
|
@ -376,22 +372,22 @@ class CrudTest extends FieldUnitTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
));
|
||||
|
|
@ -406,22 +402,22 @@ class CrudTest extends FieldUnitTestBase {
|
|||
}
|
||||
// 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',
|
||||
|
|
@ -429,18 +425,18 @@ class CrudTest extends FieldUnitTestBase {
|
|||
'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) {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class DisplayApiTest extends FieldUnitTestBase {
|
|||
$this->label = $this->randomName();
|
||||
$this->cardinality = 4;
|
||||
|
||||
$field = array(
|
||||
$field_storage = array(
|
||||
'name' => $this->field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'test_field',
|
||||
|
|
@ -94,7 +94,7 @@ class DisplayApiTest extends FieldUnitTestBase {
|
|||
),
|
||||
);
|
||||
|
||||
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')
|
||||
|
|
|
|||
|
|
@ -24,11 +24,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.
|
||||
|
|
@ -54,14 +54,14 @@ class EmailFieldTest extends WebTestBase {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class EmailItemTest extends FieldUnitTestBase {
|
|||
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',
|
||||
|
|
|
|||
|
|
@ -45,14 +45,14 @@ class FieldAccessTest extends FieldTestBase {
|
|||
$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,
|
||||
);
|
||||
|
|
@ -61,7 +61,7 @@ class FieldAccessTest extends FieldTestBase {
|
|||
// 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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
$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.
|
||||
|
|
@ -64,7 +64,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
'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(
|
||||
|
|
@ -74,7 +74,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
'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);
|
||||
|
|
@ -91,14 +91,14 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
// 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->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->render($content);
|
||||
$this->assertNoRaw($this->instance->getLabel(), "Hidden field: label is not displayed.");
|
||||
|
|
@ -109,7 +109,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
// 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(
|
||||
|
|
@ -127,7 +127,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
// 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(
|
||||
|
|
@ -178,7 +178,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
function testEntityCache() {
|
||||
// Initialize random values and a test entity.
|
||||
$entity_init = entity_create('entity_test', array('type' => $this->instance->bundle));
|
||||
$values = $this->_generateTestFieldValues($this->field->getCardinality());
|
||||
$values = $this->_generateTestFieldValues($this->field_storage->getCardinality());
|
||||
|
||||
// Non-cacheable entity type.
|
||||
$entity_type = 'entity_test';
|
||||
|
|
@ -221,7 +221,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
$this->assertEqual($cache->data, $cached_entity, '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');
|
||||
|
|
@ -233,7 +233,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
$this->assertEqual($cache->data, $cached_entity, '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();
|
||||
|
|
@ -270,11 +270,11 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
|
||||
$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");
|
||||
}
|
||||
|
|
@ -292,7 +292,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
|
||||
$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");
|
||||
}
|
||||
|
|
@ -317,11 +317,11 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
// 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;
|
||||
|
|
@ -331,11 +331,11 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
|
|||
// 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;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
|
|||
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.
|
||||
|
|
@ -108,13 +108,13 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
|
|||
);
|
||||
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],
|
||||
|
|
@ -235,7 +235,7 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
|
|||
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();
|
||||
|
||||
|
|
@ -293,7 +293,7 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
|
|||
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());
|
||||
|
|
@ -344,13 +344,13 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
|
|||
|
||||
// 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,
|
||||
|
|
@ -363,7 +363,7 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
|
|||
|
||||
// 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);
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ namespace Drupal\field\Tests;
|
|||
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
|
||||
|
||||
/**
|
||||
* Tests counting field data records and the hasData() method on FieldConfig
|
||||
* entity.
|
||||
* Tests counting field data records and the hasData() method on
|
||||
* FieldStorageConfig entity.
|
||||
*
|
||||
* @group field
|
||||
* @see \Drupal\Core\Entity\FieldableEntityStorageInterface::countFieldData()
|
||||
* @see \Drupal\field\Entity\FieldConfig::hasData()
|
||||
* @see \Drupal\field\Entity\FieldStorageConfig::hasData()
|
||||
*/
|
||||
class FieldDataCountTest extends FieldUnitTestBase {
|
||||
|
||||
|
|
@ -38,29 +38,29 @@ class FieldDataCountTest extends FieldUnitTestBase {
|
|||
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++) {
|
||||
|
|
@ -76,7 +76,7 @@ class FieldDataCountTest extends FieldUnitTestBase {
|
|||
$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()
|
||||
|
|
@ -85,17 +85,17 @@ class FieldDataCountTest extends FieldUnitTestBase {
|
|||
$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.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ class FieldImportCreateTest extends FieldUnitTestBase {
|
|||
$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));
|
||||
|
||||
|
|
@ -41,14 +41,14 @@ class FieldImportCreateTest extends FieldUnitTestBase {
|
|||
\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.');
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ class FieldImportCreateTest extends FieldUnitTestBase {
|
|||
$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_storage_config_name = "field.storage.$field_id";
|
||||
$instance_config_name = "field.instance.$instance_id";
|
||||
|
||||
// One field with two field instances.
|
||||
|
|
@ -84,7 +84,7 @@ class FieldImportCreateTest extends FieldUnitTestBase {
|
|||
$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_storage_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";
|
||||
|
||||
|
|
@ -95,9 +95,9 @@ class FieldImportCreateTest extends FieldUnitTestBase {
|
|||
// Add the new files to the staging directory.
|
||||
$src_dir = drupal_get_path('module', 'field_test_config') . '/staging';
|
||||
$target_dir = $this->configDirectories[CONFIG_STAGING_DIRECTORY];
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$field_config_name.yml", "$target_dir/$field_config_name.yml"));
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$field_storage_config_name.yml", "$target_dir/$field_storage_config_name.yml"));
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$instance_config_name.yml", "$target_dir/$instance_config_name.yml"));
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$field_config_name_2.yml", "$target_dir/$field_config_name_2.yml"));
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$field_storage_config_name_2.yml", "$target_dir/$field_storage_config_name_2.yml"));
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$instance_config_name_2a.yml", "$target_dir/$instance_config_name_2a.yml"));
|
||||
$this->assertTrue(file_unmanaged_copy("$src_dir/$instance_config_name_2b.yml", "$target_dir/$instance_config_name_2b.yml"));
|
||||
|
||||
|
|
@ -105,12 +105,12 @@ class FieldImportCreateTest extends FieldUnitTestBase {
|
|||
$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);
|
||||
|
|
|
|||
|
|
@ -29,21 +29,21 @@ class FieldImportDeleteTest extends FieldUnitTestBase {
|
|||
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";
|
||||
|
|
@ -54,15 +54,15 @@ class FieldImportDeleteTest extends FieldUnitTestBase {
|
|||
// 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)));
|
||||
|
|
@ -74,10 +74,10 @@ class FieldImportDeleteTest extends FieldUnitTestBase {
|
|||
$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);
|
||||
|
|
@ -87,22 +87,22 @@ class FieldImportDeleteTest extends FieldUnitTestBase {
|
|||
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,28 +40,26 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
// 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();
|
||||
|
||||
|
|
@ -81,7 +79,7 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
|
||||
// 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');
|
||||
|
|
@ -93,7 +91,7 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
$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();
|
||||
|
|
@ -104,10 +102,10 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
$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.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,15 +113,15 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
*/
|
||||
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();
|
||||
|
||||
|
|
@ -142,7 +140,7 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
}
|
||||
|
||||
// Delete the field.
|
||||
$field->delete();
|
||||
$field_storage->delete();
|
||||
|
||||
$active = $this->container->get('config.storage');
|
||||
$staging = $this->container->get('config.storage.staging');
|
||||
|
|
@ -153,8 +151,8 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
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.');
|
||||
|
|
@ -164,8 +162,8 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
|
|||
$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.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,28 +37,26 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
|
|||
*/
|
||||
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();
|
||||
|
||||
|
|
@ -73,7 +71,7 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
|
|||
// 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();
|
||||
|
|
@ -91,7 +89,7 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
|
|||
$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
|
||||
|
|
@ -111,10 +109,10 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
|
|||
$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.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -20,38 +20,38 @@ use Drupal\field\FieldException;
|
|||
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;
|
||||
|
||||
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',
|
||||
);
|
||||
|
|
@ -67,7 +67,7 @@ class FieldInstanceCrudTest extends FieldUnitTestBase {
|
|||
* 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
|
||||
|
|
@ -78,18 +78,18 @@ class FieldInstanceCrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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) {
|
||||
|
|
@ -98,8 +98,8 @@ class FieldInstanceCrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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) {
|
||||
|
|
@ -113,30 +113,30 @@ class FieldInstanceCrudTest extends FieldUnitTestBase {
|
|||
* 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');
|
||||
|
|
@ -154,24 +154,24 @@ class FieldInstanceCrudTest extends FieldUnitTestBase {
|
|||
|
||||
// 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.
|
||||
|
|
@ -183,41 +183,40 @@ class FieldInstanceCrudTest extends FieldUnitTestBase {
|
|||
* 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,22 +54,22 @@ abstract class FieldUnitTestBase extends DrupalUnitTestBase {
|
|||
$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',
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class FieldValidationTest extends FieldUnitTestBase {
|
|||
* 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++) {
|
||||
|
|
@ -55,7 +55,7 @@ class FieldValidationTest extends FieldUnitTestBase {
|
|||
* 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.
|
||||
|
|
|
|||
|
|
@ -29,21 +29,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.
|
||||
|
|
@ -58,18 +58,18 @@ class FormTest extends FieldTestBase {
|
|||
$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',
|
||||
|
|
@ -89,10 +89,10 @@ class FormTest extends FieldTestBase {
|
|||
}
|
||||
|
||||
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)
|
||||
|
|
@ -171,12 +171,12 @@ class FormTest extends FieldTestBase {
|
|||
* 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)
|
||||
|
|
@ -202,11 +202,11 @@ class FormTest extends FieldTestBase {
|
|||
}
|
||||
|
||||
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)
|
||||
|
|
@ -246,15 +246,15 @@ class FormTest extends FieldTestBase {
|
|||
// $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)
|
||||
|
|
@ -337,17 +337,17 @@ class FormTest extends FieldTestBase {
|
|||
*/
|
||||
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',
|
||||
|
|
@ -384,10 +384,10 @@ class FormTest extends FieldTestBase {
|
|||
}
|
||||
|
||||
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)
|
||||
|
|
@ -445,10 +445,10 @@ class FormTest extends FieldTestBase {
|
|||
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(
|
||||
|
|
@ -492,14 +492,14 @@ class FormTest extends FieldTestBase {
|
|||
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)
|
||||
|
|
@ -507,19 +507,19 @@ class FormTest extends FieldTestBase {
|
|||
|
||||
// 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)
|
||||
|
|
@ -581,14 +581,14 @@ class FormTest extends FieldTestBase {
|
|||
*/
|
||||
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
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ class NestedFormTest extends FieldTestBase {
|
|||
$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',
|
||||
|
|
@ -57,8 +57,8 @@ class NestedFormTest extends FieldTestBase {
|
|||
*/
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -23,20 +23,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.
|
||||
*
|
||||
|
|
@ -57,7 +43,7 @@ class NumberFieldTest extends WebTestBase {
|
|||
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',
|
||||
|
|
@ -149,7 +135,7 @@ class NumberFieldTest extends WebTestBase {
|
|||
|
||||
// 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',
|
||||
|
|
@ -253,7 +239,7 @@ class NumberFieldTest extends WebTestBase {
|
|||
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',
|
||||
|
|
@ -352,13 +338,13 @@ class NumberFieldTest extends WebTestBase {
|
|||
// 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',
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class NumberItemTest extends FieldUnitTestBase {
|
|||
|
||||
// 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,
|
||||
|
|
|
|||
|
|
@ -35,18 +35,16 @@ class ShapeItemTest extends FieldUnitTestBase {
|
|||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,18 +36,16 @@ class TestItemTest extends FieldUnitTestBase {
|
|||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -57,11 +57,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.
|
||||
|
|
@ -86,11 +86,11 @@ class TranslationTest extends FieldUnitTestBase {
|
|||
'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);
|
||||
|
|
@ -122,7 +122,7 @@ class TranslationTest extends FieldUnitTestBase {
|
|||
$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]);
|
||||
}
|
||||
|
||||
|
|
@ -142,11 +142,11 @@ class TranslationTest extends FieldUnitTestBase {
|
|||
$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();
|
||||
|
|
@ -158,7 +158,7 @@ class TranslationTest extends FieldUnitTestBase {
|
|||
$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]);
|
||||
}
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ class TranslationTest extends FieldUnitTestBase {
|
|||
$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;
|
||||
|
|
|
|||
|
|
@ -38,11 +38,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.
|
||||
|
|
@ -63,11 +63,11 @@ class TranslationWebTest extends FieldTestBase {
|
|||
'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();
|
||||
|
|
@ -97,7 +97,7 @@ class TranslationWebTest extends FieldTestBase {
|
|||
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);
|
||||
|
|
@ -126,7 +126,7 @@ class TranslationWebTest extends FieldTestBase {
|
|||
* 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;
|
||||
|
|
|
|||
|
|
@ -15,11 +15,6 @@ use Drupal\Core\Entity\ContentEntityDatabaseStorage;
|
|||
*/
|
||||
class ApiDataTest extends FieldTestBase {
|
||||
|
||||
/**
|
||||
* Stores the fields for this test case.
|
||||
*/
|
||||
var $fields;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
|
@ -55,9 +50,9 @@ class ApiDataTest extends FieldTestBase {
|
|||
|
||||
// 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ abstract class FieldTestBase extends ViewTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fields;
|
||||
public $fieldStorages;
|
||||
|
||||
/**
|
||||
* Stores the instances of the fields. They have
|
||||
|
|
@ -66,25 +66,22 @@ abstract class FieldTestBase extends ViewTestBase {
|
|||
$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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,21 +42,21 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
|||
$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();
|
||||
|
||||
|
|
@ -66,14 +66,14 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
|||
$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);
|
||||
}
|
||||
|
|
@ -89,8 +89,8 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
|||
*/
|
||||
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;
|
||||
|
|
@ -111,7 +111,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
|||
// 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);
|
||||
|
|
@ -125,8 +125,8 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
|||
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);
|
||||
|
|
@ -134,14 +134,14 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
|||
// 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);
|
||||
|
|
@ -161,7 +161,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -43,14 +43,14 @@ class reEnableModuleFieldTest extends WebTestBase {
|
|||
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();
|
||||
|
|
@ -90,7 +90,7 @@ class reEnableModuleFieldTest extends WebTestBase {
|
|||
$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();
|
||||
|
|
|
|||
|
|
@ -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'");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
|
||||
/**
|
||||
* @file
|
||||
|
|
@ -59,14 +59,14 @@ function field_test_permission() {
|
|||
* field_test_memorize();
|
||||
*
|
||||
* // call some Field API functions that invoke field_test hooks
|
||||
* entity_create('field_config', $field_definition)->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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 @@ class TestItem extends FieldItemBase {
|
|||
* {@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;
|
||||
|
|
|
|||
|
|
@ -11,3 +11,6 @@ default_value_function: ''
|
|||
settings:
|
||||
text_processing: 0
|
||||
field_type: text
|
||||
dependencies:
|
||||
entity:
|
||||
- field.storage.entity_test.field_test_import
|
||||
|
|
|
|||
|
|
@ -11,3 +11,6 @@ default_value_function: ''
|
|||
settings:
|
||||
text_processing: 0
|
||||
field_type: text
|
||||
dependencies:
|
||||
entity:
|
||||
- field.storage.entity_test.field_test_import_2
|
||||
|
|
|
|||
|
|
@ -11,3 +11,6 @@ default_value_function: ''
|
|||
settings:
|
||||
text_processing: 0
|
||||
field_type: text
|
||||
dependencies:
|
||||
entity:
|
||||
- field.storage.entity_test.field_test_import_2
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue