protected function CshsMenuParentFormSelector::parentSelectOptionsTreeWalkCshs in Menu Link Weight 8        
                          
                  
                        Same name and namespace in other branches
- 8.2 src/MenuParentFormSelector/CshsMenuParentFormSelector.php \Drupal\menu_link_weight\MenuParentFormSelector\CshsMenuParentFormSelector::parentSelectOptionsTreeWalkCshs()
1 call to CshsMenuParentFormSelector::parentSelectOptionsTreeWalkCshs()
  - CshsMenuParentFormSelector::getParentSelectOptionsCshs in src/MenuParentFormSelector/CshsMenuParentFormSelector.php
File
 
   - src/MenuParentFormSelector/CshsMenuParentFormSelector.php, line 83
Class
  
  - CshsMenuParentFormSelector 
- Implements Client-side hierarchical select (CSHS) as the menu parent form
selector.
Namespace
  Drupal\menu_link_weight\MenuParentFormSelector
Code
protected function parentSelectOptionsTreeWalkCshs(array $tree, $menu_name, $indent, array &$options, $exclude, $depth_limit, CacheableMetadata &$cacheability = NULL) {
  
  foreach ($tree as $element) {
    if ($element->depth > $depth_limit) {
      
      break;
    }
    
    if ($cacheability) {
      $cacheability = $cacheability
        ->merge(CacheableMetadata::createFromObject($element->access))
        ->merge(CacheableMetadata::createFromObject($element->link));
    }
    
    if (!$element->access
      ->isAllowed()) {
      continue;
    }
    $link = $element->link;
    if ($link
      ->getPluginId() != $exclude) {
      $title = Unicode::truncate($link
        ->getTitle(), 30, TRUE, FALSE);
      if (!$link
        ->isEnabled()) {
        $title .= ' (' . $this
          ->t('disabled') . ')';
      }
      $options[$menu_name . ':' . $link
        ->getPluginId()] = [
        'name' => $title,
        'parent_tid' => $indent,
      ];
      if (!empty($element->subtree)) {
        $this
          ->parentSelectOptionsTreeWalkCshs($element->subtree, $menu_name, $menu_name . ':' . $link
          ->getPluginId(), $options, $exclude, $depth_limit, $cacheability);
      }
    }
  }
}