KanbanEntry.php in Content Planner 8
File
modules/content_kanban/src/Component/KanbanEntry.php
View source
<?php
namespace Drupal\content_kanban\Component;
use Drupal\content_kanban\Form\SettingsForm;
use Drupal\content_kanban\EntityTypeConfig;
use Drupal\content_planner\Component\BaseEntry;
use Drupal\Core\Entity\EntityStorageInterface;
class KanbanEntry extends BaseEntry {
protected $entity;
protected $entityTypeConfig;
protected $config;
protected $entityTypeManager;
protected $contentModerationStatus;
public function __construct($entity, $content_moderation_status, EntityTypeConfig $entity_type_config) {
$this->entity = $entity;
$this->contentModerationStatus = $content_moderation_status;
$this->entityTypeConfig = $entity_type_config;
$this->config = \Drupal::config(SettingsForm::CONFIG_NAME);
}
public function build() {
$build = [];
$datetime = new \DateTime();
$entityType = \Drupal::entityTypeManager()
->getStorage($this->entityTypeConfig
->getEntityType());
if ($entityType instanceof EntityStorageInterface) {
$entityKeys = $entityType
->getEntityType()
->getKeys();
$entityId = $entityKeys['id'];
$this->entity->time = $datetime
->format('H:i');
$this->entity->entityLoaded = $entityType
->load($this->entity->{$entityId});
$user_picture = $this
->getUserPictureUrl($entityKeys['uid']);
$build = [
'#theme' => 'content_kanban_column_entry',
'#entity' => $this->entity,
'#entity_id' => $this->entity->{$entityId},
'#entity_type' => $this->entityTypeConfig
->getEntityType(),
'#entity_type_config' => $this->entityTypeConfig,
'#user_picture' => $user_picture,
'#workflow_state' => $this->contentModerationStatus,
'#operation_links' => [
'add' => $this->entity->entityLoaded
->toUrl(),
'edit' => $this->entity->entityLoaded
->toUrl('edit-form'),
'delete' => $this->entity->entityLoaded
->toUrl('delete-form'),
],
'#item_options' => [
'background_color' => $this->entity->entityLoaded
->isPublished() ? 'white' : '#fff4f4',
],
];
}
return $build;
}
protected function getUserPictureUrl($uid) {
if ($this->config
->get('show_user_thumb') && isset($this->entity->{$uid})) {
return $this
->getUserPictureFromCache($this->entity->{$uid}, 'content_kanban_user_thumb');
}
return FALSE;
}
}