You are here

protected function PageContextService::buildTaxonomyTermData in Simple Facebook Pixel 8

Builds taxonomy term view content event data.

1 call to PageContextService::buildTaxonomyTermData()
PageContextService::build in src/PageContextService.php
Builds events data.

File

src/PageContextService.php, line 131

Class

PageContextService
Class PageContextService.

Namespace

Drupal\simple_facebook_pixel

Code

protected function buildTaxonomyTermData() {
  $taxonomy_term = $this->request->attributes
    ->get('taxonomy_term');

  // In some cases $taxonomy_term can be just term ID -- not a term object.
  if (is_numeric($taxonomy_term)) {
    $taxonomy_term = $this->entityTypeManager
      ->getStorage('taxonomy_term')
      ->load($taxonomy_term);
  }
  if ($taxonomy_term instanceof TermInterface) {
    $view_content_entities = array_values($this->configFactory
      ->get('view_content_entities'));
    if (in_array('taxonomy_term:' . $taxonomy_term
      ->bundle(), $view_content_entities)) {
      $data = [
        'content_name' => $taxonomy_term
          ->getName(),
        'content_type' => $taxonomy_term
          ->bundle(),
        'content_ids' => [
          $taxonomy_term
            ->id(),
        ],
      ];
      $this->pixelBuilder
        ->addEvent('ViewContent', $data);
    }
  }
}