You are here

function social_tour_preprocess_container in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  2. 8 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  3. 8.2 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  4. 8.3 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  5. 8.4 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  6. 8.5 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  7. 8.7 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  8. 8.8 modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  9. 10.3.x modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  10. 10.0.x modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  11. 10.1.x modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()
  12. 10.2.x modules/custom/social_tour/social_tour.module \social_tour_preprocess_container()

Implements hook_preprocess_HOOK().

File

modules/custom/social_tour/social_tour.module, line 66
The Social Tour module.

Code

function social_tour_preprocess_container(&$variables) {
  if (!_social_tour_init()) {
    return;
  }

  // In TourViewBuilder.php a container is rendered, this container has
  // children attribute with the total count. If the count of these children
  // is 1, we can unset it. We don't want to show 1 of 1 count.
  if (!empty($variables['attributes']['class'])) {
    foreach ($variables['attributes']['class'] as $class_name) {
      if ($class_name === 'tour-progress') {
        $child_arguments = $variables['children']
          ->getArguments();

        // So we found arguments for tour_progress. This is an array consisting
        // of [ '@tour_item' => integer 1, '@total' => integer 1 ]. If we have
        // a total of one. We can unset it, we don't need a 1 of 1 count.
        if (!empty($child_arguments)) {
          if (!empty($child_arguments['@total']) && $child_arguments['@total'] == 1) {
            unset($variables['children']);
          }
        }

        // We found a tour-progress container and did our magic.
        // We can break out the foreach.
        break;
      }
    }
  }
}