presto-8.x-2.2/modules/presto_contact/presto_contact.install
modules/presto_contact/presto_contact.install
<?php /** * @file * Install, update and uninstall functions for the prest_contact module. */ use Drupal\Core\Language\LanguageInterface; use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\node\Entity\Node; /** * Implements hook_install(). */ function presto_contact_install() { // Create node. $node = Node::create([ 'type' => 'page', 'title' => 'Contact Us', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'uid' => 1, 'status' => 1, 'promote' => 0, 'field_fields' => [], 'path' => [ 'alias' => '/contact', ], ]); $node->save(); // Create pathauto alias. Drupal::service('pathauto.generator') ->updateEntityAlias($node, 'insert'); // Create menu link. $menuLink = MenuLinkContent::create([ 'title' => 'Contact Us', 'link' => [ 'uri' => "internal:/node/{$node->id()}", ], 'menu_name' => 'main', 'weight' => 20, 'expanded' => TRUE, ]); $menuLink->save(); }