You are here

protected function PullForm::getHeader in Entity Share 8.3

Same name and namespace in other branches
  1. 8.2 modules/entity_share_client/src/Form/PullForm.php \Drupal\entity_share_client\Form\PullForm::getHeader()

Helper function.

Prepare a header sortable link.

Inspired from \Drupal\Core\Utility\TableSort::header().

Parameters

\Drupal\Component\Render\MarkupInterface $header: The header label.

string $header_machine_name: The header machine name.

array $context: The context of sort.

Return value

array A sort link to be put in a table header.

1 call to PullForm::getHeader()
PullForm::buildEntitiesSelectTable in modules/entity_share_client/src/Form/PullForm.php
Helper function to generate entities table.

File

modules/entity_share_client/src/Form/PullForm.php, line 734

Class

PullForm
Form controller to pull entities.

Namespace

Drupal\entity_share_client\Form

Code

protected function getHeader(MarkupInterface $header, $header_machine_name, array $context) {
  $cell = [];
  $title = new TranslatableMarkup('sort by @s', [
    '@s' => $header,
  ]);
  if ($header_machine_name == $context['name']) {

    // aria-sort is a WAI-ARIA property that indicates if items in a table
    // or grid are sorted in ascending or descending order. See
    // http://www.w3.org/TR/wai-aria/states_and_properties#aria-sort
    $cell['aria-sort'] = $context['sort'] == 'asc' ? 'ascending' : 'descending';
    $context['sort'] = $context['sort'] == 'asc' ? 'desc' : 'asc';
    $cell['class'][] = 'is-active';
    $tablesort_indicator = [
      '#theme' => 'tablesort_indicator',
      '#style' => $context['sort'],
    ];
    $image = $this->renderer
      ->render($tablesort_indicator);
  }
  else {

    // If the user clicks a different header, we want to sort ascending
    // initially.
    $context['sort'] = 'asc';
    $image = '';
  }
  $cell['data'] = Link::createFromRoute(new FormattableMarkup('@cell_content@image', [
    '@cell_content' => $header,
    '@image' => $image,
  ]), '<current>', [], [
    'attributes' => [
      'title' => $title,
    ],
    'query' => array_merge($context['query'], [
      'sort' => $context['sort'],
      'order' => $header_machine_name,
    ]),
  ]);
  return $cell;
}