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
- class \Drupal\redhen_org\ContextProvider\RedhenOrgRouteContext implements ContextProviderInterface uses StringTranslationTrait
 
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
File
- modules/
redhen_org/ src/ ContextProvider/ RedhenOrgRouteContext.php, line 19  
Namespace
Drupal\redhen_org\ContextProviderView 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
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            RedhenOrgRouteContext:: | 
                  protected | property | The route match. | |
| 
            RedhenOrgRouteContext:: | 
                  public | function | 
            Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: | 
                  |
| 
            RedhenOrgRouteContext:: | 
                  public | function | 
            Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: | 
                  |
| 
            RedhenOrgRouteContext:: | 
                  public | function | Constructs a new RedhenOrgRouteContext object. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. |