You are here

class RedhenOrgRouteContext in RedHen CRM 8

Sets the current org as context on redhen org routes.

@todo Remove once core gets a generic EntityRouteContext.

Hierarchy

Expanded class hierarchy of RedhenOrgRouteContext

1 string reference to 'RedhenOrgRouteContext'
redhen_org.services.yml in modules/redhen_org/redhen_org.services.yml
modules/redhen_org/redhen_org.services.yml
1 service uses RedhenOrgRouteContext
redhen_org.org_route_context in modules/redhen_org/redhen_org.services.yml
Drupal\redhen_org\ContextProvider\RedhenOrgRouteContext

File

modules/redhen_org/src/ContextProvider/RedhenOrgRouteContext.php, line 19

Namespace

Drupal\redhen_org\ContextProvider
View source
class RedhenOrgRouteContext implements ContextProviderInterface {
  use StringTranslationTrait;

  /**
   * The route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a new RedhenOrgRouteContext object.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match.
   */
  public function __construct(RouteMatchInterface $route_match) {
    $this->routeMatch = $route_match;
  }

  /**
   * {@inheritdoc}
   */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    $context_definition = new ContextDefinition('entity:redhen_org', NULL, FALSE);
    $value = NULL;
    if ($org = $this->routeMatch
      ->getParameter('redhen_org')) {
      $value = $org;
    }
    elseif ($this->routeMatch
      ->getRouteName() == 'entity.redhen_org.add_form') {
      $org_type = $this->routeMatch
        ->getParameter('redhen_org_type');
      $value = Org::create([
        'type' => $org_type
          ->id(),
      ]);
    }
    $cacheability = new CacheableMetadata();
    $cacheability
      ->setCacheContexts([
      'route',
    ]);
    $context = new Context($context_definition, $value);
    $context
      ->addCacheableDependency($cacheability);
    return [
      'redhen_org' => $context,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContexts() {
    $context = EntityContext::fromEntityTypeId('redhen_org', $this
      ->t('Org from URL'));
    return [
      'redhen_org' => $context,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RedhenOrgRouteContext::$routeMatch protected property The route match.
RedhenOrgRouteContext::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface::getAvailableContexts
RedhenOrgRouteContext::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextProviderInterface::getRuntimeContexts
RedhenOrgRouteContext::__construct public function Constructs a new RedhenOrgRouteContext object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.