function NodeCreationTrait::getNodeByTitle
Same name and namespace in other branches
- 8.9.x core/modules/node/tests/src/Traits/NodeCreationTrait.php \Drupal\Tests\node\Traits\NodeCreationTrait::getNodeByTitle()
- 10 core/modules/node/tests/src/Traits/NodeCreationTrait.php \Drupal\Tests\node\Traits\NodeCreationTrait::getNodeByTitle()
- 11.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.
38 calls to NodeCreationTrait::getNodeByTitle()
- 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.
- DateTimeWidgetTest::testDateonlyDefaultValue in core/
modules/ datetime/ tests/ src/ Functional/ DateTimeWidgetTest.php - Test default value functionality.
- EarlyDateTest::testTaxonomyEarlyDateNode in core/
modules/ taxonomy/ tests/ src/ Functional/ EarlyDateTest.php - Tests taxonomy functionality with nodes prior to 1970.
- EntityTranslationFormTest::testEntityFormLanguage in core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityTranslationFormTest.php - Tests entity form language.
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.