You are here

public function OnlyOneAdminToolbar::rebuildMenu in Allow a content type only once (Only One) 8

Rebuild the menu to change the menu label in the Admin Toolbar module.

The menu will be rebuilded if the content type is configured to have only one node.

Parameters

string $content_type: The content type machine name.

Overrides OnlyOneAdminToolbarInterface::rebuildMenu

File

modules/onlyone_admin_toolbar/src/OnlyOneAdminToolbar.php, line 43

Class

OnlyOneAdminToolbar
Class OnlyOneAdminToolbar.

Namespace

Drupal\onlyone_admin_toolbar

Code

public function rebuildMenu($content_type) {

  // Getting the configured content types.
  $onlyone_content_types = $this->configFactory
    ->get('onlyone.settings')
    ->get('onlyone_node_types');

  // Checking if the content type is configured.
  if (in_array($content_type, $onlyone_content_types)) {

    // If is configured then we need to rebuild the menu.
    $this->routeBuilder
      ->rebuild();
  }
}