useMoreText example

// Test the renderMoreLink method directly. This could be directly unit     // tested.     $more_link = $view->display_handler->renderMoreLink();
    $more_link = $renderer->renderRoot($more_link);
    $this->setRawContent($more_link);
    $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
    $this->assertEquals(Url::fromRoute('view.test_display_more.page_1')->toString()$result[0]->attributes()->href, 'The right more link is shown.');
    $this->assertEquals($expected_more_texttrim($result[0][0]), 'The right link text is shown.');

    // Test the useMoreText method directly. This could be directly unit     // tested.     $more_text = $view->display_handler->useMoreText();
    $this->assertEquals($expected_more_text$more_text, 'The right more text is chosen.');

    $view = Views::getView('test_display_more');
    $view->setDisplay();
    $view->display_handler->setOption('use_more', 0);
    $this->executeView($view);
    $output = $view->preview();
    $output = $renderer->renderRoot($output);
    $this->setRawContent($output);
    $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
    $this->assertEmpty($result, 'The more link is not shown.');

    
/** * {@inheritdoc} */
  public function renderMoreLink() {
    $hasMoreRecords = !empty($this->view->pager) && $this->view->pager->hasMoreRecords();
    if ($this->isMoreEnabled() && ($this->useMoreAlways() || $hasMoreRecords)) {
      $url = $this->getMoreUrl();

      return [
        '#type' => 'more_link',
        '#url' => $url,
        '#title' => $this->useMoreText(),
        '#view' => $this->view,
      ];
    }
  }

  /** * Get the more URL for this view. * * Uses the custom URL if there is one, otherwise the display path. * * @return \Drupal\Core\Url * The more link as Url object. */
Home | Imprint | This part of the site doesn't use cookies.