You are here

public function UidToUserNameCallbackProcessor::build in Facets 8

Runs before the renderable array is created.

Parameters

\Drupal\facets\FacetInterface $facet: The facet being changed.

\Drupal\facets\Result\ResultInterface[] $results: The results being changed.

Return value

\Drupal\facets\Result\ResultInterface[] The changed results.

Overrides BuildProcessorInterface::build

File

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

Class

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

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function build(FacetInterface $facet, array $results) {
  $usernames = [];

  /** @var \Drupal\facets\Result\ResultInterface $result */
  foreach ($results as $result) {

    /** @var \Drupal\user\Entity\User $user */
    if (($user = User::load($result
      ->getRawValue())) !== NULL) {
      $result
        ->setDisplayValue($user
        ->getDisplayName());
      $usernames[] = $result;
    }
  }
  return $usernames;
}