AuthmapDeleteLink.php in External Authentication 2.0.x
File
src/Plugin/views/field/AuthmapDeleteLink.php
View source
<?php
namespace Drupal\externalauth\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\field\LinkBase;
use Drupal\views\ResultRow;
class AuthmapDeleteLink extends LinkBase {
public function query() {
$this
->addAdditionalFields();
}
protected function renderLink(ResultRow $row) {
if ($this->options['output_url_as_text']) {
return $this
->getUrlInfo($row)
->toString();
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['url'] = $this
->getUrlInfo($row);
$text = !empty($this->options['text']) ? $this
->sanitizeValue($this->options['text']) : $this
->getDefaultLabel();
return $text;
}
protected function getUrlInfo(ResultRow $row) {
return Url::fromRoute('externalauth.authmap_delete_form', [
'provider' => $row->authmap_provider,
'uid' => $row->authmap_uid,
]);
}
protected function getDefaultLabel() {
return $this
->t('delete');
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['output_url_as_text'] = [
'default' => FALSE,
];
$options['absolute'] = [
'default' => FALSE,
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['output_url_as_text'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Output the URL as text'),
'#default_value' => $this->options['output_url_as_text'],
];
$form['absolute'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use absolute link (begins with "http://")'),
'#default_value' => $this->options['absolute'],
'#description' => $this
->t('Enable this option to output an absolute link. Required if you want to use the path as a link destination.'),
];
parent::buildOptionsForm($form, $form_state);
$form['text']['#states']['visible'][':input[name="options[output_url_as_text]"]'] = [
'checked' => FALSE,
];
}
}