You are here

class OnlyOneAdminToolbar in Allow a content type only once (Only One) 8

Class OnlyOneAdminToolbar.

Hierarchy

Expanded class hierarchy of OnlyOneAdminToolbar

1 file declares its use of OnlyOneAdminToolbar
OnlyOneAdminToolbarTest.php in modules/onlyone_admin_toolbar/tests/src/Unit/OnlyOneAdminToolbarTest.php
1 string reference to 'OnlyOneAdminToolbar'
onlyone_admin_toolbar.services.yml in modules/onlyone_admin_toolbar/onlyone_admin_toolbar.services.yml
modules/onlyone_admin_toolbar/onlyone_admin_toolbar.services.yml
1 service uses OnlyOneAdminToolbar
onlyone.admin_toolbar in modules/onlyone_admin_toolbar/onlyone_admin_toolbar.services.yml
Drupal\onlyone_admin_toolbar\OnlyOneAdminToolbar

File

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

Namespace

Drupal\onlyone_admin_toolbar
View source
class OnlyOneAdminToolbar implements OnlyOneAdminToolbarInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The route builder.
   *
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routeBuilder;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
   *   The route builder.
   */
  public function __construct(ConfigFactoryInterface $config_factory, RouteBuilderInterface $route_builder) {
    $this->configFactory = $config_factory;
    $this->routeBuilder = $route_builder;
  }

  /**
   * {@inheritdoc}
   */
  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();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OnlyOneAdminToolbar::$configFactory protected property The config factory.
OnlyOneAdminToolbar::$routeBuilder protected property The route builder.
OnlyOneAdminToolbar::rebuildMenu public function Rebuild the menu to change the menu label in the Admin Toolbar module. Overrides OnlyOneAdminToolbarInterface::rebuildMenu
OnlyOneAdminToolbar::__construct public function Constructor.