MaestroEngineActiveHandler.php in Maestro 8.2
File
src/Plugin/views/field/MaestroEngineActiveHandler.php
View source
<?php
namespace Drupal\maestro\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\maestro\Utility\TaskHandler;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\Core\Url;
class MaestroEngineActiveHandler extends FieldPluginBase {
public function query() {
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['show_as_link'] = [
'default' => '0',
];
$options['link_text'] = [
'default' => $this
->t('Link'),
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['show_as_link'] = [
'#title' => $this
->t('Show as an HTML link'),
'#type' => 'checkbox',
'#default_value' => isset($this->options['show_as_link']) ? $this->options['show_as_link'] : 0,
];
$form['link_text'] = [
'#title' => $this
->t('Text used for the link'),
'#type' => 'textfield',
'#default_value' => isset($this->options['link_text']) ? $this->options['link_text'] : $this
->t('Link'),
'#states' => [
'visible' => [
':input[name="options[show_as_link]"]' => [
'checked' => TRUE,
],
],
],
];
parent::buildOptionsForm($form, $form_state);
}
public function render(ResultRow $values) {
global $base_url;
$item = $values->_entity;
if ($item
->getEntityTypeId() == 'maestro_production_assignments' || $item
->getEntityTypeId() == 'maestro_queue') {
if ($item
->getEntityTypeId() == 'maestro_production_assignments') {
$queueID = $item->queue_id
->getString();
}
else {
$queueID = $item->id
->getString();
}
$taskhandler = TaskHandler::getHandlerURL($queueID);
if (isset($this->options['show_as_link']) && $this->options['show_as_link'] == 1) {
$build['handler'][$queueID]['execute'] = [
'#type' => 'link',
'#title' => isset($this->options['link_text']) ? $this->options['link_text'] : $this
->t('Link'),
'#url' => Url::fromUri($taskhandler),
];
}
else {
$build['handler'][$queueID]['execute'] = [
'#plain_text' => $taskhandler,
];
}
return $build;
}
else {
return '';
}
}
}