You are here

class AdminThemeAdminContext in Administration theme 8

Decorates the core AdminContext to check custom admin paths.

@todo Do not extend the decorated class, implement an interface after https://www.drupal.org/node/2708599.

Hierarchy

Expanded class hierarchy of AdminThemeAdminContext

1 string reference to 'AdminThemeAdminContext'
admin_theme.services.yml in ./admin_theme.services.yml
admin_theme.services.yml
1 service uses AdminThemeAdminContext
admin_theme.admin_context in ./admin_theme.services.yml
\Drupal\admin_theme\Routing\AdminThemeAdminContext

File

src/Routing/AdminThemeAdminContext.php, line 16

Namespace

Drupal\admin_theme\Routing
View source
class AdminThemeAdminContext extends AdminContext {

  /**
   * The decorated admin context service.
   *
   * @var \Drupal\Core\Routing\AdminContext
   */
  protected $subject;

  /**
   * The condition manager.
   *
   * @var \Drupal\Core\Executable\ExecutableManagerInterface
   */
  protected $conditionManager;

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

  /**
   * AdminThemeAdminContext constructor.
   *
   * @param \Drupal\Core\Routing\AdminContext $subject
   *   The decorated admin context service.
   * @param \Drupal\Core\Executable\ExecutableManagerInterface $condition_manager
   *   The condition manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(AdminContext $subject, ExecutableManagerInterface $condition_manager, ConfigFactoryInterface $config_factory) {
    $this->subject = $subject;
    $this->conditionManager = $condition_manager;
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function isAdminRoute(Route $route = NULL) {
    $excludePaths = (string) $this->configFactory
      ->get('admin_theme.settings')
      ->get('exclude_paths');

    /** @var \Drupal\Core\Condition\ConditionInterface $excludeCondition */
    $excludeCondition = $this->conditionManager
      ->createInstance('request_path', [
      'pages' => $excludePaths,
    ]);
    if ($this->conditionManager
      ->execute($excludeCondition)) {
      return FALSE;
    }
    $paths = $this->configFactory
      ->get('admin_theme.settings')
      ->get('paths');

    /** @var \Drupal\Core\Condition\ConditionInterface $condition */
    $condition = $this->conditionManager
      ->createInstance('request_path', [
      'pages' => $paths,
    ]);
    if ($this->conditionManager
      ->execute($condition)) {
      return TRUE;
    }
    return $this->subject
      ->isAdminRoute($route);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminContext::$routeMatch protected property The route match.
AdminThemeAdminContext::$conditionManager protected property The condition manager.
AdminThemeAdminContext::$configFactory protected property The config factory.
AdminThemeAdminContext::$subject protected property The decorated admin context service.
AdminThemeAdminContext::isAdminRoute public function Determines whether the active route is an admin one. Overrides AdminContext::isAdminRoute
AdminThemeAdminContext::__construct public function AdminThemeAdminContext constructor. Overrides AdminContext::__construct