getQueryParameters example

    $element_pages = [];
    $max = $this->getMaxPagerElementId();
    for ($i = 0; $i <= $max$i++) {
      $currentPage = ($pager = $this->getPager($i)) ? $pager->getCurrentPage() : NULL;
      $element_pages[] = ($i == $element) ? $index : $currentPage;
    }
    $query['page'] = implode(',', $element_pages);

    // Merge the query parameters passed to this function with the parameters     // from the current request. In case of collision, the parameters passed     // into this function take precedence.     if ($current_query = $this->pagerParams->getQueryParameters()) {
      $query = array_merge($current_query$query);
    }
    return $query;
  }

  /** * {@inheritdoc} */
  public function getMaxPagerElementId() {
    return $this->maxPagerElementId;
  }

  

  public function queryParameters() {

    // Example query.     $build['pager_table_0'] = $this->buildTestTable(0, 5);

    // Counter of calls to the current pager.     $query_params = $this->pagerParams->getQueryParameters();
    $pager_calls = isset($query_params['pager_calls']) ? ($query_params['pager_calls'] ? $query_params['pager_calls'] : 0) : 0;
    $build['l_pager_pager_0'] = ['#markup' => $this->t('Pager calls: @pager_calls', ['@pager_calls' => $pager_calls])];

    // Pager.     $build['pager_pager_0'] = [
      '#type' => 'pager',
      '#element' => 0,
      '#parameters' => [
        'pager_calls' => ++$pager_calls,
      ],
      '#pre_render' => [
        

  public static function getContextFromRequest(array $headers, Request $request) {
    $context = static::getOrder($headers$request);
    $context['sort'] = static::getSort($headers$request);
    $context['query'] = static::getQueryParameters($request);
    return $context;
  }

  /** * Formats a column header. * * If the cell in question is the column header for the current sort * criterion, it gets special formatting. All possible sort criteria become * links. * * @param string $cell_content * The cell content to format. Passed by reference. * @param array $cell_attributes * The cell attributes. Passed by reference. * @param array $header * An array of column headers in the format described in '#type' => 'table'. * @param array $context * The current table sort context as returned from * TableSort::getContextFromRequest() method. * * @throws \Exception * * @see getContextFromRequest() */
$test_parameters = [
      'other' => 'arbitrary',
    ];
    $request = Request::create('http://example.com', 'GET', array_merge(['page' => '0,10']$test_parameters));

    /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
    $request_stack = $this->container->get('request_stack');
    $request_stack->push($request);

    $pager_params = $this->container->get('pager.parameters');

    $this->assertEquals($test_parameters$pager_params->getQueryParameters());
    $this->assertEquals(0, $pager_params->findPage());
  }

}
Home | Imprint | This part of the site doesn't use cookies.