You are here

public function UidToUserNameCallbackProcessor::supportsFacet in Facets 8

Checks if the facet is supported by this widget.

Reasons why this would be unsupported can be chosen by the widget.

Parameters

\Drupal\facets\FacetInterface $facet: The facet to check for.

Return value

bool Returns true when allowed, false otherwise.

Overrides ProcessorPluginBase::supportsFacet

See also

\Drupal\facets\Widget\WidgetPluginInterface::supportsFacet

File

src/Plugin/facets/processor/UidToUserNameCallbackProcessor.php, line 46

Class

UidToUserNameCallbackProcessor
Provides a processor that transforms the results to show the user's name.

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function supportsFacet(FacetInterface $facet) {
  $data_definition = $facet
    ->getDataDefinition();
  if ($data_definition
    ->getDataType() === 'entity_reference' && $data_definition
    ->getTargetDefinition()
    ->getConstraint('EntityType') === "user") {
    return TRUE;
  }
  if (!$data_definition instanceof ComplexDataDefinitionInterface) {
    return FALSE;
  }
  $property_definitions = $data_definition
    ->getPropertyDefinitions();
  foreach ($property_definitions as $definition) {
    if ($definition instanceof DataReferenceDefinitionInterface && $definition
      ->getDataType() === 'entity_reference' && $definition
      ->getTargetDefinition()
      ->getConstraint('EntityType') === "user") {
      return TRUE;
    }
  }
  return FALSE;
}