public function NodeCreationTrait::getNodeByTitle in Drupal 9
Same name and namespace in other branches
- 8 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.
49 calls to NodeCreationTrait::getNodeByTitle()
- BookBreadcrumbTest::createBookNode in core/
modules/ book/ tests/ src/ Functional/ BookBreadcrumbTest.php - Creates a book node.
- BookContentModerationTest::testBookWithPendingRevisions in core/
modules/ book/ tests/ src/ Functional/ BookContentModerationTest.php - Tests that book drafts can not modify the book outline.
- BookRelationshipTest::createBookNode in core/
modules/ book/ tests/ src/ Functional/ Views/ BookRelationshipTest.php - Creates a book node.
- CommentLanguageTest::testCommentLanguage in core/
modules/ comment/ tests/ src/ Functional/ CommentLanguageTest.php - Tests that comment language is properly set.
- ContentTranslationContextualLinksTest::testContentTranslationContextualLinks in core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationContextualLinksTest.php - Tests that a contextual link is available for translating a node.
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\TraitsCode
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;
}