public function TourRenderController::viewMultiple

Overrides \Drupal\Core\Entity\EntityRenderController::viewMultiple().

Overrides EntityRenderController::viewMultiple

File

drupal/core/modules/tour/lib/Drupal/tour/TourRenderController.php, line 21
Contains \Drupal\tour\TourRenderController.

Class

TourRenderController
Provides a Tour render controller.

Namespace

Drupal\tour

Code

public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
  $build = array();
  foreach ($entities as $entity_id => $entity) {
    $tips = $entity
      ->getTips();
    $count = count($tips);
    $list_items = array();
    foreach ($tips as $index => $tip) {
      if ($output = $tip
        ->getOutput()) {
        $attributes = array(
          'class' => array(
            'tip-module-' . drupal_clean_css_identifier($entity
              ->get('module')),
            'tip-type-' . drupal_clean_css_identifier($tip
              ->get('plugin')),
            'tip-' . drupal_clean_css_identifier($tip
              ->get('id')),
          ),
        );
        $list_items[] = array(
          'output' => $output,
          'counter' => array(
            '#type' => 'container',
            '#attributes' => array(
              'class' => array(
                'tour-progress',
              ),
            ),
            '#children' => t('!tour_item of !total', array(
              '!tour_item' => $index + 1,
              '!total' => $count,
            )),
          ),
          '#wrapper_attributes' => $tip
            ->getAttributes() + $attributes,
        );
      }
    }

    // If there is at least one tour item, build the tour.
    if ($list_items) {
      end($list_items);
      $key = key($list_items);
      $list_items[$key]['#wrapper_attributes']['data-text'] = t('End tour');
      $build[$entity_id] = array(
        '#theme' => 'item_list',
        '#items' => $list_items,
        '#type' => 'ol',
        '#attributes' => array(
          'id' => 'tour',
          'class' => array(
            'element-hidden',
          ),
        ),
      );
    }
  }

  // If at least one tour was built, attach the tour library.
  if ($build) {
    $build['#attached']['library'][] = array(
      'tour',
      'tour',
    );
  }
  return $build;
}