You are here

public function KanbanEntry::build in Content Planner 8

Builds the Kanban Entry output.

File

modules/content_kanban/src/Component/KanbanEntry.php, line 76

Class

KanbanEntry
Class KanbanEntry.

Namespace

Drupal\content_kanban\Component

Code

public function build() {
  $build = [];

  // Add time format to Entity.
  $datetime = new \DateTime();

  // Get the entity type and its keys.
  $entityType = \Drupal::entityTypeManager()
    ->getStorage($this->entityTypeConfig
    ->getEntityType());
  if ($entityType instanceof EntityStorageInterface) {
    $entityKeys = $entityType
      ->getEntityType()
      ->getKeys();
    $entityId = $entityKeys['id'];

    // Set needed info on the object.
    $this->entity->time = $datetime
      ->format('H:i');
    $this->entity->entityLoaded = $entityType
      ->load($this->entity->{$entityId});

    // Get User Picture.
    $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;
}