Commit 348aa684 authored by catch's avatar catch

Issue #2672600 by borisson_, arunkumark, Mile23: Replace deprecated usage of ...

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
parent 6e5de2b5
......@@ -10,6 +10,7 @@
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 @@ public function preRender(&$values) {
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.
......
......@@ -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 @@ protected function setUp() {
* 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();
......
......@@ -12,6 +12,7 @@
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 @@ function testDefaultValue() {
\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 @@ function testDefaultValue() {
\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 @@ function testDefaultValue() {
\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');
}
......
......@@ -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 @@ public function testEditorEntityHooks() {
// 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.');
......
......@@ -11,6 +11,7 @@
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 @@ function testEntityReferenceDefaultValue() {
\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.
......
......@@ -9,6 +9,7 @@
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 @@ function testNumberFormatter() {
->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.
......
......@@ -9,6 +9,7 @@
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 @@ public function testNode() {
$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 @@ public function testComment() {
$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(
......
......@@ -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.');
......
......@@ -150,7 +150,7 @@ public function testCommentHooks() {
])->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 @@ public function testCommentHooks() {
'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 @@ public function testFileHooks() {
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 @@ public function testNodeHooks() {
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
));
]);
$this->assertHookMessageOrder(array(
'entity_crud_hook_test_node_create called',
......
......@@ -16,6 +16,7 @@
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 @@ public function testEntityConstraintValidation() {
// 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 @@ public function testEntityConstraintValidation() {
$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();
......
......@@ -11,6 +11,7 @@
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 @@ public function testNodeHandler() {
$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 @@ public function testCommentHandler() {
);
$nodes = array();
foreach ($node_values as $key => $values) {
$node = entity_create('node', $values);
$node = Node::create($values);
$node->save();
$nodes[$key] = $node;
}
......
......@@ -10,6 +10,7 @@
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 @@ function testUninstallPage() {
$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');
......
......@@ -9,6 +9,7 @@
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 @@ function testContext() {
$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 {
......
......@@ -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 @@ public function testTranslatedTaxonomyTermReferenceDisplay() {
*/
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();
......
......@@ -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 @@ public function testGetEntity() {
$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(),
......
......@@ -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 @@ protected function setUp() {
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']++;
......
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