MaestroEngineActiveAssignments.php in Maestro 8.2
File
src/Plugin/views/field/MaestroEngineActiveAssignments.php
View source
<?php
namespace Drupal\maestro\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\maestro\Engine\MaestroEngine;
class MaestroEngineActiveAssignments extends FieldPluginBase {
public function query() {
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['show_how_assigned'] = [
'default' => '0',
];
$options['separator_text'] = [
'default' => ',',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['show_how_assigned'] = [
'#title' => $this
->t('When checked, this will add a suffix of :Fixed or :Variable to the assigned entity name.'),
'#type' => 'checkbox',
'#default_value' => isset($this->options['show_how_assigned']) ? $this->options['show_how_assigned'] : 0,
];
$form['separator_text'] = [
'#title' => $this
->t('Text used for separating multiple values. HTML allowed.'),
'#type' => 'textfield',
'#default_value' => isset($this->options['separator_text']) ? $this->options['separator_text'] : ',',
];
parent::buildOptionsForm($form, $form_state);
}
public function render(ResultRow $values) {
$item = $values->_entity;
$output = '';
$assignees = MaestroEngine::getAssignedNamesOfQueueItem($item->id
->getString(), TRUE);
if (count($assignees) == 0) {
return $this
->t('No assignees');
}
else {
foreach ($assignees as $arr) {
if ($output != '') {
$output .= $this->options['separator_text'];
}
$output .= $arr['assign_id'];
if ($this->options['show_how_assigned']) {
$output .= $arr['by_variable'];
}
}
return [
'#markup' => $output,
];
}
}
}