function NodeCreationTrait::getNodeByTitle

Same name and namespace in other branches
  1. 11.x core/modules/node/tests/src/Traits/NodeCreationTrait.php \Drupal\Tests\node\Traits\NodeCreationTrait::getNodeByTitle()
  2. 10 core/modules/node/tests/src/Traits/NodeCreationTrait.php \Drupal\Tests\node\Traits\NodeCreationTrait::getNodeByTitle()
  3. 8.9.x core/modules/node/tests/src/Traits/NodeCreationTrait.php \Drupal\Tests\node\Traits\NodeCreationTrait::getNodeByTitle()

Get a node from the database based on its title.

Parameters

string|\Drupal\Component\Render\MarkupInterface $title: A node title, usually generated by $this->randomMachineName().

$reset: (optional) Whether to reset the entity cache.

Return value

\Drupal\node\NodeInterface A node entity matching $title.

8 calls to NodeCreationTrait::getNodeByTitle()
DbLogTest::doNode in core/modules/dblog/tests/src/Functional/DbLogTest.php
Generates and then verifies some node events.
FileFieldDisplayTest::testDescToggle in core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
Tests description toggle for field instance configuration.
FileFieldWidgetTest::doTestTemporaryFileRemovalExploit in core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
Helper for testing exploiting the temporary file removal using fid.
FileFieldWidgetTest::testPrivateFileComment in core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
Tests that download restrictions on private files work on comments.
FilePrivateTest::testPrivateFile in core/modules/file/tests/src/Functional/FilePrivateTest.php
Tests file access for file uploaded to a private node.

... See full list

File

core/modules/node/tests/src/Traits/NodeCreationTrait.php, line 26

Class

NodeCreationTrait
Provides methods to create node based on default settings.

Namespace

Drupal\Tests\node\Traits

Code

public function getNodeByTitle($title, $reset = FALSE) {
  if ($reset) {
    \Drupal::entityTypeManager()->getStorage('node')
      ->resetCache();
  }
  // Cast MarkupInterface objects to string.
  $title = (string) $title;
  $nodes = \Drupal::entityTypeManager()->getStorage('node')
    ->loadByProperties([
    'title' => $title,
  ]);
  // Load the first node returned from the database.
  $returned_node = reset($nodes);
  return $returned_node;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.