Commit d583b740 authored by webchick's avatar webchick

Issue #2322639 by hussainweb, LinL, Temoor, oenie, MKorostoff, mglaman,...

Issue #2322639 by hussainweb, LinL, Temoor, oenie, MKorostoff, mglaman, kyuubi, unstatu, omers, pcambra, legolasbo, benjy, JeroenT: Replace all instances of node_type_load(), node_type_get_types(), entity_load('node_type') and entity_load_multiple('node_type') with static method calls from DRUPAL SOUTH WOOOO!
parent 84367206
......@@ -12,6 +12,7 @@
use Drupal\comment\CommentInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
/**
......@@ -54,7 +55,7 @@ protected function setUp() {
// Create an article content type only if it does not yet exist, so that
// child classes may specify the standard profile.
$types = node_type_get_types();
$types = NodeType::loadMultiple();
if (empty($types['article'])) {
$this->drupalCreateContentType(array('type' => 'article', 'name' => t('Article')));
}
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\StorageComparer;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\KernelTestBase;
/**
......@@ -102,7 +103,7 @@ public function testRecreateEntity() {
// Verify that there is nothing more to import.
$this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
$content_type = entity_load('node_type', $type_name);
$content_type = NodeType::load($type_name);
$this->assertEqual('Node type one', $content_type->label());
}
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Entity\Plugin\Validation\Constraint\ReferenceAccessConstraint;
use Drupal\Component\Utility\String;
use Drupal\file\Entity\File;
use Drupal\node\Entity\NodeType;
/**
* Uploads a test to a private node and checks access.
......@@ -27,7 +28,7 @@ class FilePrivateTest extends FileFieldTestBase {
protected function setUp() {
parent::setUp();
node_access_test_add_field(entity_load('node_type', 'article'));
node_access_test_add_field(NodeType::load('article'));
node_access_rebuild();
\Drupal::state()->set('node_access_test.private', TRUE);
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\forum\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\node\Entity\NodeType;
/**
* Tests forum block view for private node access.
......@@ -26,7 +27,7 @@ class ForumNodeAccessTest extends WebTestBase {
protected function setUp() {
parent::setUp();
node_access_rebuild();
node_access_test_add_field(entity_load('node_type', 'forum'));
node_access_test_add_field(NodeType::load('forum'));
\Drupal::state()->set('node_access_test.private', TRUE);
}
......
......@@ -10,6 +10,7 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
use Drupal\node\Entity\NodeType;
/**
* Upgrade node types to node.type.*.yml.
......@@ -46,7 +47,7 @@ protected function setUp() {
public function testNodeType() {
$migration = entity_load('migration', 'd6_node_type');
// Test the test_page content type.
$node_type_page = entity_load('node_type', 'test_page');
$node_type_page = NodeType::load('test_page');
$this->assertIdentical($node_type_page->id(), 'test_page', 'Node type test_page loaded');
$this->assertIdentical($node_type_page->displaySubmitted(), TRUE);
......@@ -59,7 +60,7 @@ public function testNodeType() {
$this->assertIdentical($field->getLabel(), 'This is the body field label', 'Body field was found.');
// Test the test_story content type.
$node_type_story = entity_load('node_type', 'test_story');
$node_type_story = NodeType::load('test_story');
$this->assertIdentical($node_type_story->id(), 'test_story', 'Node type test_story loaded');
$this->assertIdentical($node_type_story->displaySubmitted(), TRUE);
......@@ -72,7 +73,7 @@ public function testNodeType() {
$this->assertIdentical($field, NULL, 'No body field found');
// Test the test_event content type.
$node_type_event = entity_load('node_type', 'test_event');
$node_type_event = NodeType::load('test_event');
$this->assertIdentical($node_type_event->id(), 'test_event', 'Node type test_event loaded');
$this->assertIdentical($node_type_event->displaySubmitted(), TRUE);
......
......@@ -240,7 +240,7 @@ function node_mark($nid, $timestamp) {
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
* Use \Drupal\node\Entity\NodeType::loadMultiple().
*
* @see node_type_load()
* @see \Drupal\node\Entity\NodeType::load()
*/
function node_type_get_types() {
return NodeType::loadMultiple();
......@@ -273,7 +273,7 @@ function node_type_get_names() {
* entity bundles.
*/
function node_get_type_label(NodeInterface $node) {
$type = entity_load('node_type', $node->bundle());
$type = NodeType::load($node->bundle());
return $type ? $type->label() : FALSE;
}
......@@ -366,7 +366,7 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') {
function node_entity_extra_field_info() {
$extra = array();
$description = t('Node module element');
foreach (node_type_get_types() as $bundle) {
foreach (NodeType::loadMultiple() as $bundle) {
$extra['node'][$bundle->id()]['display']['links'] = array(
'label' => t('Links'),
'description' => $description,
......
......@@ -85,7 +85,7 @@ public function form(array $form, FormStateInterface $form_state) {
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#disabled' => $type->isLocked(),
'#machine_name' => array(
'exists' => 'node_type_load',
'exists' => ['Drupal\node\Entity\NodeType', 'load'],
'source' => array('name'),
),
'#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array(
......
......@@ -8,7 +8,9 @@
namespace Drupal\node\Plugin\views\argument;
use Drupal\Component\Utility\String as UtilityString;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\views\Plugin\views\argument\String;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Argument handler to accept a node type.
......@@ -17,6 +19,44 @@
*/
class Type extends String {
/**
* NodeType storage controller.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $nodeTypeStorage;
/**
* Constructs a new Node Type object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $node_type_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->nodeTypeStorage = $node_type_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$entity_manager = $container->get('entity.manager');
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$entity_manager->getStorage('node_type')
);
}
/**
* Override the behavior of summaryName(). Get the user friendly version
* of the node type.
......@@ -34,7 +74,7 @@ function title() {
}
function node_type($type_name) {
$type = entity_load('node_type', $type_name);
$type = $this->nodeTypeStorage->load($type_name);
$output = $type ? $type->label() : $this->t('Unknown content type');
return UtilityString::checkPlain($output);
}
......
......@@ -8,8 +8,9 @@
namespace Drupal\node\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\Plugin\views\field\Node;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Field handler to translate a node type into its readable form.
......@@ -20,6 +21,47 @@
*/
class Type extends Node {
/**
* Database Service Object.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $nodeTypeStorage;
/**
* Constructs a new Node Type object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->nodeTypeStorage = $storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$entity_manager = $container->get('entity.manager');
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$entity_manager->getStorage('node_type')
);
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['machine_name'] = array('default' => FALSE);
......@@ -46,7 +88,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
*/
function render_name($data, $values) {
if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') {
$type = entity_load('node_type', $data);
$type = $this->nodeTypeStorage->load($data);
return $type ? $this->t($this->sanitizeValue($type->label())) : '';
}
return $this->sanitizeValue($data);
......
......@@ -7,6 +7,7 @@
namespace Drupal\node\Tests\Config;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\KernelTestBase;
/**
......@@ -56,7 +57,7 @@ public function testImportChange() {
$this->configImporter()->import();
// Check that the updated config was correctly imported.
$node_type = entity_load('node_type', $node_type_id);
$node_type = NodeType::load($node_type_id);
$this->assertEqual($node_type->label(), $new_label, 'Node type name has been updated.');
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Tests\Config;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\KernelTestBase;
/**
......@@ -42,12 +43,12 @@ public function testImportCreateDefault() {
$node_type_id = 'default';
// Check that the content type does not exist yet.
$this->assertFalse(entity_load('node_type', $node_type_id));
$this->assertFalse(NodeType::load($node_type_id));
// Enable node_test_config module and check that the content type
// shipped in the module's default config is created.
$this->container->get('module_installer')->install(array('node_test_config'));
$node_type = entity_load('node_type', $node_type_id);
$node_type = NodeType::load($node_type_id);
$this->assertTrue($node_type, 'The default content type was created.');
}
......@@ -71,7 +72,7 @@ public function testImportCreate() {
$this->configImporter()->import();
// Check that the content type was created.
$node_type = entity_load('node_type', $node_type_id);
$node_type = NodeType::load($node_type_id);
$this->assertTrue($node_type, 'Import node type from staging was created.');
$this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body'));
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\node\Tests;
use Drupal\node\Entity\NodeType;
/**
* Tests behavior of the node access subsystem if the base table is not node.
*
......@@ -33,7 +35,7 @@ class NodeAccessBaseTableTest extends NodeTestBase {
protected function setUp() {
parent::setUp();
node_access_test_add_field(entity_load('node_type', 'article'));
node_access_test_add_field(NodeType::load('article'));
node_access_rebuild();
\Drupal::state()->set('node_access_test.private', TRUE);
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
/**
* Tests node access functionality with multiple languages and two node access
......@@ -49,7 +50,7 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
protected function setUp() {
parent::setUp();
node_access_test_add_field(entity_load('node_type', 'page'));
node_access_test_add_field(NodeType::load('page'));
// Create the 'private' field, which allows the node to be marked as private
// (restricted access) in a given translation.
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
/**
* Tests node_access and db_select() with node_access tag functionality with
......@@ -28,7 +29,7 @@ class NodeAccessLanguageTest extends NodeTestBase {
protected function setUp() {
parent::setUp();
node_access_test_add_field(entity_load('node_type', 'page'));
node_access_test_add_field(NodeType::load('page'));
// After enabling a node access module, the access table has to be rebuild.
node_access_rebuild();
......
......@@ -38,8 +38,10 @@ protected function setUp() {
* Creates a "Basic page" node and verifies its consistency in the database.
*/
function testNodeCreation() {
$node_type_storage = \Drupal::entityManager()->getStorage('node_type');
// Test /node/add page with only one content type.
entity_load('node_type', 'article')->delete();
$node_type_storage->load('article')->delete();
$this->drupalGet('node/add');
$this->assertResponse(200);
$this->assertUrl('node/add/page');
......@@ -62,7 +64,8 @@ function testNodeCreation() {
$this->assertNoText(format_date($node->getCreatedTime()));
// Change the node type setting to show submitted by information.
$node_type = entity_load('node_type', 'page');
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_type = $node_type_storage->load('page');
$node_type->setDisplaySubmitted(TRUE);
$node_type->save();
......@@ -171,7 +174,7 @@ function testNodeAddWithoutContentTypes () {
$this->assertNoLinkByHref('/admin/structure/types/add');
// Test /node/add page without content types.
foreach (entity_load_multiple('node_type') as $entity ) {
foreach (\Drupal::entityManager()->getStorage('node_type')->loadMultiple() as $entity ) {
$entity->delete();
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\node\Tests;
use Drupal\node\Entity\NodeType;
/**
* Tests the UI for controlling node revision behavior.
*
......@@ -39,7 +41,7 @@ function testNodeFormSaveWithoutRevision() {
// Set page revision setting 'create new revision'. This will mean new
// revisions are created by default when the node is edited.
$type = entity_load('node_type', 'page');
$type = NodeType::load('page');
$type->setNewRevision(TRUE);
$type->save();
......
......@@ -11,6 +11,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\simpletest\WebTestBase;
use Drupal\node\Entity\NodeType;
/**
* Tests importing renamed node type via configuration synchronization.
......@@ -132,8 +133,8 @@ public function testConfigurationRename() {
$this->drupalPostForm('admin/config/development/configuration', array(), t('Import all'));
$this->assertText(t('There are no configuration changes to import.'));
$this->assertFalse(entity_load('node_type', $active_type), 'The content no longer exists with the old name.');
$content_type = entity_load('node_type', $staged_type);
$this->assertFalse(NodeType::load($active_type), 'The content no longer exists with the old name.');
$content_type = NodeType::load($staged_type);
$this->assertIdentical($staged_type, $content_type->id());
// Ensure the base field override has been renamed and the value is correct.
......
......@@ -6,6 +6,7 @@
*/
namespace Drupal\node\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
......@@ -29,7 +30,7 @@ class NodeTypeTest extends NodeTestBase {
* Load available node types and validate the returned data.
*/
function testNodeTypeGetFunctions() {
$node_types = node_type_get_types();
$node_types = NodeType::loadMultiple();
$node_names = node_type_get_names();
$this->assertTrue(isset($node_types['article']), 'Node type article is available.');
......@@ -37,7 +38,7 @@ function testNodeTypeGetFunctions() {
$this->assertEqual($node_types['article']->label(), $node_names['article'], 'Correct node type base has been returned.');
$article = entity_load('node_type', 'article');
$article = NodeType::load('article');
$this->assertEqual($node_types['article'], $article, 'Correct node type has been returned.');
$this->assertEqual($node_types['article']->label(), $article->label(), 'Correct node type name has been returned.');
}
......@@ -49,7 +50,7 @@ function testNodeTypeCreation() {
// Create a content type programmaticaly.
$type = $this->drupalCreateContentType();
$type_exists = (bool) entity_load('node_type', $type->id());
$type_exists = (bool) NodeType::load($type->id());
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
// Login a test user.
......@@ -68,7 +69,7 @@ function testNodeTypeCreation() {
'type' => 'foo',
);
$this->drupalPostForm('admin/structure/types/add', $edit, t('Save and manage fields'));
$type_exists = (bool) entity_load('node_type', 'foo');
$type_exists = (bool) NodeType::load('foo');
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Tests\Views;
use Drupal\Component\Utility\String;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/**
* Tests if entity access is respected on a node bulk operations form.
......@@ -52,7 +53,7 @@ protected function setUp() {
$this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node');
node_access_test_add_field(entity_load('node_type', 'article'));
node_access_test_add_field(NodeType::load('article'));
// After enabling a node access module, the access table has to be rebuild.
node_access_rebuild();
......
......@@ -11,6 +11,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\block_content\Entity\BlockContent;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
/**
......@@ -251,7 +252,7 @@ public function testUserWithPermission() {
// then again retrieve the field form, fill it, submit it (so it ends up
// in PrivateTempStore) and then save the entity. Now there should be two
// revisions.
$node_type = entity_load('node_type', 'article');
$node_type = NodeType::load('article');
$node_type->setNewRevision(TRUE);
$node_type->save();
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\node\Entity\NodeType;
/**
* Tests the RDF mappings and RDFa markup of the standard profile.
......@@ -272,7 +273,7 @@ protected function doPageRdfaTests() {
// The standard profile hides the created date on pages. Revert display to
// true for testing.
// @todo Clean-up standard profile defaults.
$node_type = entity_load('node_type', 'page');
$node_type = NodeType::load('page');
$node_type->setDisplaySubmitted(TRUE);
$node_type->save();
......
......@@ -27,6 +27,7 @@
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\block\Entity\Block;
use Drupal\node\Entity\NodeType;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
use Drupal\user\Entity\Role;
......@@ -277,7 +278,7 @@ protected function drupalCreateContentType(array $values = array()) {
if (!isset($values['type'])) {
do {
$id = strtolower($this->randomMachineName(8));
} while (node_type_load($id));
} while (NodeType::load($id));
}
else {
$id = $values['type'];
......
......@@ -12,6 +12,7 @@
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Render\Element;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\node\Entity\NodeType;
/**
* @defgroup entity_crud Entity CRUD, editing, and view hooks
......@@ -1902,7 +1903,7 @@ function hook_entity_extra_field_info() {
$module_language_enabled = \Drupal::moduleHandler()->moduleExists('language');
$description = t('Node module element');
foreach (node_type_get_types() as $bundle) {
foreach (NodeType::loadMultiple() as $bundle) {
// Add also the 'language' select if Language module is enabled and the
// bundle has multilingual support.
......@@ -1940,7 +1941,7 @@ function hook_entity_extra_field_info() {
*/
function hook_entity_extra_field_info_alter(&$info) {
// Force node title to always be at the top of the list by default.
foreach (node_type_get_types() as $bundle) {
foreach (NodeType::loadMultiple() as $bundle) {
if (isset($info['node'][$bundle->type]['form']['title'])) {
$info['node'][$bundle->type]['form']['title']['weight'] = -20;
}
......
......@@ -9,6 +9,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
/**
......@@ -31,7 +32,7 @@ protected function setUp() {
parent::setUp();
node_access_rebuild();
$this->drupalCreateContentType(array('type' => 'page'));
node_access_test_add_field(entity_load('node_type', 'page'));
node_access_test_add_field(NodeType::load('page'));
$this->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN);
\Drupal::state()->set('node_access_test.private', TRUE);
}
......
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