Commit 35372e59 authored by catch's avatar catch

Issue #2491009 by trwad: Replace deprecated usage of entity_create with a...

Issue #2491009 by trwad: Replace deprecated usage of entity_create with a direct call to the entity type class in Field UI module
parent ae4a224e
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
namespace Drupal\field_ui\Tests; namespace Drupal\field_ui\Tests;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\KernelTestBase; use Drupal\simpletest\KernelTestBase;
/** /**
...@@ -34,7 +38,7 @@ protected function setUp() { ...@@ -34,7 +38,7 @@ protected function setUp() {
* Tests basic CRUD operations on entity display objects. * Tests basic CRUD operations on entity display objects.
*/ */
public function testEntityDisplayCRUD() { public function testEntityDisplayCRUD() {
$display = entity_create('entity_view_display', array( $display = EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
...@@ -108,7 +112,7 @@ public function testEntityDisplayCRUD() { ...@@ -108,7 +112,7 @@ public function testEntityDisplayCRUD() {
* Test sorting of components by name on basic CRUD operations * Test sorting of components by name on basic CRUD operations
*/ */
public function testEntityDisplayCRUDSort() { public function testEntityDisplayCRUDSort() {
$display = entity_create('entity_view_display', array( $display = EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
...@@ -148,7 +152,7 @@ public function testEntityGetDisplay() { ...@@ -148,7 +152,7 @@ public function testEntityGetDisplay() {
*/ */
public function testExtraFieldComponent() { public function testExtraFieldComponent() {
entity_test_create_bundle('bundle_with_extra_fields'); entity_test_create_bundle('bundle_with_extra_fields');
$display = entity_create('entity_view_display', array( $display = EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'bundle_with_extra_fields', 'bundle' => 'bundle_with_extra_fields',
'mode' => 'default', 'mode' => 'default',
...@@ -172,19 +176,19 @@ public function testExtraFieldComponent() { ...@@ -172,19 +176,19 @@ public function testExtraFieldComponent() {
public function testFieldComponent() { public function testFieldComponent() {
$field_name = 'test_field'; $field_name = 'test_field';
// Create a field storage and a field. // Create a field storage and a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'type' => 'test_field' 'type' => 'test_field'
)); ));
$field_storage->save(); $field_storage->save();
$field = entity_create('field_config', array( $field = FieldConfig::create(array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
)); ));
$field->save(); $field->save();
$display = entity_create('entity_view_display', array( $display = EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
...@@ -234,7 +238,7 @@ public function testFieldComponent() { ...@@ -234,7 +238,7 @@ public function testFieldComponent() {
* Tests the behavior of a field component for a base field. * Tests the behavior of a field component for a base field.
*/ */
public function testBaseFieldComponent() { public function testBaseFieldComponent() {
$display = entity_create('entity_view_display', array( $display = EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test_base_field_display', 'targetEntityType' => 'entity_test_base_field_display',
'bundle' => 'entity_test_base_field_display', 'bundle' => 'entity_test_base_field_display',
'mode' => 'default', 'mode' => 'default',
...@@ -296,7 +300,7 @@ public function testBaseFieldComponent() { ...@@ -296,7 +300,7 @@ public function testBaseFieldComponent() {
*/ */
public function testRenameDeleteBundle() { public function testRenameDeleteBundle() {
// Create a node bundle, display and form display object. // Create a node bundle, display and form display object.
$type = entity_create('node_type', array('type' => 'article')); $type = NodeType::create(array('type' => 'article'));
$type->save(); $type->save();
node_add_body_field($type); node_add_body_field($type);
entity_get_display('node', 'article', 'default')->save(); entity_get_display('node', 'article', 'default')->save();
...@@ -349,13 +353,13 @@ public function testRenameDeleteBundle() { ...@@ -349,13 +353,13 @@ public function testRenameDeleteBundle() {
public function testDeleteField() { public function testDeleteField() {
$field_name = 'test_field'; $field_name = 'test_field';
// Create a field storage and a field. // Create a field storage and a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'type' => 'test_field' 'type' => 'test_field'
)); ));
$field_storage->save(); $field_storage->save();
$field = entity_create('field_config', array( $field = FieldConfig::create(array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
)); ));
...@@ -363,12 +367,12 @@ public function testDeleteField() { ...@@ -363,12 +367,12 @@ public function testDeleteField() {
// Create default and teaser entity display. // Create default and teaser entity display.
EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save(); EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save();
entity_create('entity_view_display', array( EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
))->setComponent($field_name)->save(); ))->setComponent($field_name)->save();
entity_create('entity_view_display', array( EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'teaser', 'mode' => 'teaser',
...@@ -398,19 +402,19 @@ public function testOnDependencyRemoval() { ...@@ -398,19 +402,19 @@ public function testOnDependencyRemoval() {
$field_name = 'test_field'; $field_name = 'test_field';
// Create a field. // Create a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'type' => 'text' 'type' => 'text'
)); ));
$field_storage->save(); $field_storage->save();
$field = entity_create('field_config', array( $field = FieldConfig::create(array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
)); ));
$field->save(); $field->save();
entity_create('entity_view_display', array( EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
namespace Drupal\field_ui\Tests; namespace Drupal\field_ui\Tests;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityFormMode; use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\KernelTestBase; use Drupal\simpletest\KernelTestBase;
/** /**
...@@ -54,19 +57,19 @@ public function testEntityGetFromDisplay() { ...@@ -54,19 +57,19 @@ public function testEntityGetFromDisplay() {
public function testFieldComponent() { public function testFieldComponent() {
// Create a field storage and a field. // Create a field storage and a field.
$field_name = 'test_field'; $field_name = 'test_field';
$field_storage = entity_create('field_storage_config', array( $field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'type' => 'test_field' 'type' => 'test_field'
)); ));
$field_storage->save(); $field_storage->save();
$field = entity_create('field_config', array( $field = FieldConfig::create(array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
)); ));
$field->save(); $field->save();
$form_display = entity_create('entity_form_display', array( $form_display = EntityFormDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
...@@ -121,7 +124,7 @@ public function testFieldComponent() { ...@@ -121,7 +124,7 @@ public function testFieldComponent() {
* Tests the behavior of a field component for a base field. * Tests the behavior of a field component for a base field.
*/ */
public function testBaseFieldComponent() { public function testBaseFieldComponent() {
$display = entity_create('entity_form_display', array( $display = EntityFormDisplay::create(array(
'targetEntityType' => 'entity_test_base_field_display', 'targetEntityType' => 'entity_test_base_field_display',
'bundle' => 'entity_test_base_field_display', 'bundle' => 'entity_test_base_field_display',
'mode' => 'default', 'mode' => 'default',
...@@ -182,13 +185,13 @@ public function testBaseFieldComponent() { ...@@ -182,13 +185,13 @@ public function testBaseFieldComponent() {
public function testDeleteField() { public function testDeleteField() {
$field_name = 'test_field'; $field_name = 'test_field';
// Create a field storage and a field. // Create a field storage and a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'type' => 'test_field' 'type' => 'test_field'
)); ));
$field_storage->save(); $field_storage->save();
$field = entity_create('field_config', array( $field = FieldConfig::create(array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
)); ));
...@@ -196,12 +199,12 @@ public function testDeleteField() { ...@@ -196,12 +199,12 @@ public function testDeleteField() {
// Create default and compact entity display. // Create default and compact entity display.
EntityFormMode::create(array('id' => 'entity_test.compact', 'targetEntityType' => 'entity_test'))->save(); EntityFormMode::create(array('id' => 'entity_test.compact', 'targetEntityType' => 'entity_test'))->save();
entity_create('entity_form_display', array( EntityFormDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
))->setComponent($field_name)->save(); ))->setComponent($field_name)->save();
entity_create('entity_form_display', array( EntityFormDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'compact', 'mode' => 'compact',
...@@ -231,19 +234,19 @@ public function testOnDependencyRemoval() { ...@@ -231,19 +234,19 @@ public function testOnDependencyRemoval() {
$field_name = 'test_field'; $field_name = 'test_field';
// Create a field. // Create a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'type' => 'text' 'type' => 'text'
)); ));
$field_storage->save(); $field_storage->save();
$field = entity_create('field_config', array( $field = FieldConfig::create(array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
)); ));
$field->save(); $field->save();
entity_create('entity_form_display', array( EntityFormDisplay::create(array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'mode' => 'default', 'mode' => 'default',
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\field_ui\Tests; namespace Drupal\field_ui\Tests;
use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -75,7 +77,7 @@ public function testFieldUIRoutes() { ...@@ -75,7 +77,7 @@ public function testFieldUIRoutes() {
// Create new view mode and verify it's available on the Manage Display // Create new view mode and verify it's available on the Manage Display
// screen after enabling it. // screen after enabling it.
entity_create('entity_view_mode' ,array( EntityViewMode::create(array(
'id' => 'user.test', 'id' => 'user.test',
'label' => 'Test', 'label' => 'Test',
'targetEntityType' => 'user', 'targetEntityType' => 'user',
...@@ -88,7 +90,7 @@ public function testFieldUIRoutes() { ...@@ -88,7 +90,7 @@ public function testFieldUIRoutes() {
// Create new form mode and verify it's available on the Manage Form // Create new form mode and verify it's available on the Manage Form
// Display screen after enabling it. // Display screen after enabling it.
entity_create('entity_form_mode' ,array( EntityFormMode::create(array(
'id' => 'user.test', 'id' => 'user.test',
'label' => 'Test', 'label' => 'Test',
'targetEntityType' => 'user', 'targetEntityType' => 'user',
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests the Field UI "Manage display" and "Manage form display" screens. * Tests the Field UI "Manage display" and "Manage form display" screens.
...@@ -45,7 +47,7 @@ protected function setUp() { ...@@ -45,7 +47,7 @@ protected function setUp() {
$this->type = $type->id(); $this->type = $type->id();
// Create a default vocabulary. // Create a default vocabulary.
$vocabulary = entity_create('taxonomy_vocabulary', array( $vocabulary = Vocabulary::create(array(
'name' => $this->randomMachineName(), 'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(), 'description' => $this->randomMachineName(),
'vid' => Unicode::strtolower($this->randomMachineName()), 'vid' => Unicode::strtolower($this->randomMachineName()),
...@@ -375,7 +377,7 @@ function testSingleViewMode() { ...@@ -375,7 +377,7 @@ function testSingleViewMode() {
*/ */
function testNoFieldsDisplayOverview() { function testNoFieldsDisplayOverview() {
// Create a fresh content type without any fields. // Create a fresh content type without any fields.
entity_create('node_type', array( NodeType::create(array(
'type' => 'no_fields', 'type' => 'no_fields',
'name' => 'No fields', 'name' => 'No fields',
))->save(); ))->save();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests the Field UI "Manage fields" screen. * Tests the Field UI "Manage fields" screen.
...@@ -86,7 +87,7 @@ protected function setUp() { ...@@ -86,7 +87,7 @@ protected function setUp() {
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
// Create a vocabulary named "Tags". // Create a vocabulary named "Tags".
$vocabulary = entity_create('taxonomy_vocabulary', array( $vocabulary = Vocabulary::create(array(
'name' => 'Tags', 'name' => 'Tags',
'vid' => 'tags', 'vid' => 'tags',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
...@@ -366,12 +367,12 @@ function testFieldPrefix() { ...@@ -366,12 +367,12 @@ function testFieldPrefix() {
function testDefaultValue() { function testDefaultValue() {
// Create a test field storage and field. // Create a test field storage and field.
$field_name = 'test'; $field_name = 'test';
entity_create('field_storage_config', array( FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'node', 'entity_type' => 'node',
'type' => 'test_field' 'type' => 'test_field'
))->save(); ))->save();
$field = entity_create('field_config', array( $field = FieldConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => $this->contentType, 'bundle' => $this->contentType,
...@@ -503,7 +504,7 @@ function testLockedField() { ...@@ -503,7 +504,7 @@ function testLockedField() {
// Create a locked field and attach it to a bundle. We need to do this // Create a locked field and attach it to a bundle. We need to do this
// programmatically as there's no way to create a locked field through UI. // programmatically as there's no way to create a locked field through UI.
$field_name = strtolower($this->randomMachineName(8)); $field_name = strtolower($this->randomMachineName(8));
$field_storage = entity_create('field_storage_config', array( $field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'node', 'entity_type' => 'node',
'type' => 'test_field', 'type' => 'test_field',
...@@ -511,7 +512,7 @@ function testLockedField() { ...@@ -511,7 +512,7 @@ function testLockedField() {
'locked' => TRUE 'locked' => TRUE
)); ));
$field_storage->save(); $field_storage->save();
entity_create('field_config', array( FieldConfig::create(array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => $this->contentType, 'bundle' => $this->contentType,
))->save(); ))->save();
...@@ -544,7 +545,7 @@ function testHiddenFields() { ...@@ -544,7 +545,7 @@ function testHiddenFields() {
// Create a field storage and a field programmatically. // Create a field storage and a field programmatically.
$field_name = 'hidden_test_field'; $field_name = 'hidden_test_field';
entity_create('field_storage_config', array( FieldStorageConfig::create(array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'node', 'entity_type' => 'node',
'type' => $field_name, 'type' => $field_name,
...@@ -555,7 +556,7 @@ function testHiddenFields() { ...@@ -555,7 +556,7 @@ function testHiddenFields() {
'entity_type' => 'node', 'entity_type' => 'node',
'label' => t('Hidden field'), 'label' => t('Hidden field'),
); );
entity_create('field_config', $field)->save(); FieldConfig::create($field)->save();
entity_get_form_display('node', $this->contentType, 'default') entity_get_form_display('node', $this->contentType, 'default')
->setComponent($field_name) ->setComponent($field_name)
->save(); ->save();
...@@ -638,13 +639,13 @@ function testDeleteTaxonomyField() { ...@@ -638,13 +639,13 @@ function testDeleteTaxonomyField() {
*/ */
function testHelpDescriptions() { function testHelpDescriptions() {
// Create an image field // Create an image field
entity_create('field_storage_config', array( FieldStorageConfig::create(array(
'field_name' => 'field_image', 'field_name' => 'field_image',
'entity_type' => 'node', 'entity_type' => 'node',
'type' => 'image', 'type' => 'image',
))->save(); ))->save();
entity_create('field_config', array( FieldConfig::create(array(
'field_name' => 'field_image', 'field_name' => 'field_image',
'entity_type' => 'node', 'entity_type' => 'node',
'label' => 'Image', 'label' => 'Image',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment