Commit 8e4fe5c0 authored by catch's avatar catch

Issue #2641584 by Mac_Weber, heykarthikwithu, legovaer: Replace deprecated...

Issue #2641584 by Mac_Weber, heykarthikwithu, legovaer: Replace deprecated usage of  entity_create('field_config') with a direct call to FieldConfig::create()
parent 854649c9
......@@ -79,12 +79,12 @@ function block_content_add_body_field($block_type_id, $label = 'Body') {
// Add or remove the body field, as needed.
$field = FieldConfig::loadByName('block_content', $block_type_id, 'body');
if (empty($field)) {
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
'bundle' => $block_type_id,
'label' => $label,
'settings' => array('display_summary' => FALSE),
));
]);
$field->save();
// Assign widget settings for the 'default' form mode.
......
......@@ -114,10 +114,10 @@ public function testExportImport() {
'type' => 'text',
));
$this->fieldStorage->save();
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => $this->contentType->id(),
))->save();
])->save();
// Update the displays so that configuration does not change unexpectedly on
// import.
entity_get_form_display('node', $this->contentType->id(), 'default')
......
......@@ -8,6 +8,7 @@
namespace Drupal\config_translation\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
......@@ -399,14 +400,14 @@ public function doFieldListTest() {
'revision' => FALSE
));
$block_content_type->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
// The field storage is guaranteed to exist because it is supplied by the
// block_content module.
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
'bundle' => $block_content_type->id(),
'label' => 'Body',
'settings' => array('display_summary' => FALSE),
));
]);
$field->save();
// Look at a few fields on a few entity types.
......
......@@ -7,6 +7,7 @@
namespace Drupal\contact\Tests\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\views\Tests\ViewTestBase;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\contact\Entity\ContactForm;
......@@ -47,10 +48,10 @@ protected function setUp() {
'label' => 'Test contact form',
])->save();
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'contact_message',
))->save();
])->save();
$this->container->get('views.views_data')->clear();
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\content_translation\Tests;
use Drupal\Component\Serialization\Json;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
......@@ -79,12 +80,12 @@ protected function setUp() {
'type' => 'text',
'cardinality' => 1,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'field_test_text',
'bundle' => $this->bundle,
'label' => 'Test text-field',
))->save();
])->save();
entity_get_form_display('node', $this->bundle, 'default')
->setComponent('field_test_text', array(
'type' => 'text_textfield',
......
......@@ -8,6 +8,7 @@
namespace Drupal\content_translation\Tests;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
......@@ -57,7 +58,7 @@ protected function setupTestFields() {
'cardinality' => $this->cardinality,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => $this->entityTypeId,
'field_name' => $this->fieldName,
'bundle' => $this->entityTypeId,
......@@ -71,7 +72,7 @@ protected function setupTestFields() {
),
),
),
))->save();
])->save();
}
/**
......
......@@ -8,6 +8,7 @@
namespace Drupal\content_translation\Tests;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -190,12 +191,12 @@ protected function setupTestFields() {
'entity_type' => $this->entityTypeId,
'cardinality' => 1,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => $this->entityTypeId,
'field_name' => $this->fieldName,
'bundle' => $this->bundle,
'label' => 'Test translatable text-field',
))->save();
])->save();
entity_get_form_display($this->entityTypeId, $this->bundle, 'default')
->setComponent($this->fieldName, array(
'type' => 'string_textfield',
......
......@@ -11,6 +11,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -85,11 +86,11 @@ protected function setUp() {
'settings' => array('datetime_type' => 'date'),
));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array(
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
'required' => TRUE,
));
]);
$this->field->save();
entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')
......@@ -633,10 +634,10 @@ function testDefaultValue() {
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'date_content',
));
]);
$field->save();
// Set now as default_value.
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -37,13 +38,13 @@ protected function setUp() {
'settings' => array('datetime_type' => 'date'),
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'settings' => array(
'default_value' => 'blank',
),
));
]);
$field->save();
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\datetime\Tests\Views;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldConfig;
use Drupal\views\Tests\Handler\HandlerTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -57,7 +58,7 @@ protected function setUp() {
'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
]);
$fieldStorage->save();
$field = entity_create('field_config', [
$field = FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => 'page',
'required' => TRUE,
......
......@@ -72,7 +72,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
* Constructs a FieldConfig object.
*
* In most cases, Field entities are created via
* entity_create('field_config', $values), where $values is the same
* FieldConfig::create($values), where $values is the same
* parameter as in this constructor.
*
* @param array $values
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -31,11 +32,11 @@ protected function setUp() {
'entity_type' => 'entity_test',
'type' => 'boolean',
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_boolean',
'bundle' => 'entity_test',
))->save();
])->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')
......
......@@ -127,10 +127,10 @@ protected function setUp() {
// fields.
foreach ($this->bundles as $bundle) {
foreach ($this->fieldStorages as $field_storage) {
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
))->save();
])->save();
}
for ($i = 0; $i < 10; $i++) {
$entity = entity_create($this->entityTypeId, array('type' => $bundle));
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
......@@ -96,7 +97,7 @@ protected function setUp() {
);
FieldStorageConfig::create($field_storage)->save();
entity_create('field_config', $field)->save();
FieldConfig::create($field)->save();
// Create a display for the default view mode.
entity_get_display($field['entity_type'], $field['bundle'], 'default')
->setComponent($this->fieldName, $this->displayOptions['default'])
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests\Email;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -61,10 +62,10 @@ function testEmailField() {
'type' => 'email',
));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array(
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
));
]);
$this->field->save();
// Create a form display for the default form mode.
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -28,11 +29,11 @@ protected function setUp() {
'entity_type' => 'entity_test',
'type' => 'email',
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_email',
'bundle' => 'entity_test',
))->save();
])->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests\EntityReference;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\node\Entity\Node;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -57,7 +58,7 @@ protected function setUp() {
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'label' => 'Entity reference field',
'field_name' => 'test_field',
'entity_type' => 'node',
......@@ -73,7 +74,7 @@ protected function setUp() {
'auto_create' => TRUE,
),
),
))->save();
])->save();
entity_get_display('node', $referencing->id(), 'default')
->setComponent('test_field')
......
......@@ -9,6 +9,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\WebTestBase;
......@@ -62,7 +63,7 @@ function testEntityReferenceDefaultValue() {
'settings' => array('target_type' => 'node'),
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'reference_content',
'settings' => array(
......@@ -72,7 +73,7 @@ function testEntityReferenceDefaultValue() {
'sort' => array('field' => '_none'),
),
),
));
]);
$field->save();
// Set created node as default_value.
......@@ -126,7 +127,7 @@ function testEntityReferenceDefaultConfigValue() {
'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'reference_content',
'settings' => array(
......@@ -135,7 +136,7 @@ function testEntityReferenceDefaultConfigValue() {
'sort' => array('field' => '_none'),
),
),
));
]);
$field->save();
// Set created node as default_value.
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Tests\EntityReference;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase;
......@@ -222,11 +223,11 @@ protected function setUpEntityReferenceField() {
),
))->save();
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $this->referenceFieldName,
'bundle' => $this->referrerType->id(),
'entity_type' => $this->testEntityTypeName,
))
])
->save();
entity_get_form_display($this->testEntityTypeName, $this->referrerType->id(), 'default')
->setComponent($this->referenceFieldName, array(
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests\EntityReference;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -64,7 +65,7 @@ protected function setUp() {
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'label' => 'Entity reference field',
'field_name' => 'test_field',
'entity_type' => 'node',
......@@ -79,7 +80,7 @@ protected function setUp() {
),
),
),
))->save();
])->save();
// Create a file field.
......@@ -90,12 +91,12 @@ protected function setUp() {
'type' => 'file'
));
$field_storage->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => 'node',
'field_storage' => $field_storage,
'bundle' => $referencing->id(),
'label' => $this->randomMachineName() . '_label',
))->save();
])->save();
entity_get_display('node', $referencing->id(), 'default')
->setComponent('test_field')
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
......@@ -89,12 +90,12 @@ protected function setUp() {
'type' => 'text',
'settings' => array(),
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => $this->entityType,
'bundle' => $this->bundle,
'field_name' => 'body',
'label' => 'Body',
))->save();
])->save();
entity_get_display($this->entityType, $this->bundle, 'default')
->setComponent('body', array(
'type' => 'text_default',
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Tests\EntityReference\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\views\Views;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -62,7 +63,7 @@ protected function setUp() {
'cardinality' => '1',
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'test_bundle',
'settings' => array(
......@@ -75,7 +76,7 @@ protected function setUp() {
),
),
),
));
]);
$field->save();
$this->field = $field;
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
......@@ -58,7 +59,7 @@ protected function setUp() {
'entity_type' => 'node',
'bundle' => $content_type,
);
entity_create('field_config', $field)->save();
FieldConfig::create($field)->save();
// Assign display properties for the 'default' and 'teaser' view modes.
foreach (array('default', 'teaser') as $view_mode) {
......
......@@ -104,11 +104,11 @@ function testFieldAttachLoadMultiple() {
$field_storage->save();
$field_ids[$i] = $field_storage->uuid();
foreach ($field_bundles_map[$i] as $bundle) {
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $field_names[$i],
'entity_type' => $entity_type,
'bundle' => $bundles[$bundle],
))->save();
])->save();
}
}
......@@ -289,7 +289,7 @@ function testEntityCreateBundle() {
// Add a field to that bundle.
$this->fieldTestData->field_definition['bundle'] = $new_bundle;
entity_create('field_config', $this->fieldTestData->field_definition)->save();
FieldConfig::create($this->fieldTestData->field_definition)->save();
// Save an entity with data in the field.
$entity = entity_create($entity_type, array('type' => $this->fieldTestData->field->getTargetBundle()));
......@@ -314,7 +314,7 @@ function testEntityDeleteBundle() {
// Add a field to that bundle.
$this->fieldTestData->field_definition['bundle'] = $new_bundle;
entity_create('field_config', $this->fieldTestData->field_definition)->save();
FieldConfig::create($this->fieldTestData->field_definition)->save();
// Create a second field for the test bundle
$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
......@@ -333,7 +333,7 @@ function testEntityDeleteBundle() {
'description' => $this->randomMachineName() . '_description',
'weight' => mt_rand(0, 127),
);
entity_create('field_config', $field)->save();
FieldConfig::create($field)->save();
// Save an entity with data for both fields
$entity = entity_create($entity_type, array('type' => $this->fieldTestData->field->getTargetBundle()));
......
......@@ -73,7 +73,7 @@ function testCreateField() {
// constraint for this field.
\Drupal::state()->set('field_test_add_constraint', $this->fieldStorage->getName());
/** @var \Drupal\Core\Field\FieldConfigInterface $field */
$field = entity_create('field_config', $this->fieldDefinition);
$field = FieldConfig::create($this->fieldDefinition);
$field->save();
$field = FieldConfig::load($field->id());
......@@ -118,7 +118,7 @@ function testCreateField() {
// Guarantee that the field/bundle combination is unique.
try {
entity_create('field_config', $this->fieldDefinition)->save();
FieldConfig::create($this->fieldDefinition)->save();
$this->fail(t('Cannot create two fields with the same field / bundle combination.'));
}
catch (EntityStorageException $e) {
......@@ -128,7 +128,7 @@ function testCreateField() {
// Check that the specified field exists.
try {
$this->fieldDefinition['field_name'] = $this->randomMachineName();
entity_create('field_config', $this->fieldDefinition)->save();
FieldConfig::create($this->fieldDefinition)->save();
$this->fail(t('Cannot create a field with a non-existing storage.'));
}
catch (FieldException $e) {
......@@ -180,7 +180,7 @@ public function testCreateFieldCustomStorage() {
* Test reading back a field definition.
*/
function testReadField() {
entity_create('field_config', $this->fieldDefinition)->save();
FieldConfig::create($this->fieldDefinition)->save();
// Read the field back.
$field = FieldConfig::load('entity_test.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
......@@ -193,7 +193,7 @@ function testReadField() {
* Test the update of a field.
*/
function testUpdateField() {
entity_create('field_config', $this->fieldDefinition)->save();
FieldConfig::create($this->fieldDefinition)->save();
// Check that basic changes are saved.
$field = FieldConfig::load('entity_test.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
......@@ -221,11 +221,11 @@ function testDeleteField() {
// Create two fields for the same field storage so we can test that only one
// is deleted.
entity_create('field_config', $this->fieldDefinition)->save();
FieldConfig::create($this->fieldDefinition)->save();
$another_field_definition = $this->fieldDefinition;
$another_field_definition['bundle'] .= '_another_bundle';
entity_test_create_bundle($another_field_definition['bundle']);
entity_create('field_config', $another_field_definition)->save();
FieldConfig::create($another_field_definition)->save();
// Test that the first field is not deleted, and then delete it.
$field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE)));
......@@ -255,8 +255,8 @@ function testDeleteFieldCrossDeletion() {
// Check that deletion of a field storage deletes its fields.
$field_storage = $this->fieldStorage;
entity_create('field_config', $this->fieldDefinition)->save();
entity_create('field_config', $field_definition_2)->save();
FieldConfig::create($this->fieldDefinition)->save();
FieldConfig::create($field_definition_2)->save();
$field_storage->delete();
$this->assertFalse(FieldConfig::loadByName('entity_test', $this->fieldDefinition['bundle'], $field_storage->getName()));
$this->assertFalse(FieldConfig::loadByName('entity_test', $field_definition_2['bundle'], $field_storage->getName()));
......@@ -264,9 +264,9 @@ function testDeleteFieldCrossDeletion() {
// Check that deletion of the last field deletes the storage.
$field_storage = FieldStorageConfig::create($this->fieldStorageDefinition);
$field_storage->save();
$field = entity_create('field_config', $this->fieldDefinition);
$field = FieldConfig::create($this->fieldDefinition);
$field->save();
$field_2 = entity_create('field_config', $field_definition_2);
$field_2 = FieldConfig::create($field_definition_2);
$field_2->save();
$field->delete();
$this->assertTrue(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
......@@ -277,9 +277,9 @@ function testDeleteFieldCrossDeletion() {
// the storage.
$field_storage = FieldStorageConfig::create($this->fieldStorageDefinition);
$field_storage->save();
$field = entity_create('field_config', $this->fieldDefinition);
$field = FieldConfig::create($this->fieldDefinition);
$field->save();
$field_2 = entity_create('field_config', $field_definition_2);
$field_2 = FieldConfig::create($field_definition_2);
$field_2->save();
$this->container->get('entity.manager')->getStorage('field_config')->delete(array($field, $field_2));
$this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
......
......@@ -61,10 +61,10 @@ public function testEntityCountAndHasData() {
'cardinality' => 2,
));
$field_storage->save();
entity_create('field_config', array(