resetLink example


      'bundle' => 'menu_name',
    ]);
    $menu_link_2->save();
    $this->verifyPageCache($url, 'MISS');

    // Verify a cache hit.     $this->verifyPageCache($url, 'HIT');

    // Verify that after resetting the first menu link, there is a cache miss.     $this->assertTrue($menu_link->isResettable(), 'First link can be reset');
    $menu_link = $menu_link_manager->resetLink($menu_link->getPluginId());
    $this->verifyPageCache($url, 'MISS');

    // Verify a cache hit.     $this->verifyPageCache($url, 'HIT', $expected_tags);

    // Verify that after deleting the menu, there is a cache miss.     $menu->delete();
    $this->verifyPageCache($url, 'MISS');

    // Verify a cache hit.     $this->verifyPageCache($url, 'HIT', ['config:block_list', 'config:user.role.anonymous', 'http_response', 'rendered']);
  }
public function buildForm(array $form, FormStateInterface $form_state, MenuLinkInterface $menu_link_plugin = NULL) {
    $this->link = $menu_link_plugin;

    $form = parent::buildForm($form$form_state);
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->link = $this->menuLinkManager->resetLink($this->link->getPluginId());
    $this->messenger()->addStatus($this->t('The menu link was reset to its default settings.'));
    $form_state->setRedirectUrl($this->getCancelUrl());
  }

  /** * Checks access based on whether the link can be reset. * * @param \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin * The menu link plugin being checked. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */
Home | Imprint | This part of the site doesn't use cookies.