You are here

public function ShurlyLinkEdit::render in ShURLy 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/ShurlyLinkEdit.php, line 68

Class

ShurlyLinkEdit
Field handler to provide a link to the short URL entry.

Namespace

Drupal\shurly\Plugin\views\field

Code

public function render(ResultRow $values) {
  $user = \Drupal::currentUser();
  $uid = $this
    ->getValue($values, 'uid');
  $active = $this
    ->getValue($values, 'active');
  if (!$active) {
    return t('deactivated');
  }

  // Only allow the user to view the link if they can actually edit.
  if (\Drupal::currentUser()
    ->hasPermission('Administer short URLs') || \Drupal::currentUser()
    ->hasPermission('Edit own URLs') && $uid == $user->uid) {
    $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
    $rid = $this
      ->getValue($values, 'rid');
    return link::fromTextAndUrl($text, Url::fromUri('internal:/shurly/edit/' . $rid, [
      'query' => \Drupal::service('redirect.destination')
        ->getAsArray(),
    ]))
      ->toString();
  }
}