getUrlInfo example


  public function testExposedFormRender() {
    $view = Views::getView('test_exposed_form_buttons');
    $this->executeView($view);
    $exposed_form = $view->display_handler->getPlugin('exposed_form');
    $output = $exposed_form->renderExposedForm();
    $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));

    $this->assertFieldByXpath('//form/@id', Html::cleanCssIdentifier('views-exposed-form-' . $view->storage->id() . '-' . $view->current_display), 'Expected form ID found.');

    $view->setDisplay('page_1');
    $expected_action = $view->display_handler->getUrlInfo()->toString();
    $this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.');
    // Make sure the description is shown.     $result = $this->xpath('//form//div[contains(@id, "edit-type--2--description") and normalize-space(text())="Exposed description"]');
    $this->assertCount(1, $result, 'Filter description was found.');
  }

  /** * Tests the exposed form raw input. */
  public function testExposedFormRawInput() {
    $node_type = NodeType::create(['type' => 'article']);
    
/** * {@inheritdoc} */
  protected function renderLink(ResultRow $row) {
    $entity = $this->getEntity($row);
    if (!$entity) {
      return '';
    }

    $this->options['alter']['make_link'] = TRUE;
    $this->options['alter']['url'] = $this->getUrlInfo($row);

    $title = $this->t('Contact %user', ['%user' => $entity->label()]);
    $this->options['alter']['attributes'] = ['title' => $title];

    if (!empty($this->options['text'])) {
      return $this->options['text'];
    }
    else {
      return $title;
    }
  }

  

  public function render(ResultRow $row) {
    return $this->getEntity($row) ? parent::render($row) : [];
  }

  /** * {@inheritdoc} */
  protected function renderLink(ResultRow $row) {
    if ($this->options['output_url_as_text']) {
      $url_info = $this->getUrlInfo($row);
      return $url_info ? $url_info->toString() : '';
    }
    return parent::renderLink($row);
  }

  /** * {@inheritdoc} */
  protected function getUrlInfo(ResultRow $row) {
    $template = $this->getEntityLinkTemplate();
    $entity = $this->getEntity($row);
    
/** * Checks access to the link route. * * @param \Drupal\views\ResultRow $row * A view result row. * * @return \Drupal\Core\Access\AccessResultInterface|null * The access result, or NULL if the URI elements of the link doesn't exist. */
  protected function checkUrlAccess(ResultRow $row) {
    if ($url = $this->getUrlInfo($row)) {
      return $this->accessManager->checkNamedRoute($url->getRouteName()$url->getRouteParameters()$this->currentUser(), TRUE);
    }
  }

  /** * Returns the URI elements of the link. * * @param \Drupal\views\ResultRow $row * A view result row. * * @return \Drupal\Core\Url|null * The URI elements of the link. */
unset($args[$position]);
          }
          $position++;
        }
      }
    }

    $path = $this->getPath();

    // Don't bother working if there's nothing to do:     if (empty($path) || (empty($args) && !str_contains($path, '%'))) {
      return $display_handler->getUrlInfo();
    }

    $argument_keys = isset($this->argument) ? array_keys($this->argument) : [];
    $id = current($argument_keys);

    /** @var \Drupal\Core\Url $url */
    $url = $display_handler->getUrlInfo();
    $route = $this->routeProvider->getRouteByName($url->getRouteName());

    $variables = $route->compile()->getVariables();
    $parameters = $url->getRouteParameters();

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