public TourViewBuilder::viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL)
Builds the render array for the provided entities.
Parameters
array $entities: An array of entities implementing EntityInterface to view.
string $view_mode: (optional) The view mode that should be used to render the entity.
string $langcode: (optional) For which language the entity should be rendered, defaults to the current content language.
Return value
A render array for the entities, indexed by the same keys as the entities array passed in $entities.
Throws
\InvalidArgumentException Can be thrown when the set of parameters is inconsistent, like when trying to view Comments and passing a Node which is not the one the comments belongs to, or not passing one, and having the comments node not be available for loading.
Overrides EntityViewBuilder::viewMultiple
File
- core/modules/tour/src/TourViewBuilder.php, line 16
Class
- TourViewBuilder
- Provides a Tour view builder.
Namespace
Drupal\tour
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | public function viewMultiple( array $entities = array (), $view_mode = 'full' , $langcode = NULL) { /** @var \Drupal\tour\TourInterface[] $entities */ $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-' . Html::cleanCssIdentifier( $entity ->getModule()), 'tip-type-' . Html::cleanCssIdentifier( $tip ->getPluginId()), 'tip-' . Html::cleanCssIdentifier( $tip ->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 , '#list_type' => 'ol' , '#attributes' => array ( 'id' => 'tour' , 'class' => array ( 'hidden' , ), ), '#cache' => [ 'tags' => $entity ->getCacheTags(), ], ); } } // If at least one tour was built, attach the tour library. if ( $build ) { $build [ '#attached' ][ 'library' ][] = 'tour/tour' ; } return $build ; } |
Please login to continue.