menu_ui_get_menu_link_defaults example

'moderation_state[0][state]' => 'draft',
    ];
    $this->drupalGet('node/add/page');
    $this->submitForm($edit, 'Save');

    // Assert that the unpublished node can be selected as a parent menu link     // for users with access to the node.     $node = $this->drupalGetNodeByTitle($node_title);
    $this->assertTrue($node->access('view', $editor_with_unpublished_content_access));
    $this->assertEquals($edit['title[0][value]']$node->getTitle());
    $this->drupalGet('node/add/page');
    $link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
    /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $link */
    $link = MenuLinkContent::load($link_id);
    $this->assertSession()->optionExists('edit-menu-menu-parent', 'main:' . $link->getPluginId());

    // Assert that the unpublished node cannot be selected as a parent menu link     // for users without access to the node.     $editor_without_unpublished_content_access = $this->drupalCreateUser([
      'administer nodes',
      'administer menu',
      'create page content',
      'use editorial transition create_new_draft',
    ]);
/** * Constraint validator for changing the menu settings in pending revisions. */
class MenuSettingsConstraintValidator extends ConstraintValidator {

  /** * {@inheritdoc} */
  public function validate($entity, Constraint $constraint) {
    if (isset($entity) && !$entity->isNew() && !$entity->isDefaultRevision()) {
      $defaults = menu_ui_get_menu_link_defaults($entity);

      // If the menu UI entity builder is not present and the menu property has       // not been set, do not attempt to validate the menu settings since they       // are not being modified.       if (!$values = $entity->menu) {
        return;
      }

      if (trim($values['title']) && !empty($values['menu_parent'])) {
        [$menu_name$parent] = explode(':', $values['menu_parent'], 2);
        $values['menu_name'] = $menu_name;
        
// Check if menu weight is 17.     $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->fieldValueEquals('edit-menu-weight', 17);
    // Verify that the menu link title field has correct maxlength in node edit     // form.     $this->assertSession()->responseMatches('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/');
    // Verify that the menu link description field has correct maxlength in     // node add form.     $this->assertSession()->responseMatches('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/');

    // Disable the menu link, then edit the node--the link should stay disabled.     $link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
    /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $link */
    $link = MenuLinkContent::load($link_id);
    $link->set('enabled', FALSE);
    $link->save();
    $this->drupalGet($node->toUrl('edit-form'));
    $this->submitForm($edit, 'Save');
    $link = MenuLinkContent::load($link_id);
    $this->assertFalse($link->isEnabled(), 'Saving a node with a disabled menu link keeps the menu link disabled.');

    // Edit the node and remove the menu link.     $edit = [
      
Home | Imprint | This part of the site doesn't use cookies.