You are here

class RouteEnhancer in Taxonomy Views Integrator 8

Enhancer to set correct views defaults arguments for Term based on TVI.

By default TVI only alter route and change renderer for taxonomy term page. But some modules, like Search API, Facets and others is hardly rely on current_route_match service. This service allows developers to get router parameters for current request current_route_match:getParameters(). This method returns parameters for current route, but if TVI replaces views they still remains taxonomy_term/page_1, or the first view page found by view with taxonomy/term/%. This makes views detection incorrect, and modules behave not as expected.

This srvice fix it. It uses the same logit to find current view id and and display id, and set it as defaults.

Hierarchy

Expanded class hierarchy of RouteEnhancer

1 string reference to 'RouteEnhancer'
tvi.services.yml in ./tvi.services.yml
tvi.services.yml
1 service uses RouteEnhancer
tvi.route_enhancer in ./tvi.services.yml
Drupal\tvi\Enhancer\RouteEnhancer

File

src/Enhancer/RouteEnhancer.php, line 25

Namespace

Drupal\tvi\Enhancer
View source
class RouteEnhancer implements EnhancerInterface {

  /**
   * RouteEnhancer constructor.
   */
  public function __construct(TaxonomyViewsIntegratorManagerInterface $tvi_manager) {
    $this->tviManager = $tvi_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function applies(Route $route) {
    return $route
      ->getPath() == '/taxonomy/term/{taxonomy_term}';
  }

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (!empty($defaults['taxonomy_term']) && ($term = $defaults['taxonomy_term'])) {
      $term_view = $this->tviManager
        ->getTaxonomyTermViewAndDisplayId($term);
      $defaults['view_id'] = $term_view['view_id'];
      $defaults['display_id'] = $term_view['display_id'];
    }
    return $defaults;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteEnhancer::applies protected function
RouteEnhancer::enhance public function Update the defaults based on its own data and the request.
RouteEnhancer::__construct public function RouteEnhancer constructor.