You are here

public function Generic::processDatabaseRow in Core Views Facets 8

Same name in this branch
  1. 8 src/Plugin/facets/processor/contextual_filter_type/Generic.php \Drupal\core_views_facets\Plugin\facets\processor\contextual_filter_type\Generic::processDatabaseRow()
  2. 8 src/Plugin/facets/processor/exposed_filter_type/Generic.php \Drupal\core_views_facets\Plugin\facets\processor\exposed_filter_type\Generic::processDatabaseRow()

Throws

\Exception

Overrides CoreViewsFacetsFilterType::processDatabaseRow

File

src/Plugin/facets/processor/contextual_filter_type/Generic.php, line 46

Class

Generic
A generic filter type for core views.

Namespace

Drupal\core_views_facets\Plugin\facets\processor\contextual_filter_type

Code

public function processDatabaseRow(\stdClass $row, HandlerBase $handler, FacetInterface $facet) {
  $result = parent::processDatabaseRow($row, $handler, $facet);
  $exception = NULL;
  if ($entity_type = $handler
    ->getEntityType()) {
    try {
      switch ($entity_type) {
        case 'taxonomy_term':
          $entity_field = $handler->definition['field_name'];
          break;
        default:
          $entity_field = $handler->realField;
          break;
      }
      $entities = $this
        ->entityTypeManager()
        ->getStorage($entity_type)
        ->loadByProperties([
        $entity_field => $result
          ->getRawValue(),
      ]);
      $entity = reset($entities);
      if ($entity) {
        $bundle = $entity
          ->bundle();
        if ($bundle != $entity
          ->getEntityTypeId() && $bundle == $result
          ->getRawValue()) {
          $result
            ->setDisplayValue($result
            ->getRawValue());
        }
        else {
          $result
            ->setDisplayValue($entity
            ->label());
        }
      }
    } catch (\Exception $e) {
      $exception = $e;
    }
  }
  if ($exception) {
    watchdog_exception('facets', $exception, t('The core_views_facets module tried at least once to generically handle the unknown views filter type %filter_type and failed.'), [
      '%filter_type' => $handler->pluginId,
    ], RfcLogLevel::NOTICE);
  }
  return $result;
}