summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-03-04 10:59:57 +0900
committerNathaniel Catchpole2016-03-04 10:59:57 +0900
commit348aa684a748433255979bf8b2d6ceeb8942ec76 (patch)
tree5de426b75c446bc97dcea19b3b2e77268d91df1d
parent6e5de2b54371552c5576a6b9918c6751f4d49f03 (diff)
Issue #2672600 by borisson_, arunkumark, Mile23: Replace deprecated usage of entity_create('node') with a direct call to Node::create() in comment,datetime,editor,field,hal,system,taxonomy,views
-rw-r--r--core/modules/comment/src/Plugin/views/field/NodeNewComments.php5
-rw-r--r--core/modules/comment/src/Tests/CommentBookTest.php5
-rw-r--r--core/modules/datetime/src/Tests/DateTimeFieldTest.php7
-rw-r--r--core/modules/editor/src/Tests/EditorFileUsageTest.php5
-rw-r--r--core/modules/field/src/Tests/EntityReference/EntityReferenceFieldDefaultValueTest.php3
-rw-r--r--core/modules/field/src/Tests/Number/NumberFieldTest.php13
-rw-r--r--core/modules/hal/src/Tests/EntityTest.php21
-rw-r--r--core/modules/system/src/Tests/Condition/ConditionFormTest.php8
-rw-r--r--core/modules/system/src/Tests/Entity/EntityCrudHookTest.php8
-rw-r--r--core/modules/system/src/Tests/Entity/EntityFieldTest.php9
-rw-r--r--core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php5
-rw-r--r--core/modules/system/src/Tests/Module/UninstallTest.php6
-rw-r--r--core/modules/system/src/Tests/Plugin/ContextPluginTest.php3
-rw-r--r--core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php12
-rw-r--r--core/modules/views/src/Tests/Entity/FieldEntityTest.php7
-rw-r--r--core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php7
16 files changed, 76 insertions, 48 deletions
diff --git a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
index 6b223b1..ece5eef 100644
--- a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
+++ b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
@@ -10,6 +10,7 @@ namespace Drupal\comment\Plugin\views\field;
use Drupal\Core\Database\Connection;
use Drupal\comment\CommentInterface;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\node\Entity\Node;
use Drupal\views\Plugin\views\field\NumericField;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ResultRow;
@@ -162,10 +163,10 @@ class NodeNewComments extends NumericField {
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$node_type = $this->getValue($values, 'type');
- $node = entity_create('node', array(
+ $node = Node::create([
'nid' => $this->getValue($values, 'nid'),
'type' => $node_type,
- ));
+ ]);
// Because there is no support for selecting a specific comment field to
// reference, we arbitrarily use the first such field name we find.
// @todo Provide a means for selecting the comment field.
diff --git a/core/modules/comment/src/Tests/CommentBookTest.php b/core/modules/comment/src/Tests/CommentBookTest.php
index 24581be..8f2e744 100644
--- a/core/modules/comment/src/Tests/CommentBookTest.php
+++ b/core/modules/comment/src/Tests/CommentBookTest.php
@@ -8,6 +8,7 @@
namespace Drupal\comment\Tests;
use Drupal\comment\CommentInterface;
+use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
@@ -38,11 +39,11 @@ class CommentBookTest extends WebTestBase {
* Tests comments in book export.
*/
public function testBookCommentPrint() {
- $book_node = entity_create('node', array(
+ $book_node = Node::create([
'type' => 'book',
'title' => 'Book title',
'body' => 'Book body',
- ));
+ ]);
$book_node->book['bid'] = 'new';
$book_node->save();
diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
index dc55bfe..a406717 100644
--- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php
+++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
@@ -12,6 +12,7 @@ use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\field\Entity\FieldConfig;
+use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
@@ -659,7 +660,7 @@ class DateTimeFieldTest extends WebTestBase {
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is today.
- $new_node = entity_create('node', array('type' => 'date_content'));
+ $new_node = Node::create(['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));
@@ -692,7 +693,7 @@ class DateTimeFieldTest extends WebTestBase {
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is +90 days.
- $new_node = entity_create('node', array('type' => 'date_content'));
+ $new_node = Node::create(['type' => 'date_content']);
$expected_date = new DrupalDateTime('+90 days', DATETIME_STORAGE_TIMEZONE);
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
@@ -715,7 +716,7 @@ class DateTimeFieldTest extends WebTestBase {
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is not set.
- $new_node = entity_create('node', array('type' => 'date_content'));
+ $new_node = Node::create(['type' => 'date_content']);
$this->assertNull($new_node->get($field_name)->value, 'Default value is not set');
}
diff --git a/core/modules/editor/src/Tests/EditorFileUsageTest.php b/core/modules/editor/src/Tests/EditorFileUsageTest.php
index 750edd3..8d9473d 100644
--- a/core/modules/editor/src/Tests/EditorFileUsageTest.php
+++ b/core/modules/editor/src/Tests/EditorFileUsageTest.php
@@ -8,6 +8,7 @@
namespace Drupal\editor\Tests;
use Drupal\editor\Entity\Editor;
+use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\file\Entity\File;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
@@ -107,12 +108,12 @@ class EditorFileUsageTest extends EntityUnitTestBase {
// Test editor_entity_insert(): increment.
$this->createUser();
- $node = entity_create('node', array(
+ $node = $node = Node::create([
'type' => 'page',
'title' => 'test',
'body' => $body,
'uid' => 1,
- ));
+ ]);
$node->save();
foreach ($image_entities as $key => $image_entity) {
$this->assertIdentical(array('editor' => array('node' => array(1 => '1'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 1 usage.');
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFieldDefaultValueTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFieldDefaultValueTest.php
index 19d99f2..158b454 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFieldDefaultValueTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFieldDefaultValueTest.php
@@ -11,6 +11,7 @@ use Drupal\Component\Utility\Unicode;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
/**
@@ -98,7 +99,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that UUID has been converted to numeric ID.
- $new_node = entity_create('node', array('type' => 'reference_content'));
+ $new_node = Node::create(['type' => 'reference_content']);
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->target_id, $referenced_node->id());
// Ensure that the entity reference config schemas are correct.
diff --git a/core/modules/field/src/Tests/Number/NumberFieldTest.php b/core/modules/field/src/Tests/Number/NumberFieldTest.php
index 894c92c..549c6f5 100644
--- a/core/modules/field/src/Tests/Number/NumberFieldTest.php
+++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php
@@ -9,6 +9,7 @@ namespace Drupal\field\Tests\Number;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
+use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
@@ -436,16 +437,12 @@ class NumberFieldTest extends WebTestBase {
->save();
// Create a node to test formatters.
- $node = entity_create('node', array(
+ $node = Node::create([
'type' => $type,
'title' => $this->randomMachineName(),
- $float_field => array(
- 'value' => $random_float,
- ),
- $integer_field => array(
- 'value' => $random_integer,
- ),
- ));
+ $float_field => ['value' => $random_float],
+ $integer_field => ['value' => $random_integer],
+ ]);
$node->save();
// Go to manage display page.
diff --git a/core/modules/hal/src/Tests/EntityTest.php b/core/modules/hal/src/Tests/EntityTest.php
index 66402f8..159e220 100644
--- a/core/modules/hal/src/Tests/EntityTest.php
+++ b/core/modules/hal/src/Tests/EntityTest.php
@@ -9,6 +9,7 @@ namespace Drupal\hal\Tests;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\comment\Entity\Comment;
+use Drupal\node\Entity\Node;
use Drupal\user\Entity\User;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term;
@@ -62,19 +63,19 @@ class EntityTest extends NormalizerTestBase {
$this->addDefaultCommentField('node', 'example_type');
- $node = entity_create('node', array(
+ $node = Node::create([
'title' => $this->randomMachineName(),
'uid' => $user->id(),
'type' => $node_type->id(),
'status' => NODE_PUBLISHED,
'promote' => 1,
'sticky' => 0,
- 'body' => array(
+ 'body' => [
'value' => $this->randomMachineName(),
- 'format' => $this->randomMachineName(),
- ),
+ 'format' => $this->randomMachineName()
+ ],
'revision_log' => $this->randomString(),
- ));
+ ]);
$node->save();
$original_values = $node->toArray();
@@ -144,18 +145,18 @@ class EntityTest extends NormalizerTestBase {
$this->addDefaultCommentField('node', 'example_type');
- $node = entity_create('node', array(
+ $node = Node::create([
'title' => $this->randomMachineName(),
'uid' => $account->id(),
'type' => $node_type->id(),
'status' => NODE_PUBLISHED,
'promote' => 1,
'sticky' => 0,
- 'body' => array(
+ 'body' => [[
'value' => $this->randomMachineName(),
- 'format' => $this->randomMachineName(),
- )
- ));
+ 'format' => $this->randomMachineName()
+ ]],
+ ]);
$node->save();
$parent_comment = Comment::create(array(
diff --git a/core/modules/system/src/Tests/Condition/ConditionFormTest.php b/core/modules/system/src/Tests/Condition/ConditionFormTest.php
index cfbdb74..231806f 100644
--- a/core/modules/system/src/Tests/Condition/ConditionFormTest.php
+++ b/core/modules/system/src/Tests/Condition/ConditionFormTest.php
@@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Condition;
+use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
/**
@@ -28,8 +29,13 @@ class ConditionFormTest extends WebTestBase {
function testConfigForm() {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Page'));
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
- $article = entity_create('node', array('type' => 'article', 'title' => $this->randomMachineName()));
+
+ $article = Node::create([
+ 'type' => 'article',
+ 'title' => $this->randomMachineName(),
+ ]);
$article->save();
+
$this->drupalGet('condition_test');
$this->assertField('bundles[article]', 'There is an article bundle selector.');
$this->assertField('bundles[page]', 'There is a page bundle selector.');
diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
index 8268a43..2aea883 100644
--- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
@@ -150,7 +150,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
])->save();
$this->addDefaultCommentField('node', 'article', 'comment', CommentItemInterface::OPEN);
- $node = entity_create('node', array(
+ $node = Node::create([
'uid' => $account->id(),
'type' => 'article',
'title' => 'Test node',
@@ -160,7 +160,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
- ));
+ ]);
$node->save();
$nid = $node->id();
$GLOBALS['entity_crud_hook_test'] = array();
@@ -295,7 +295,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
public function testNodeHooks() {
$account = $this->createUser();
- $node = entity_create('node', array(
+ $node = Node::create([
'uid' => $account->id(),
'type' => 'article',
'title' => 'Test node',
@@ -305,7 +305,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
- ));
+ ]);
$this->assertHookMessageOrder(array(
'entity_crud_hook_test_node_create called',
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
index 8919326..1ef4bbf 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
@@ -16,6 +16,7 @@ use Drupal\Core\TypedData\ComplexDataDefinitionInterface;
use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\TypedData\Type\StringInterface;
use Drupal\Core\TypedData\TypedDataInterface;
+use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/**
@@ -686,11 +687,11 @@ class EntityFieldTest extends EntityUnitTestBase {
// Test validating an entity of the wrong type.
$user = $this->createUser();
$user->save();
- $node = entity_create('node', array(
+ $node = $node = Node::create([
'type' => 'page',
'uid' => $user->id(),
'title' => $this->randomString(),
- ));
+ ]);
$reference->setValue($node);
$violations = $reference->validate();
$this->assertEqual($violations->count(), 1);
@@ -707,11 +708,11 @@ class EntityFieldTest extends EntityUnitTestBase {
$violations = $reference_field->validate();
$this->assertEqual($violations->count(), 1);
- $node = entity_create('node', array(
+ $node = Node::create([
'type' => 'article',
'uid' => $user->id(),
'title' => $this->randomString(),
- ));
+ ]);
$node->save();
$reference_field->entity = $node;
$violations = $reference_field->validate();
diff --git a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
index 92efca6..b3fe06f 100644
--- a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
@@ -11,6 +11,7 @@ use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Component\Utility\Html;
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
+use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
use Drupal\user\Entity\User;
use Drupal\comment\Entity\Comment;
@@ -108,7 +109,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
$nodes = array();
$node_labels = array();
foreach ($node_values as $key => $values) {
- $node = entity_create('node', $values);
+ $node = Node::create($values);
$node->save();
$nodes[$key] = $node;
$node_labels[$key] = Html::escape($node->label());
@@ -367,7 +368,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
);
$nodes = array();
foreach ($node_values as $key => $values) {
- $node = entity_create('node', $values);
+ $node = Node::create($values);
$node->save();
$nodes[$key] = $node;
}
diff --git a/core/modules/system/src/Tests/Module/UninstallTest.php b/core/modules/system/src/Tests/Module/UninstallTest.php
index 4a32b10..8c91d8b 100644
--- a/core/modules/system/src/Tests/Module/UninstallTest.php
+++ b/core/modules/system/src/Tests/Module/UninstallTest.php
@@ -10,6 +10,7 @@ namespace Drupal\system\Tests\Module;
use Drupal\Core\Cache\Cache;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityMalformedException;
+use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
@@ -52,7 +53,10 @@ class UninstallTest extends WebTestBase {
$node_type->setThirdPartySetting('module_test', 'key', 'value');
$node_type->save();
// Add a node to prevent node from being uninstalled.
- $node = entity_create('node', array('type' => 'uninstall_blocker', 'title' => $this->randomString()));
+ $node = Node::create([
+ 'type' => 'uninstall_blocker',
+ 'title' => $this->randomString(),
+ ]);
$node->save();
$this->drupalGet('admin/modules/uninstall');
diff --git a/core/modules/system/src/Tests/Plugin/ContextPluginTest.php b/core/modules/system/src/Tests/Plugin/ContextPluginTest.php
index 92be3e5..4a9b73a 100644
--- a/core/modules/system/src/Tests/Plugin/ContextPluginTest.php
+++ b/core/modules/system/src/Tests/Plugin/ContextPluginTest.php
@@ -9,6 +9,7 @@ namespace Drupal\system\Tests\Plugin;
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Core\Plugin\Context\ContextDefinition;
+use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\plugin_test\Plugin\MockBlockManager;
use Drupal\simpletest\KernelTestBase;
@@ -37,7 +38,7 @@ class ContextPluginTest extends KernelTestBase {
$manager = new MockBlockManager();
$plugin = $manager->createInstance('user_name');
// Create a node, add it as context, catch the exception.
- $node = entity_create('node', array('title' => $name, 'type' => 'page'));
+ $node = Node::create(['type' => 'page', 'title' => $name]);
// Try to get context that is missing its definition.
try {
diff --git a/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php b/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php
index d807d5e..f9d6bce 100644
--- a/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php
+++ b/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php
@@ -7,6 +7,8 @@
namespace Drupal\taxonomy\Tests;
+use Drupal\node\Entity\Node;
+
/**
* Tests the translation of taxonomy terms field on nodes.
*
@@ -74,16 +76,16 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
*/
protected function setUpNode() {
/** @var \Drupal\node\Entity\Node $node */
- $node = entity_create('node', array(
+ $node = Node::create([
'title' => $this->randomMachineName(),
'type' => 'article',
- 'description' => array(
+ 'description' => [[
'value' => $this->randomMachineName(),
- 'format' => 'basic_html',
- ),
+ 'format' => 'basic_html'
+ ]],
$this->termFieldName => array(array('target_id' => $this->term->id())),
'langcode' => $this->baseLangcode,
- ));
+ ]);
$node->save();
$node->addTranslation($this->translateToLangcode, $node->toArray());
$node->save();
diff --git a/core/modules/views/src/Tests/Entity/FieldEntityTest.php b/core/modules/views/src/Tests/Entity/FieldEntityTest.php
index 1044dff..6f34dda 100644
--- a/core/modules/views/src/Tests/Entity/FieldEntityTest.php
+++ b/core/modules/views/src/Tests/Entity/FieldEntityTest.php
@@ -8,6 +8,7 @@
namespace Drupal\views\Tests\Entity;
use Drupal\comment\Tests\CommentTestTrait;
+use Drupal\node\Entity\Node;
use Drupal\user\Entity\User;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
@@ -59,7 +60,11 @@ class FieldEntityTest extends ViewTestBase {
$account = User::create(['name' => $this->randomMachineName(), 'bundle' => 'user']);
$account->save();
- $node = entity_create('node', array('uid' => $account->id(), 'type' => 'page', 'title' => $this->randomString()));
+ $node = Node::create([
+ 'uid' => $account->id(),
+ 'type' => 'page',
+ 'title' => $this->randomString(),
+ ]);
$node->save();
$comment = Comment::create(array(
'uid' => $account->id(),
diff --git a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php
index 709dd37..99a7193 100644
--- a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php
+++ b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php
@@ -7,6 +7,7 @@
namespace Drupal\views\Tests\Entity;
+use Drupal\node\Entity\Node;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
@@ -60,7 +61,11 @@ class FilterEntityBundleTest extends ViewTestBase {
foreach ($this->entityBundles as $key => $info) {
for ($i = 0; $i < 5; $i++) {
- $entity = entity_create('node', array('title' => $this->randomString(), 'uid' => 1, 'type' => $key));
+ $entity = Node::create([
+ 'title' => $this->randomString(),
+ 'uid' => 1,
+ 'type' => $key,
+ ]);
$entity->save();
$this->entities[$key][$entity->id()] = $entity;
$this->entities['count']++;