Commit c8d8f72d authored by Paulo Henrique Cota Starling's avatar Paulo Henrique Cota Starling Committed by Romain Jarraud
Browse files

Issue #3247913 by romainj, paulocs, victorml, rkoller, beatrizrodrigues: Add a...

Issue #3247913 by romainj, paulocs, victorml, rkoller, beatrizrodrigues: Add a menu link "Manage permissions" for bundles with associated permissions
parent 9bb9c0e2
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
@@ -55,15 +56,23 @@ class ExtraLinks extends DeriverBase implements ContainerDeriverInterface {
   */
  protected $config;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * {@inheritdoc}
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, RouteProviderInterface $route_provider, ThemeHandlerInterface $theme_handler, ConfigFactoryInterface $config_factory) {
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, RouteProviderInterface $route_provider, ThemeHandlerInterface $theme_handler, ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
    $this->entityTypeManager = $entity_type_manager;
    $this->moduleHandler = $module_handler;
    $this->routeProvider = $route_provider;
    $this->themeHandler = $theme_handler;
    $this->config = $config_factory->get('admin_toolbar_tools.settings');
    $this->currentUser = $current_user;
  }

  /**
@@ -75,7 +84,8 @@ class ExtraLinks extends DeriverBase implements ContainerDeriverInterface {
      $container->get('module_handler'),
      $container->get('router.route_provider'),
      $container->get('theme_handler'),
      $container->get('config.factory')
      $container->get('config.factory'),
      $container->get('current_user')
    );
  }

@@ -180,6 +190,17 @@ class ExtraLinks extends DeriverBase implements ContainerDeriverInterface {
              'weight' => 3,
            ] + $base_plugin_definition;
          }
          if ($this->routeExists('entity.' . $bundle->getEntityTypeId() . '.entity_permissions_form')) {
            $links['entity.entity_permissions_form.' . $content_entity . '.default.' . $machine_name] = [
              'title' => $this->t('Manage permissions'),
              'route_name' => 'entity.' . $bundle->getEntityTypeId() . '.entity_permissions_form',
              'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
              'route_parameters' => [
                $bundle->getEntityTypeId() => $machine_name,
              ],
              'weight' => 3,
            ] + $base_plugin_definition;
          }
        }
        if ($this->moduleHandler->moduleExists('devel') && $this->routeExists('entity.' . $content_entity_bundle . '.devel_load')) {
          $links['entity.' . $content_entity_bundle . '.devel_load.' . $machine_name] = [