CloneLink.php in Quick Node Clone 8
File
src/Plugin/views/field/CloneLink.php
View source
<?php
namespace Drupal\quick_node_clone\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
class CloneLink extends FieldPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['text'] = [
'default' => $this
->getDefaultLabel(),
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text to display'),
'#default_value' => $this->options['text'],
];
parent::buildOptionsForm($form, $form_state);
}
public function query() {
}
protected function getDefaultLabel() {
return $this
->t('Clone');
}
public function render(ResultRow $values) {
$node = $this
->getEntity($values);
if (!$node) {
return '';
}
$url = Url::fromRoute('quick_node_clone.node.quick_clone', [
'node' => $node
->id(),
]);
if (!$url
->access()) {
return '';
}
return [
'#type' => 'link',
'#url' => $url,
'#title' => $this->options['text'] ?: $this
->getDefaultLabel(),
];
}
}
Classes
Name |
Description |
CloneLink |
Handler for showing quick node clone link. |