You are here

public function LinkcheckerLinkPageEntityLabel::render in Link checker 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/LinkcheckerLinkPageEntityLabel.php, line 53

Class

LinkcheckerLinkPageEntityLabel
Field handler that builds the page entity label for the linkchecker_link.

Namespace

Drupal\linkchecker\Plugin\views\field

Code

public function render(ResultRow $values) {
  $linkchecker_link = $this
    ->getEntity($values);
  if (!$linkchecker_link instanceof LinkCheckerLinkInterface) {
    return '';
  }
  if (!$linkchecker_link
    ->hasField('entity_id')) {
    return '';
  }
  if ($linkchecker_link
    ->get('entity_id')
    ->isEmpty()) {
    return '';
  }
  $linked_entity = $linkchecker_link
    ->get('entity_id')->entity;
  if (!$linked_entity instanceof EntityInterface) {
    return '';
  }
  if ($linked_entity
    ->getEntityTypeId() === 'paragraph' && $linked_entity
    ->getParentEntity() !== NULL) {
    $linked_entity = $linked_entity
      ->getParentEntity();
  }
  if (!empty($this->options['link_to_entity'])) {
    try {
      $this->options['alter']['url'] = $linked_entity
        ->toUrl();
      $this->options['alter']['make_link'] = TRUE;
    } catch (UndefinedLinkTemplateException $e) {
      $this->options['alter']['make_link'] = FALSE;
    } catch (EntityMalformedException $e) {
      $this->options['alter']['make_link'] = FALSE;
    }
  }
  return $this
    ->sanitizeValue($linked_entity
    ->label());
}