isResettable example


  public function getOperations(): array {
    $operations = [];

    $operations['edit'] = [
      'title' => $this->t('Edit'),
      'url' => $this->getEditRoute(),
    ];

    // Links can either be reset or deleted, not both.     if ($this->isResettable()) {
      $operations['reset'] = [
        'title' => $this->t('Reset'),
        'url' => $this->getResetRoute(),
      ];
    }
    elseif ($this->isDeletable()) {
      $operations['delete'] = [
        'title' => $this->t('Delete'),
        'url' => $this->getDeleteRoute(),
      ];
    }

    
'uri' => 'internal:/'],
      ],
      '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.
/** * 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. */
  public function linkIsResettable(MenuLinkInterface $menu_link_plugin) {
    return AccessResult::allowedIf($menu_link_plugin->isResettable())->setCacheMaxAge(0);
  }

}


  /** * {@inheritdoc} */
  public function deleteLinksInMenu($menu_name) {
    foreach ($this->treeStorage->loadByProperties(['menu_name' => $menu_name]) as $plugin_id => $definition) {
      $instance = $this->createInstance($plugin_id);
      if ($instance->isDeletable()) {
        $this->deleteInstance($instance, TRUE);
      }
      elseif ($instance->isResettable()) {
        $new_instance = $this->resetInstance($instance);
        $affected_menus[$new_instance->getMenuName()] = $new_instance->getMenuName();
      }
    }
  }

  /** * Deletes a specific instance. * * @param \Drupal\Core\Menu\MenuLinkInterface $instance * The plugin instance to be deleted. * @param bool $persist * If TRUE, calls MenuLinkInterface::deleteLink() on the instance. * * @throws \Drupal\Component\Plugin\Exception\PluginException * If the plugin instance does not support deletion. */
Home | Imprint | This part of the site doesn't use cookies.