GathercontentStatusColorField.php in GatherContent 8.4
File
gathercontent_ui/src/Plugin/views/field/GathercontentStatusColorField.php
View source
<?php
namespace Drupal\gathercontent_ui\Plugin\views\field;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
class GathercontentStatusColorField extends FieldPluginBase {
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->field_alias = 'item_status';
}
public function usesGroupBy() {
return FALSE;
}
public function query() {
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['hide_alter_empty'] = [
'default' => FALSE,
];
return $options;
}
public function render(ResultRow $values) {
$entity = $values->_entity;
return [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => ' ',
'#attributes' => [
'style' => 'width:20px; height: 20px; float: left; margin-right: 5px; background: ' . $entity
->getItemStatusColor(),
],
];
}
}