You are here

function opigno_ilt_preprocess_views_view_field in Opigno Instructor-led Trainings 3.x

Same name and namespace in other branches
  1. 8 opigno_ilt.module \opigno_ilt_preprocess_views_view_field()

Implements hook_preprocess_views_view_field().

Replaces titles of a instructor-led training calendar event with links.

File

./opigno_ilt.module, line 351
Contains opigno_ilt.module.

Code

function opigno_ilt_preprocess_views_view_field(&$vars) {
  $id = $vars['view']
    ->id();
  $field = $vars['field']->field;
  if ($id === 'opigno_calendar' && $field === 'title') {

    /** @var \Drupal\opigno_calendar_event\CalendarEventInterface $entity */
    $entity = $vars['row']->_entity;
    $bundle = $entity
      ->bundle();
    if ($bundle === 'ilt_calendar_event') {
      $title = $vars['field']
        ->getValue($vars['row']);

      /** @var \Drupal\opigno_ilt\ILTInterface $ilt */
      $ilt = $entity
        ->get('field_ilt')->entity;
      if (isset($ilt)) {
        $link = Link::createFromRoute($title, 'entity.opigno_ilt.canonical', [
          'opigno_ilt' => $ilt
            ->id(),
        ]);
        $vars['output'] = $link;
      }
    }
  }
}