You are here

protected function ILTViewBuilder::alterBuild in Opigno Instructor-led Trainings 3.x

Same name and namespace in other branches
  1. 8 src/ILTViewBuilder.php \Drupal\opigno_ilt\ILTViewBuilder::alterBuild()

Specific per-entity building.

Parameters

array $build: The render array that is being created.

\Drupal\Core\Entity\EntityInterface $entity: The entity to be prepared.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

string $view_mode: The view mode that should be used to prepare the entity.

Overrides EntityViewBuilder::alterBuild

File

src/ILTViewBuilder.php, line 69

Class

ILTViewBuilder
Provides a list controller for opigno_ilt entity.

Namespace

Drupal\opigno_ilt

Code

protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  /** @var \Drupal\opigno_ilt\ILTInterface $entity */
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => $entity
      ->getTitle(),
  ];
  $start_date = $entity
    ->getStartDate();
  $end_date = $entity
    ->getEndDate();
  if (isset($start_date) && isset($end_date)) {
    $start_date = DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $start_date);
    $end_date = DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $end_date);
    $end_date_format = $end_date
      ->format('g:i A');
    if ($start_date
      ->format('jS F Y') != $end_date
      ->format('jS F Y')) {
      $end_date_format = $end_date
        ->format('jS F Y - g:i A');
    }
    $build[] = [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this
        ->t('Date: @start to @end', [
        '@start' => $start_date
          ->format('jS F Y - g:i A'),
        '@end' => $end_date_format,
      ]),
    ];
  }
  $build[] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $this
      ->t('Place: @place', [
      '@place' => $entity
        ->getPlace(),
    ]),
  ];
  $trainer_id = $entity
    ->getTrainerId();
  if ($trainer_id) {
    $trainer = \Drupal::entityTypeManager()
      ->getStorage('user')
      ->load($trainer_id);
    if ($trainer) {
      $build[] = [
        '#type' => 'html_tag',
        '#tag' => 'p',
        '#value' => $this
          ->t('Trainer: @trainer', [
          '@trainer' => $trainer
            ->getAccountName(),
        ]),
      ];
    }
  }
  $build[] = $this
    ->buildNavigation($entity);
}