You are here

class SupportTicketRouteContext in Support Ticketing System 8

Sets the current support ticket as a context on support ticket routes.

Hierarchy

Expanded class hierarchy of SupportTicketRouteContext

1 string reference to 'SupportTicketRouteContext'
support_ticket.services.yml in modules/support_ticket/support_ticket.services.yml
modules/support_ticket/support_ticket.services.yml
1 service uses SupportTicketRouteContext
support_ticket.support_ticket_route_context in modules/support_ticket/support_ticket.services.yml
Drupal\support_ticket\ContextProvider\SupportTicketRouteContext

File

modules/support_ticket/src/ContextProvider/SupportTicketRouteContext.php, line 20
Contains \Drupal\support_ticket\ContextProvider\SupportTicketRouteContext.

Namespace

Drupal\support_ticket\ContextProvider
View source
class SupportTicketRouteContext implements ContextProviderInterface {

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

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

  /**
   * {@inheritdoc}
   */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    $result = [];
    $context_definition = new ContextDefinition('entity:support_ticket', NULL, FALSE);
    $value = NULL;
    if (($route_object = $this->routeMatch
      ->getRouteObject()) && ($route_contexts = $route_object
      ->getOption('parameters')) && isset($route_contexts['support_ticket'])) {
      if ($support_ticket = $this->routeMatch
        ->getParameter('support_ticket')) {
        $value = $support_ticket;
      }
    }
    elseif ($this->routeMatch
      ->getRouteName() == 'support_ticket.add') {
      $support_ticket_type = $this->routeMatch
        ->getParameter('support_ticket_type');
      $value = SupportTicket::create(array(
        'type' => $support_ticket_type
          ->id(),
      ));
    }
    $cacheability = new CacheableMetadata();
    $cacheability
      ->setCacheContexts([
      'route',
    ]);
    $context = new Context($context_definition, $value);
    $context
      ->addCacheableDependency($cacheability);
    $result['support_ticket'] = $context;
    return $result;
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContexts() {
    $context = new Context(new ContextDefinition('entity:support_ticket'));
    return [
      'support_ticket' => $context,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SupportTicketRouteContext::$routeMatch protected property The route match object.
SupportTicketRouteContext::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface::getAvailableContexts
SupportTicketRouteContext::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextProviderInterface::getRuntimeContexts
SupportTicketRouteContext::__construct public function Constructs a new SupportTicketRouteContext.