Update to Drupal 8.1.9. For more information, see https://www.drupal.org/project/drupal/releases/8.1.9
This commit is contained in:
parent
f9f23cdf38
commit
09b113657a
125 changed files with 2307 additions and 385 deletions
|
@ -3,12 +3,12 @@
|
|||
namespace Drupal\field\Plugin\migrate\process;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\StaticMap;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
|
|||
/**
|
||||
* The cckfield plugin manager.
|
||||
*
|
||||
* @var \Drupal\Component\Plugin\PluginManagerInterface
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
|
||||
*/
|
||||
protected $cckPluginManager;
|
||||
|
||||
|
@ -41,12 +41,12 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
|
|||
* The plugin ID.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin definition.
|
||||
* @param \Drupal\Component\Plugin\PluginManagerInterface $cck_plugin_manager
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_plugin_manager
|
||||
* The cckfield plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration being run.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, PluginManagerInterface $cck_plugin_manager, MigrationInterface $migration = NULL) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_plugin_manager, MigrationInterface $migration = NULL) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->cckPluginManager = $cck_plugin_manager;
|
||||
$this->migration = $migration;
|
||||
|
@ -72,7 +72,8 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
|
|||
$field_type = is_array($value) ? $value[0] : $value;
|
||||
|
||||
try {
|
||||
return $this->cckPluginManager->createInstance($field_type, [], $this->migration)->getFieldType($row);
|
||||
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration);
|
||||
return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
return parent::transform($value, $migrate_executable, $row, $destination_property);
|
||||
|
|
|
@ -208,6 +208,7 @@ class EntityReferenceAdminTest extends WebTestBase {
|
|||
'id' => 'node_test_view',
|
||||
'label' => 'Node Test View',
|
||||
'show[wizard_key]' => 'node',
|
||||
'show[sort]' => 'none',
|
||||
'page[create]' => 1,
|
||||
'page[title]' => 'Test Node View',
|
||||
'page[path]' => 'test/node/view',
|
||||
|
@ -221,6 +222,14 @@ class EntityReferenceAdminTest extends WebTestBase {
|
|||
'style_options[search_fields][title]' => 'title',
|
||||
);
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply'));
|
||||
|
||||
// Set sort to NID ascending.
|
||||
$edit = [
|
||||
'name[node_field_data.nid]' => 1,
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/add-handler/node_test_view/entity_reference_1/sort', $edit, t('Add and configure sort criteria'));
|
||||
$this->drupalPostForm(NULL, NULL, t('Apply'));
|
||||
|
||||
$this->drupalPostForm('admin/structure/views/view/node_test_view/edit/entity_reference_1', array(), t('Save'));
|
||||
$this->clickLink(t('Settings'));
|
||||
|
||||
|
@ -301,6 +310,7 @@ class EntityReferenceAdminTest extends WebTestBase {
|
|||
$this->assertText(t('Multiple entities match this reference;'));
|
||||
$this->assertText(t("@node1", ['@node1' => $node1->getTitle() . ' (' . $node1->id() . ')']));
|
||||
$this->assertText(t("@node2", ['@node2' => $node2->getTitle() . ' (' . $node2->id() . ')']));
|
||||
$this->assertText(t('Specify the one you want by appending the id in parentheses, like "@example".', ['@example' => $node2->getTitle() . ' (' . $node2->id() . ')']));
|
||||
|
||||
$edit = array(
|
||||
'title[0][value]' => 'Test',
|
||||
|
|
|
@ -210,6 +210,98 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$this->assertFalse(array_diff($found, array_keys($this->entities)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that recreating a field with the name as a deleted field works.
|
||||
*/
|
||||
public function testPurgeWithDeletedAndActiveField() {
|
||||
$bundle = reset($this->bundles);
|
||||
// Create another field storage.
|
||||
$field_name = 'bf_3';
|
||||
$deleted_field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1
|
||||
));
|
||||
$deleted_field_storage->save();
|
||||
// Create the field.
|
||||
FieldConfig::create([
|
||||
'field_storage' => $deleted_field_storage,
|
||||
'bundle' => $bundle,
|
||||
])->save();
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId)
|
||||
->create(array('type' => $bundle));
|
||||
$entity->{$field_name}->setValue($this->_generateTestFieldValues(1));
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
// Delete the field.
|
||||
$deleted_field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name);
|
||||
$deleted_field->delete();
|
||||
$deleted_field_uuid = $deleted_field->uuid();
|
||||
|
||||
// Reload the field storage.
|
||||
$field_storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $deleted_field_storage->uuid(), 'include_deleted' => TRUE));
|
||||
$deleted_field_storage = reset($field_storages);
|
||||
|
||||
// Create the field again.
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1
|
||||
));
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => $bundle,
|
||||
])->save();
|
||||
|
||||
// The field still exists, deleted, with the same field name.
|
||||
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $deleted_field_uuid, 'include_deleted' => TRUE));
|
||||
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->isDeleted(), 'The field exists and is deleted');
|
||||
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->getName() == $field_name);
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId)
|
||||
->create(array('type' => $bundle));
|
||||
$entity->{$field_name}->setValue($this->_generateTestFieldValues(1));
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
// Check that the two field storages have different tables.
|
||||
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
|
||||
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
||||
$table_mapping = $storage->getTableMapping();
|
||||
$deleted_table_name = $table_mapping->getDedicatedDataTableName($deleted_field_storage, TRUE);
|
||||
$active_table_name = $table_mapping->getDedicatedDataTableName($field_storage);
|
||||
|
||||
field_purge_batch(50);
|
||||
|
||||
// Ensure the new field still has its table and the deleted one has been
|
||||
// removed.
|
||||
$this->assertTrue(\Drupal::database()->schema()->tableExists($active_table_name));
|
||||
$this->assertFalse(\Drupal::database()->schema()->tableExists($deleted_table_name));
|
||||
|
||||
// The field has been removed from the system.
|
||||
$fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $deleted_field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE));
|
||||
$this->assertEqual(count($fields), 0, 'The field is gone');
|
||||
|
||||
// Verify there are still 10 entries in the main table.
|
||||
$count = \Drupal::database()
|
||||
->select('entity_test__' . $field_name, 'f')
|
||||
->fields('f', array('entity_id'))
|
||||
->condition('bundle', $bundle)
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertEqual($count, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that field data items and fields are purged when a field storage is
|
||||
* deleted.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\field\Kernel\EntityReference\Views;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTestMulChanged;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
|
@ -27,6 +28,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
*/
|
||||
public static $testViews = array(
|
||||
'test_entity_reference_entity_test_view',
|
||||
'test_entity_reference_entity_test_view_long',
|
||||
'test_entity_reference_reverse_entity_test_view',
|
||||
'test_entity_reference_entity_test_mul_view',
|
||||
'test_entity_reference_reverse_entity_test_mul_view',
|
||||
|
@ -55,6 +57,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installEntitySchema('entity_test_mul');
|
||||
$this->installEntitySchema('entity_test_mul_changed');
|
||||
|
||||
// Create reference from entity_test to entity_test_mul.
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_data', 'field_test_data', 'entity_test_mul');
|
||||
|
@ -62,6 +65,12 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
// Create reference from entity_test_mul to entity_test.
|
||||
$this->createEntityReferenceField('entity_test_mul', 'entity_test_mul', 'field_data_test', 'field_data_test', 'entity_test');
|
||||
|
||||
// Create another field for testing with a long name. So it's storage name
|
||||
// will become hashed. Use entity_test_mul_changed, so the resulting field
|
||||
// tables created will be greater than 48 chars long.
|
||||
// @see \Drupal\Core\Entity\Sql\DefaultTableMapping::generateFieldTableName()
|
||||
$this->createEntityReferenceField('entity_test_mul_changed', 'entity_test_mul_changed', 'field_test_data_with_a_long_name', 'field_test_data_with_a_long_name', 'entity_test');
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('entity_reference_test_views'));
|
||||
}
|
||||
|
||||
|
@ -124,7 +133,6 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
// Test that the correct relationship entity is on the row.
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data']->id(), 1);
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data']->bundle(), 'entity_test_mul');
|
||||
|
||||
}
|
||||
|
||||
// Check the backwards reference view.
|
||||
|
@ -225,4 +233,47 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests views data generated for relationship.
|
||||
*
|
||||
* @see entity_reference_field_views_data()
|
||||
*/
|
||||
public function testDataTableRelationshipWithLongFieldName() {
|
||||
// Create some test entities which link each other.
|
||||
$referenced_entity = EntityTest::create();
|
||||
$referenced_entity->save();
|
||||
|
||||
$entity = EntityTestMulChanged::create();
|
||||
$entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
|
||||
$entity->save();
|
||||
$this->entities[] = $entity;
|
||||
|
||||
$entity = EntityTestMulChanged::create();
|
||||
$entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
|
||||
$entity->save();
|
||||
$this->entities[] = $entity;
|
||||
|
||||
Views::viewsData()->clear();
|
||||
|
||||
// Check an actual test view.
|
||||
$view = Views::getView('test_entity_reference_entity_test_view_long');
|
||||
$this->executeView($view);
|
||||
/** @var \Drupal\views\ResultRow $row */
|
||||
foreach ($view->result as $index => $row) {
|
||||
// Check that the actual ID of the entity is the expected one.
|
||||
$this->assertEqual($row->id, $this->entities[$index]->id());
|
||||
|
||||
// Also check that we have the correct result entity.
|
||||
$this->assertEqual($row->_entity->id(), $this->entities[$index]->id());
|
||||
|
||||
// Test the forward relationship.
|
||||
//$this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1);
|
||||
|
||||
// Test that the correct relationship entity is on the row.
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->id(), 1);
|
||||
$this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->bundle(), 'entity_test');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Migrates and rolls back Drupal 7 fields.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class RollbackFieldInstanceTest extends MigrateFieldInstanceTest {
|
||||
|
||||
/**
|
||||
* Tests migrating D7 fields to field_storage_config entities, then rolling back.
|
||||
*/
|
||||
public function testFieldInstances() {
|
||||
// Test that the field instances have migrated (prior to rollback).
|
||||
parent::testFieldInstances();
|
||||
|
||||
$this->executeRollback('d7_field_instance');
|
||||
$this->executeRollback('d7_field');
|
||||
|
||||
// Check that field instances have been rolled back.
|
||||
$field_instance_ids = [
|
||||
'comment.comment_node_page.comment_body',
|
||||
'node.page.body',
|
||||
'comment.comment_node_article.comment_body',
|
||||
'node.article.body',
|
||||
'node.article.field_tags',
|
||||
'node.article.field_image',
|
||||
'comment.comment_node_blog.comment_body',
|
||||
'node.blog.body',
|
||||
'comment.comment_node_book.comment_body',
|
||||
'node.book.body',
|
||||
'node.forum.taxonomy_forums',
|
||||
'comment.comment_node_forum.comment_body',
|
||||
'node.forum.body',
|
||||
'comment.comment_node_test_content_type.comment_body',
|
||||
'node.test_content_type.field_boolean',
|
||||
'node.test_content_type.field_email',
|
||||
'node.test_content_type.field_phone',
|
||||
'node.test_content_type.field_date',
|
||||
'node.test_content_type.field_date_with_end_time',
|
||||
'node.test_content_type.field_file',
|
||||
'node.test_content_type.field_float',
|
||||
'node.test_content_type.field_images',
|
||||
'node.test_content_type.field_integer',
|
||||
'node.test_content_type.field_link',
|
||||
'node.test_content_type.field_text_list',
|
||||
'node.test_content_type.field_integer_list',
|
||||
'node.test_content_type.field_long_text',
|
||||
'node.test_content_type.field_term_reference',
|
||||
'node.test_content_type.field_text',
|
||||
'comment.comment_node_test_content_type.field_integer',
|
||||
'user.user.field_file',
|
||||
];
|
||||
foreach ($field_instance_ids as $field_instance_id) {
|
||||
$this->assertNull(FieldConfig::load($field_instance_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single rollback.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to rollback, or its ID.
|
||||
*/
|
||||
protected function executeRollback($migration) {
|
||||
if (is_string($migration)) {
|
||||
$this->migration = $this->getMigration($migration);
|
||||
}
|
||||
else {
|
||||
$this->migration = $migration;
|
||||
}
|
||||
(new MigrateExecutable($this->migration, $this))->rollback();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Migrates and rolls back Drupal 7 fields.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class RollbackFieldTest extends MigrateFieldTest {
|
||||
|
||||
/**
|
||||
* Tests migrating D7 fields to field_storage_config entities, then rolling back.
|
||||
*/
|
||||
public function testFields() {
|
||||
// Test that the fields have migrated (prior to rollback).
|
||||
parent::testFields();
|
||||
|
||||
$this->executeRollback('d7_field');
|
||||
|
||||
// Check that fields have been rolled back.
|
||||
$rolled_back_field_ids = [
|
||||
'comment.field_integer',
|
||||
'node.taxonomy_forums',
|
||||
'node.field_integer',
|
||||
'node.field_tags',
|
||||
'node.field_term_reference',
|
||||
'node.field_text_list',
|
||||
'node.field_text',
|
||||
'node.field_phone',
|
||||
'node.field_file',
|
||||
'node.field_images',
|
||||
'node.field_image',
|
||||
'node.field_long_text',
|
||||
'node.field_date_with_end_time',
|
||||
'node.field_integer_list',
|
||||
'node.field_date',
|
||||
'node.field_link',
|
||||
'node.field_float',
|
||||
'node.field_boolean',
|
||||
'node.field_email',
|
||||
'user.field_file',
|
||||
];
|
||||
foreach ($rolled_back_field_ids as $field_id) {
|
||||
$this->assertNull(FieldStorageConfig::load($field_id));
|
||||
}
|
||||
|
||||
// Check that fields that should persist have not been rolled back.
|
||||
$non_rolled_back_field_ids = [
|
||||
'node.body',
|
||||
'comment.comment_body',
|
||||
];
|
||||
foreach ($non_rolled_back_field_ids as $field_id) {
|
||||
$this->assertNotNull(FieldStorageConfig::load($field_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single rollback.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to rollback, or its ID.
|
||||
*/
|
||||
protected function executeRollback($migration) {
|
||||
if (is_string($migration)) {
|
||||
$this->migration = $this->getMigration($migration);
|
||||
}
|
||||
else {
|
||||
$this->migration = $migration;
|
||||
}
|
||||
(new MigrateExecutable($this->migration, $this))->rollback();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewMode;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Migrates and rolls back Drupal 7 view modes.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class RollbackViewModesTest extends MigrateViewModesTest {
|
||||
|
||||
/**
|
||||
* Tests migrating D7 view modes, then rolling back.
|
||||
*/
|
||||
public function testMigration() {
|
||||
// Test that the view modes have migrated (prior to rollback).
|
||||
parent::testMigration();
|
||||
|
||||
$this->executeRollback('d7_view_modes');
|
||||
|
||||
// Check that view modes have been rolled back.
|
||||
$view_mode_ids = [
|
||||
'comment.full',
|
||||
'node.teaser',
|
||||
'node.full',
|
||||
'user.full',
|
||||
];
|
||||
foreach ($view_mode_ids as $view_mode_id) {
|
||||
$this->assertNull(EntityViewMode::load($view_mode_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single rollback.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to rollback, or its ID.
|
||||
*/
|
||||
protected function executeRollback($migration) {
|
||||
if (is_string($migration)) {
|
||||
$this->migration = $this->getMigration($migration);
|
||||
}
|
||||
else {
|
||||
$this->migration = $migration;
|
||||
}
|
||||
(new MigrateExecutable($this->migration, $this))->rollback();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue