You are here

public function ShurlyLinkDeactivate::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/ShurlyLinkDeactivate.php, line 62

Class

ShurlyLinkDeactivate
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 delete.
  if (\Drupal::currentUser()
    ->hasPermission('Administer short URLs') || \Drupal::currentUser()
    ->hasPermission('Deactivate own URLs') && $uid == $user->uid) {
    $text = !empty($this->options['text']) ? $this->options['text'] : t('deactivate');
    $rid = $values->rid;
    return link::fromTextAndUrl($text, Url::fromUri('internal:/shurly/deactivate/' . $rid, [
      'query' => \Drupal::service('redirect.destination')
        ->getAsArray(),
    ]))
      ->toString();
  }
}