menu_bean.module in Menu Bean 7
Bean Plugin definition
File
menu_bean.moduleView source
<?php
/**
* @file
* Bean Plugin definition
*/
/**
* Implements hook_bean_types_api_info().
*/
function menu_bean_bean_types_api_info() {
return array(
'api' => 4,
);
}
/**
* Implements hook_bean_types().
*
* Beans uses ctools plugins to define the block types.
* All plugin files must be registered in the .info file.
*/
function menu_bean_bean_types() {
$plugins = array();
$plugins['menu_bean'] = array(
'label' => t('Menu'),
'description' => t('A Block Type that allows the creation of dynamic menus'),
'abstract' => FALSE,
'handler' => array(
'class' => 'MenuBeanType',
'parent' => 'bean',
'path' => drupal_get_path('module', 'menu_bean') . '/plugins',
'file' => 'MenuBeanType.class.php',
),
);
return $plugins;
}
/**
* Get the settings plugins
*
* format of setting info array. Every class should implement SettingInterface
*/
function menu_bean_get_settings($key = NULL) {
$settings =& drupal_static(__FUNCTION__, NULL);
if (!$settings) {
$settings = module_invoke_all('menu_bean_setting_info');
drupal_alter('menu_bean_setting_info', $settings);
// Only classes that implement SettingInterface will pass
$settings = array_filter($settings, function ($setting) {
$ref_class = new ReflectionClass(menu_bean_get_settings_class($setting));
if (in_array('Drupal\\menu_bean\\Setting\\SettingInterface', $ref_class
->getInterfaceNames())) {
return TRUE;
}
return FALSE;
});
}
if ($key) {
return $settings[$key];
}
return $settings;
}
/**
* Get the setting class
*
* @param string $key
*
* @return Drupal\menu_bean\Setting\SettingInterface
*/
function menu_bean_load_setting_class($key) {
$settings = menu_bean_get_settings($key);
return $settings['factory']::getSettingInstance($key, $settings);
}
/**
* Get the class name from the settings array
*
* @param settings
*/
function menu_bean_get_settings_class($settings) {
return $settings['class'];
}
/**
* Implements menu_bean_setting_info().
*/
function menu_bean_menu_bean_setting_info() {
return array(
'menu_bean_expanded' => array(
'factory' => 'Drupal\\menu_bean\\SettingsFactory',
'class' => 'Drupal\\menu_bean\\Setting\\ExpandedSetting',
'default_values' => array(
'expanded' => false,
),
),
'menu_bean_i18n' => array(
'factory' => 'Drupal\\menu_bean\\SettingsFactory',
'class' => 'Drupal\\menu_bean\\Setting\\i18nSetting',
'default_values' => array(),
),
'menu_bean_depth' => array(
'factory' => 'Drupal\\menu_bean\\SettingsFactory',
'class' => 'Drupal\\menu_bean\\Setting\\DepthSetting',
'default_values' => array(
'depth' => 0,
),
),
'menu_bean_level' => array(
'factory' => 'Drupal\\menu_bean\\SettingsFactory',
'class' => 'Drupal\\menu_bean\\Setting\\LevelSetting',
'default_values' => array(
'level' => 1,
'parent_mlid' => 0,
),
),
);
}
/**
* Get the initial plugin that builds the menutree
*/
function menu_bean_get_initial_plugin_key() {
return variable_get("menu_get_initial_plugin_key", "menu_bean_expanded");
}
/**
* Add the active trail indicators into the tree.
*
* The data returned by menu_tree_page_data() has link['in_active_trail'] set to
* TRUE for each menu item in the active trail. The data returned from
* menu_tree_all_data() does not contain the active trail indicators. This is a
* helper function that adds it back in.
*
* From menu_block
*
* @param $tree
* array The menu tree.
* @return void void
*/
function menu_bean_tree_add_active_path($tree) {
// Grab any menu item to find the menu_name for this tree.
$menu_item = current($tree);
$tree_with_trail = menu_tree_page_data($menu_item['link']['menu_name']);
// To traverse the original tree down the active trail, we use a pointer.
$subtree_pointer =& $tree;
// Find each key in the active trail.
while ($tree_with_trail) {
foreach ($tree_with_trail as $key => &$value) {
if ($tree_with_trail[$key]['link']['in_active_trail']) {
// Set the active trail info in the original tree.
$subtree_pointer[$key]['link']['in_active_trail'] = TRUE;
// Continue in the subtree, if it exists.
$tree_with_trail =& $tree_with_trail[$key]['below'];
$subtree_pointer =& $subtree_pointer[$key]['below'];
break;
}
else {
unset($tree_with_trail[$key]);
}
}
}
}
Functions
Name | Description |
---|---|
menu_bean_bean_types | Implements hook_bean_types(). |
menu_bean_bean_types_api_info | Implements hook_bean_types_api_info(). |
menu_bean_get_initial_plugin_key | Get the initial plugin that builds the menutree |
menu_bean_get_settings | Get the settings plugins |
menu_bean_get_settings_class | Get the class name from the settings array |
menu_bean_load_setting_class | Get the setting class |
menu_bean_menu_bean_setting_info | Implements menu_bean_setting_info(). |
menu_bean_tree_add_active_path | Add the active trail indicators into the tree. |