public function PermissionsByTermDrupalSubContext::createMainMenuItemForNode in Permissions by Term 8.2
@Then /^I create main menu item for node with title "([^"]*)"$/
File
- tests/
src/ Behat/ Context/ permissions_by_term.behat.inc, line 339
Class
- PermissionsByTermDrupalSubContext
- Class PermissionsByTermContext
Namespace
Drupal\Tests\permissions_by_term\Behat\PermissionsByTermDrupalSubContextCode
public function createMainMenuItemForNode(string $nodeTitle) : void {
$query = \Drupal::service('database')
->select('node_field_data', 'nfd')
->fields('nfd', [
'nid',
])
->condition('nfd.title', $nodeTitle);
$menuLink = MenuLinkContent::create([
'title' => $nodeTitle,
'link' => [
'uri' => 'internal:/node/' . $query
->execute()
->fetchField(),
],
'menu_name' => 'main',
'expanded' => TRUE,
]);
$menuLink
->save();
}