Drupal 7: Выпадающий список ссылок при помощи CTools
Опубликовано: 09.10.2017
Все мы используем Views и видели выпадающие списки с ссылками для различных операций с представлениями.
CTools шаблон
Можно воспользоваться возможностями CTools.
$links = array( array('title' => t('Content'), 'href' => 'admin/content'), array('title' => t('Structure'), 'href' => 'admin/structure'), array('title' => t('Modules'), 'href' => 'admin/modules'), ); print theme('links__ctools_dropbutton', array('links' => $links));Собственный шаблон
Для того что бы реализовать выпадающий список ссылок, достаточно объявить функцию темизации и ее callback.
прикол угар
/** * Implements hook_theme(). */ function ctools_twisty_dropbutton_theme() { return array( 'ctools_twisty_dropbutton' => array( 'variables' => array( 'links' => array(), ), ), ); } /** * Theme function for twisty dropdown. */ function theme_ctools_twisty_dropbutton($variables) { $links = $variables['links']; if (count($links) > 1) { ctools_add_js('dropbutton'); ctools_add_css('dropbutton'); } ctools_add_css('button'); // Unique identifier buttons. static $twisty_id = 0; $twisty_id++; $output = '<div class="ctools-dropbutton ctools-button" id="ctools-button-' . $twisty_id . '">'; $output .= '<div class="ctools-link">'; $output .= '<a href="#" class="ctools-twisty ctools-text">' . t('open') . '</a>'; $output .= '</div>'; $output .= '<div class="ctools-content">'; $output .= theme('item_list', array('items' => $links)); $output .= '</div>'; $output .= '</div>'; return $output; }
После этого можно отобразить данный список передав в функцию список ссылок.
$links = array(); $links[] = l(t('Content'), 'admin/content'); $links[] = l(t('Structure'), 'admin/structure'); $links[] = l(t('Modules'), 'admin/modules'); print theme('ctools_twisty_dropbutton', array('links' => $links));Github