You are here

public function AlphaPaginationCharacter::buildLink in Views Alpha Pagination 8.2

Builds a link render array based on current text, value and options.

Parameters

array $options: Optional. Array of options to pass to url().

Return value

array A render array for the link.

1 call to AlphaPaginationCharacter::buildLink()
AlphaPaginationCharacter::build in src/AlphaPaginationCharacter.php
Builds a render array of the character.

File

src/AlphaPaginationCharacter.php, line 105

Class

AlphaPaginationCharacter
Class AlphaPaginationCharacter.

Namespace

Drupal\alpha_pagination

Code

public function buildLink(array $options = []) {

  // Merge in options.
  $options = NestedArray::mergeDeep([
    'attributes' => [],
    'html' => FALSE,
    'query' => \Drupal::request()->query
      ->all(),
  ], $options);

  // Merge in classes.
  $this->alphaPagination
    ->addClasses($this
    ->getOption('paginate_link_class'), $options['attributes']);
  $token = \Drupal::service('token');
  $tokens = $this->alphaPagination
    ->getTokens($this
    ->getValue());
  $path = $token
    ->replace($this
    ->getOption('paginate_link_path'), $tokens);

  // Determine if link is external (automatically enforcing for anchors).
  if ($this
    ->getOption('paginate_link_external') || $path && $path[0] === '#') {
    $options['external'] = TRUE;
  }
  else {
    $path = 'internal:/' . $path;
  }

  // Add in additional attributes.
  if ($this
    ->getOption('paginate_link_attributes')) {
    $attributes = $this->alphaPagination
      ->parseAttributes($this
      ->getOption('paginate_link_attributes'), $tokens);

    // Remove any class attributes (should use the dedicated class option).
    unset($attributes['class']);

    // Merge in the attributes.
    $options['attributes'] = NestedArray::mergeDeep($options['attributes'], $attributes);
  }

  // Build link render array.
  return [
    //      '#theme' => 'link__alpha_pagination',
    '#type' => 'link',
    '#title' => $this
      ->getLabel(),
    '#url' => Url::fromUri($path),
    '#options' => $options,
  ];
}