original_string: private function addCategoriesToTemplate(FrontendTemplate $template, Module $module, Collection $categories)
      {
          $data = [];
          $list = [];
          $cssClasses = trimsplit(' ', $template->class);
  
          /** @var NewsCategoryModel $category */
          foreach ($categories as $category) {
              // Skip the categories not eligible for the current module
              if (!$this->manager->isVisibleForModule($category, $module)) {
                  continue;
              }
  
              // Add category to data and list
              $data[$category->id] = $this->generateCategoryData($category, $module);
              $list[$category->id] = $category->getTitle();
  
              // Add the category CSS classes to news class
              $cssClasses = \array_merge($cssClasses, trimsplit(' ', $category->getCssClass()));
          }
  
          // Sort the categories data alphabetically
          \uasort($data, function ($a, $b) {
              return \strnatcasecmp($a['name'], $b['name']);
          });
  
          // Sort the category list alphabetically
          \asort($list);
  
          $template->categories = $data;
          $template->categoriesList = $list;
  
          if (count($cssClasses = \array_unique($cssClasses)) > 0) {
              $template->class = ' ' . \implode(' ', $cssClasses);
          }
      }
code: private function addCategoriesToTemplate(FrontendTemplate $template, Module $module, Collection $categories)
      {
          $data = [];
          $list = [];
          $cssClasses = trimsplit(' ', $template->class);
  
          /** @var NewsCategoryModel $category */
          foreach ($categories as $category) {
              // Skip the categories not eligible for the current module
              if (!$this->manager->isVisibleForModule($category, $module)) {
                  continue;
              }
  
              // Add category to data and list
              $data[$category->id] = $this->generateCategoryData($category, $module);
              $list[$category->id] = $category->getTitle();
  
              // Add the category CSS classes to news class
              $cssClasses = \array_merge($cssClasses, trimsplit(' ', $category->getCssClass()));
          }
  
          // Sort the categories data alphabetically
          \uasort($data, function ($a, $b) {
              return \strnatcasecmp($a['name'], $b['name']);
          });
  
          // Sort the category list alphabetically
          \asort($list);
  
          $template->categories = $data;
          $template->categoriesList = $list;
  
          if (count($cssClasses = \array_unique($cssClasses)) > 0) {
              $template->class = ' ' . \implode(' ', $cssClasses);
          }
      }
code_tokens: private function addCategoriesToTemplate ( FrontendTemplate $ template , Module $ module , Collection $ categories ) { $ data = [ ] ; $ list = [ ] ; $ cssClasses = trimsplit ( ' ' , $ template -> class ) ; /** @var NewsCategoryModel $category */ foreach ( $ categories as $ category ) { // Skip the categories not eligible for the current module if ( ! $ this -> manager -> isVisibleForModule ( $ category , $ module ) ) { continue ; } // Add category to data and list $ data [ $ category -> id ] = $ this -> generateCategoryData ( $ category , $ module ) ; $ list [ $ category -> id ] = $ category -> getTitle ( ) ; // Add the category CSS classes to news class $ cssClasses = \ array_merge ( $ cssClasses , trimsplit ( ' ' , $ category -> getCssClass ( ) ) ) ; } // Sort the categories data alphabetically \ uasort ( $ data , function ( $ a , $ b ) { return \ strnatcasecmp ( $ a [ 'name' ] , $ b [ 'name' ] ) ; } ) ; // Sort the category list alphabetically \ asort ( $ list ) ; $ template -> categories = $ data ; $ template -> categoriesList = $ list ; if ( count ( $ cssClasses = \ array_unique ( $ cssClasses ) ) > 0 ) { $ template -> class = ' ' . \ implode ( ' ' , $ cssClasses ) ; } }
docstring: Add categories to the template.
  
  @param FrontendTemplate $template
  @param Module           $module
  @param Collection       $categories
docstring_tokens: Add categories to the template .