MaestroEngineProcessCompletionTime.php in Maestro 3.x
File
src/Plugin/views/field/MaestroEngineProcessCompletionTime.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;
class MaestroEngineProcessCompletionTime extends FieldPluginBase {
public function query() {
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['date_format'] = [
'default' => 'medium',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$options = [
'unix' => $this
->t('Database Timestamp'),
'short' => $this
->t('Short ( 12/01/1901 - 23:59 )'),
'medium' => $this
->t('Medium ( Tue, 12/01/1901 - 23:59 )'),
'long' => $this
->t('Long ( Tuesday, December 1, 1901 - 23:59 )'),
'html_datetime' => $this
->t('HTML5 Date/Time ( YYYY-MM-DDThh:mm:ssTZD )'),
];
$form['date_format'] = [
'#title' => $this
->t('Date Format'),
'#type' => 'select',
'#default_value' => isset($this->options['date_format']) ? $this->options['date_format'] : 'name',
'#options' => $options,
];
parent::buildOptionsForm($form, $form_state);
}
public function render(ResultRow $values) {
$item = $values->_entity;
$timestamp = $item->completed
->getString();
$format = '';
if ($this->options['date_format'] != 'unix') {
if ($timestamp) {
$format = \Drupal::service('date.formatter')
->format($timestamp, $this->options['date_format']);
}
}
else {
$format = $timestamp;
}
return $format;
}
}