pm-4.1.x-dev/src/PathProcessor/PmPathProcessor.php

src/PathProcessor/PmPathProcessor.php
<?php

namespace Drupal\pm\PathProcessor;

use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Url;

class PmPathProcessor implements OutboundPathProcessorInterface {

  /**
   * {@inheritdoc}
   */
  public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    $key = 'pm-project';
    $target_id = $request ? $request->query->get($key) : '';
    $url = Url::fromUserInput($path);
    // When visiting a project page,
    // always read and override from current project in context.
    if ($url->isRouted()) {
      $params = $url->getRouteParameters();
      if (!empty($params['pm_project'])) {
        $target_id = $params['pm_project'];
      }
    }
    if ($target_id) {
      $options['query'][$key] = $target_id;
    }
    // The path now has a dependency on the url query parameter,
    // add that as a cache context.
    if ($bubbleable_metadata !== NULL) {
      $bubbleable_metadata->addCacheContexts(['url.query_args:' . $key]);
    }
    return $path;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc