countMenuLinks example

return new static(
      $container->get('plugin.manager.menu.link'),
      $container->get('database')
    );
  }

  /** * {@inheritdoc} */
  public function getDescription() {
    $caption = '';
    $num_links = $this->menuLinkManager->countMenuLinks($this->entity->id());
    if ($num_links) {
      $caption .= '<p>' . $this->formatPlural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined links will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', ['%title' => $this->entity->label()]) . '</p>';
    }
    $caption .= '<p>' . $this->t('This action cannot be undone.') . '</p>';
    return $caption;
  }

  /** * {@inheritdoc} */
  protected function logDeletionMessage() {
    
$this->menu = $this->addCustomMenu();
    $this->doMenuTests();
    $this->doTestMenuBlock();
    $this->addInvalidMenuLink();
    $this->addCustomMenuCRUD();

    // Verify that the menu links rebuild is idempotent and leaves the same     // number of links in the table.     /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
    $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
    $before_count = $menu_link_manager->countMenuLinks(NULL);
    $menu_link_manager->rebuild();
    $after_count = $menu_link_manager->countMenuLinks(NULL);
    $this->assertSame($before_count$after_count, 'MenuLinkManager::rebuild() does not add more links');
    // Do standard user tests.     // Log in the user.     $this->drupalLogin($this->authenticatedUser);
    $this->verifyAccess(403);

    foreach ($this->items as $item) {
      // Menu link URIs are stored as 'internal:/node/$nid'.       $node = Node::load(str_replace('internal:/node/', '', $item->link->uri));
      

  public function testBasicMethods() {
    $this->doTestEmptyStorage();
    $this->doTestTable();
  }

  /** * Ensures that there are no menu links by default. */
  protected function doTestEmptyStorage() {
    $this->assertEquals(0, $this->treeStorage->countMenuLinks());
  }

  /** * Ensures that table gets created on the fly. */
  protected function doTestTable() {
    // Test that we can create a tree storage with an arbitrary table name and     // that selecting from the storage creates the table.     $tree_storage = new MenuTreeStorage($this->container->get('database')$this->container->get('cache.menu')$this->container->get('cache_tags.invalidator'), 'test_menu_tree');
    $this->assertFalse($this->connection->schema()->tableExists('test_menu_tree'), 'Test table is not yet created');
    $tree_storage->countMenuLinks();
    
/** * {@inheritdoc} */
  public function menuNameInUse($menu_name) {
    $this->treeStorage->menuNameInUse($menu_name);
  }

  /** * {@inheritdoc} */
  public function countMenuLinks($menu_name = NULL) {
    return $this->treeStorage->countMenuLinks($menu_name);
  }

  /** * {@inheritdoc} */
  public function getParentIds($id) {
    if ($this->getDefinition($id, FALSE)) {
      return $this->treeStorage->getRootPathIds($id);
    }
    return NULL;
  }

  
Home | Imprint | This part of the site doesn't use cookies.