')),
);
$form['help2']['tokens'] = array('#value' => theme('custom_breadcrumbs_help_identifiers'), );
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
if (isset($bid)) {
$form['buttons']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array('custom_breadcrumbs_form_delete'),
);
}
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#submit' => array('custom_breadcrumbs_form_cancel'),
);
return $form;
}
/**
* Form builder; Configure basic and advanced custom breadcrumbs settings for this site.
*
* @ingroup forms
* @see system_settings_form()
*/
function custom_breadcrumbs_admin_settings() {
$form = array();
drupal_set_title(t('Custom Breadcrumbs Configuration'));
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Basic settings'),
'#collapsible' => TRUE,
);
$form['settings']['custom_breadcrumb_home'] = array(
'#type' => 'textfield',
'#title' => t('Home breadcrumb text'),
'#default_value' => variable_get('custom_breadcrumb_home', t('Home')),
'#description' => t('This text will be displayed as the first item of the breadcrumb trail. Typically Home or your site name. Leave blank to have no home breadcrumb. You can also specify a title attribute (tooltip text) to add to the link. Just separate the crumb text and the title attribute text with a pipe (|) symbol (i.e. Home crumb text|attribute title text).'),
);
$form['settings']['custom_breadcrumbs_menu_structure'] = array(
'#type' => 'fieldset',
'#title' => t('Menu structure'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['settings']['custom_breadcrumbs_menu_structure']['custom_breadcrumbs_set_menu_breadcrumb'] = array(
'#type' => 'checkbox',
'#title' => t('Use the menu structure to set the breadcrumb trail'),
'#default_value' => variable_get('custom_breadcrumbs_set_menu_breadcrumb', FALSE),
'#description' => t("If enabled, the default breadcrumb trail will be patterned after the page's placement in the menu structure. Select the menus that this option will apply to below. Note that this default can be superceded by other custom breadcrumbs."),
'#weight' => -30,
);
$menu_options = array();
foreach (menu_get_names() as $name) {
$menu_options[$name] = $name;
}
$form['settings']['custom_breadcrumbs_menu_structure']['custom_breadcrumbs_menu_list'] = array(
'#type' => 'select',
'#title' => t('Menu name'),
'#options' => $menu_options,
'#default_value' => variable_get('custom_breadcrumbs_menu_list', FALSE),
'#description' => t("Pages within selected menus will have a default breadcrumb patterned after the menu structure."),
'#multiple' => TRUE,
'#weight' => -20,
);
$form['adv_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
);
$form['adv_settings']['custom_breadcrumbs_set_global_home_breadcrumb'] = array(
'#type' => 'checkbox',
'#title' => t('Set the home breadcrumb text on all pages'),
'#default_value' => variable_get('custom_breadcrumbs_set_global_home_breadcrumb', FALSE),
'#description' => t("If enabled, the home breadcrumb text will be used on all pages, not just those with defined custom breadcrumbs. If you don't want a home breadcrumb to be displayed, just enable this option and make sure that the home breadcrumb text above is empty."),
'#weight' => -40,
);
$form['adv_settings']['custom_breadcrumbs_use_php_in_titles'] = array(
'#type' => 'checkbox',
'#title' => t('Allow the use of PHP to set titles and paths'),
'#default_value' => variable_get('custom_breadcrumbs_use_php_in_titles', FALSE),
'#description' => t("If enabled, small PHP code snippets (less than 250 characters) can be used in the titles and paths section of the create breadcrumb forms. Each should return an array with text strings for each part of the crumb. Alternatively, a PHP code snippet placed in the titles box can return an associative array with elements 'titles' and 'paths', each an array of text strings. If this is done, the paths text field will be ignored."),
'#weight' => -35,
);
$form['adv_settings']['custom_breadcrumbs_force_active_trail'] = array(
'#type' => 'checkbox',
'#title' => t('Force the active trail'),
'#description' => t('This options sets the active trail to match the custom breadcrumb trail and overrides the normal theme_links() implementation to add the active-trail class to links. This is experimental and may not work as expected. If this is of interest to you, please test and report back to the custom breadcrumbs issue queue.'),
'#default_value' => variable_get('custom_breadcrumbs_force_active_trail', FALSE),
'#weight' => -10,
);
$form['adv_settings']['custom_breadcrumbs_excluded'] = array(
'#type' => 'fieldset',
'#title' => t('Excluded paths'),
'#description' => t("If enabled, the custom breadcrumbs module will not modify breadcrumbs set on the paths defined below."),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['adv_settings']['custom_breadcrumbs_excluded']['custom_breadcrumbs_use_exclude_list'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude custom breadcrumbs from some pages'),
'#default_value' => variable_get('custom_breadcrumbs_use_exclude_list', FALSE),
);
$default_exclude_paths = array();
if (module_exists('admin_menu')) {
$default_exclude_paths[] = 'admin/user/user';
$default_exclude_paths[] = 'user';
}
$default = implode(',', $default_exclude_paths);
$form['adv_settings']['custom_breadcrumbs_excluded']['custom_breadcrumbs_exclude_list'] = array(
'#type' => 'textfield',
'#title' => t('Do not set custom breadcrumbs on the following paths'),
'#default_value' => variable_get('custom_breadcrumbs_exclude_list', $default),
'#description' => t("A comma delimited set of paths to exclude from custom breadcrumbs. The '*' character can be used as a wildcard."),
);
$form['adv_settings']['custom_breadcrumbs_identifiers'] = array(
'#type' => 'fieldset',
'#title' => t('HTML element identifiers'),
'#description' => t("Enabling one or more of these options will provide html identifiers (class or id) for theming custom breadcrumbs links. Style rules can then be defined in the styles.css file located in the site's theme directory."),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['adv_settings']['custom_breadcrumbs_identifiers']['cb_identifier_options'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
);
$form['adv_settings']['custom_breadcrumbs_identifiers']['cb_identifier_options']['custom_breadcrumbs_home_id'] = array(
'#type' => 'checkbox',
'#title' => t("Add a custom-breadcrumbs-home ID attribute to the home breadcrumb item."),
'#default_value' => variable_get('custom_breadcrumbs_home_id', FALSE),
);
$form['adv_settings']['custom_breadcrumbs_identifiers']['cb_identifier_options']['custom_breadcrumbs_parts_class'] = array(
'#type' => 'checkbox',
'#title' => t("Add a numbered class attribute for each breadcrumb item."),
'#description' => t("If enabled, a custom-breadcrumbs-item-N class attribute will be assigned for each item, where N designates the item number, starting with the first item after the home breadcrumb."),
'#default_value' => variable_get('custom_breadcrumbs_parts_class', FALSE),
);
$form['adv_settings']['custom_breadcrumbs_identifiers']['cb_identifier_options']['custom_breadcrumbs_even_odd_class'] = array(
'#type' => 'checkbox',
'#title' => t("Add even and odd classes to breadcrumb items."),
'#default_value' => variable_get('custom_breadcrumbs_even_odd_class', FALSE),
);
$form['adv_settings']['custom_breadcrumbs_identifiers']['cb_identifier_options']['custom_breadcrumbs_type_class'] = array(
'#type' => 'checkbox',
'#title' => t("Store an identifier for breadcrumb theming."),
'#description' => t("If enabled, the breadcrumb class 'custom-breadcrumbs-type' (where type is the breadcrumb type) can be retrieved and used in the breadcrumb theme override. The function custom_breadcrumbs_unique_breadcrumb_id() will return a string containing the class name."),
'#default_value' => variable_get('custom_breadcrumbs_type_class', FALSE),
);
$form['adv_settings']['custom_breadcrumbs_identifiers']['cb_identifier_options']['custom_breadcrumbs_append_bid_class'] = array(
'#type' => 'checkbox',
'#title' => t("Append a unique breadcrumb id number to the custom-breadcrumbs-type identifier."),
'#description' => t("If this option and 'Store an identifier for breadcrumb theming' are both enabled, the identifer will be custom-breadcrumbs-type-id, where id is the unique breadcrumb id number."),
'#default_value' => variable_get('custom_breadcrumbs_append_bid_class', FALSE),
);
$form['adv_settings']['module_weights'] = array(
'#type' => 'fieldset',
'#title' => t('Module weights'),
'#description' => t('If enabled, the relative module weights can be adjusted in the table below. Modules with lighter weights will provide custom breadcrumbs that can be modified, or overriden, by heavier modules.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['adv_settings']['module_weights']['custom_breadcrumbs_adjust_module_weights'] = array(
'#type' => 'checkbox',
'#title' => t('Adjust module weights'),
'#default_value' => FALSE,
);
$form['adv_settings']['module_weights']['table'] = custom_breadcrumbs_module_weight();
if (!empty($form['adv_settings']['module_weights']['table'])) {
$form['adv_settings']['module_weights']['table']['#theme'] = 'custom_breadcrumbs_module_weight';
}
else {
unset($form['adv_settings']['module_weights']);
}
$form['#submit'][] = 'custom_breadcrumbs_admin_settings_submit';
return system_settings_form($form);
}
/**
* Form submission handler for custom_breadcrumbs_admin_settings().
*
* @see custom_breadcrumbs_admin_settings()
*/
function custom_breadcrumbs_admin_settings_submit($form, &$form_state) {
if (!empty($form['adv_settings']['module_weights']['table']) && $form_state['values']['custom_breadcrumbs_adjust_module_weights']) {
// Set the initial weight of the lightest module to zero.
$current_mod_weight = 0;
$table = array('module name' => array(), 'table weight' => array(), 'module weight' => array());
// Prepare module table that can be sorted by table weight.
foreach ($form_state['values']['table'] as $module_id => $value) {
if (is_numeric($module_id)) {
$module = $form['adv_settings']['module_weights']['table'][$module_id]['#module'];
$table['table weight'][$module] = $form_state['values']['table'][$module_id]['weight'];
$table['module weight'][$module] = $form['adv_settings']['module_weights']['table'][$module_id]['#weight'];
}
}
// Sort module list by table weight.
array_multisort($table['table weight'], $table['module weight']);
foreach ($table['module weight'] as $module => $orig_weight) {
// Find the module's minimum weight determined by dependence on other modules.
$func = $module .'_minimum_module_weight';
$min = function_exists($func) ? $func() : 0;
$weight = max($min, $current_mod_weight);
// Update module weight in the system table if it has changed.
if ($orig_weight != $weight) {
db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, $module);
variable_set('menu_rebuild_needed', TRUE);
}
$current_mod_weight = $weight + 1;
}
}
// Rebuild the theme registry if custom_breadcrumbs_force_active_trail has changed.
if ($form_state['values']['custom_breadcrumbs_force_active_trail'] != $form['adv_settings']['custom_breadcrumbs_force_active_trail']['#default_value']) {
drupal_rebuild_theme_registry();
drupal_set_message(t('The theme registry has been rebuilt'));
}
}
/**
* Lists and manages custom breadcrumb module weights.
*
* @see theme_custom_breadcrumbs_module_weight()
* @see custom_breadcrumbs_admin_settings_submit()
*/
function custom_breadcrumbs_module_weight() {
// Get a list of all custom_breadcrumbs submodules and their module weights.
$modules = module_implements('cb_breadcrumb_info');
$form = array('#tree' => TRUE);
$module_id = 0;
$weights = _custom_breadcrumbs_get_module_weight($modules);
foreach ($weights as $module => $weight) {
$info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
$form[$module_id]['#weight'] = $weight;
$form[$module_id]['#module'] = $module;
$form[$module_id]['name'] = array('#value' => check_plain($info['name']));
$form[$module_id]['weight'] = array('#type' => 'weight', '#delta' => 200, '#default_value' => $weight);
++$module_id;
}
// Only add this form if there is more than one module.
return ($module_id > 1) ? $form : array();
}
/**
* Returns HTML for the module weights as a sortable list.
*
* @ingroup themeable
* @see custom_breadcrumbs_module_weight()
*/
function theme_custom_breadcrumbs_module_weight($form) {
$rows = array();
foreach (element_children($form) as $key) {
if (isset($form[$key]['name'])) {
$module = &$form[$key];
$row = array();
$row[] = drupal_render($module['name']);
if (isset($module['weight'])) {
$module['weight']['#attributes']['class'] = 'module-weight';
$row[] = drupal_render($module['weight']);
}
$rows[] = array('data' => $row, 'class' => 'draggable');
}
}
$header = array(t('Module Name'));
$header[] = t('Weight');
drupal_add_tabledrag('custom_breadcrumbs', 'order', 'self', 'module-weight');
return theme('table', $header, $rows, array('id' => 'custom_breadcrumbs')) . drupal_render($form);
}
/**
* Checks whether the administration interface should show multilingual features.
*/
function _custom_breadcrumbs_multilingual() {
return module_exists('locale');
}
/**
* Lists custom_breadcrumbs administration filters that can be applied.
*/
function custom_breadcrumbs_filters() {
$filters = array();
$options = array();
foreach (module_implements('cb_breadcrumb_info') as $module) {
$bc_info = module_invoke($module, 'cb_breadcrumb_info');
foreach ($bc_info as $info) {
$options[$module .'-'. $info['table']] = $info['type'];
}
}
$filters['type'] = array(
'title' => t('Type'),
'options' => $options,
);
if (_custom_breadcrumbs_multilingual()) {
$filters['language'] = array(
'title' => t('Language'),
'options' => array('' => t('All languages')) + locale_language_list('name'),
);
}
return $filters;
}
/**
* Form builder; Return form for custom_breadcrumbs administration filters.
*
* @ingroup forms
* @see custom_breadcrumbs_filter_form_submit()
*/
function custom_breadcrumbs_filter_form() {
$session = &$_SESSION['custom_breadcrumbs_overview_filter'];
$session = is_array($session) ? $session : array();
$filters = custom_breadcrumbs_filters();
$i = 0;
$form['filters'] = array(
'#type' => 'fieldset',
'#title' => t('Show only custom_breadcrumbs where'),
'#theme' => 'custom_breadcrumbs_filters',
);
foreach ($session as $filter) {
list($type, $value) = $filter;
// Merge an array of arrays into one if necessary.
$options = $filters[$type]['options'];
$params = array('%property' => $filters[$type]['title'] , '%value' => $options[$value]);
if ($i++ > 0) {
$form['filters']['current'][] = array('#value' => t('and where %property is %value', $params));
}
else {
$form['filters']['current'][] = array('#value' => t('%property is %value', $params));
}
unset($filters[$type]);
}
foreach ($filters as $key => $filter) {
$names[$key] = $filter['title'];
$form['filters']['status'][$key] = array(
'#type' => 'select',
'#options' => $filter['options'],
);
}
$form['filters']['filter'] = array(
'#type' => 'radios',
'#options' => $names,
);
if (count($filters)) {
$form['filters']['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => (count($session) ? t('Refine') : t('Filter')),
);
}
if (count($session)) {
$form['filters']['buttons']['undo'] = array(
'#type' => 'submit',
'#value' => t('Undo'),
);
$form['filters']['buttons']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
);
}
drupal_add_js('misc/form.js', 'core');
return $form;
}
/**
* Form submission handler for custom_breadcrumbs_filter_form().
*
* @see custom_breadcrumbs_filter_form()
*/
function custom_breadcrumbs_filter_form_submit($form, &$form_state) {
$op = $form_state['values']['op'];
$filters = custom_breadcrumbs_filters();
switch ($op) {
case t('Filter'): case t('Refine'):
if (isset($form_state['values']['filter'])) {
$filter = $form_state['values']['filter'];
// Merge an array of arrays into one if necessary.
$options = $filters[$filter]['options'];
if (isset($options[$form_state['values'][$filter]])) {
$_SESSION['custom_breadcrumbs_overview_filter'][] = array($filter, $form_state['values'][$filter]);
}
}
break;
case t('Undo'):
array_pop($_SESSION['custom_breadcrumbs_overview_filter']);
break;
case t('Reset'):
$_SESSION['custom_breadcrumbs_overview_filter'] = array();
break;
case t('Update'):
return;
}
$form_state['redirect'] = 'admin/build/custom_breadcrumbs';
return;
}
/**
* Returns HTML for the custom_breadcrumbs filter form.
*
* @ingroup themeable
*/
function theme_custom_breadcrumbs_filter_form($form) {
$output = '';
$output .= drupal_render($form['filters']);
$output .= '
';
$output .= drupal_render($form);
return $output;
}
/**
* Returns HTML for the custom_breadcrumbs filter selector.
*
* @ingroup themeable
*/
function theme_custom_breadcrumbs_filters($form) {
$output = '';
return $output;
}
/**
* Provides a simple breadcrumb table for the node edit form.
*
* @param $breadcrumbs
* An array of breadcrumbs that apply to the node.
*
* @return
* A themed table of custom breadcrumbs.
*/
function custom_breadcrumbs_simple_breadcrumb_table($breadcrumbs) {
$header = array(t('Name'), t('Type'), t('Titles'), t('Paths'));
$multilingual = _custom_breadcrumbs_multilingual();
if ($multilingual) {
$header[] = t('Language');
}
$header[] = t('Operations');
$rows = array();
foreach ($breadcrumbs as $breadcrumb) {
$row = array();
$row[] = array('data' => $breadcrumb->name . (!empty($breadcrumb->visibility_php) ? ' '. t('with PHP snippet') : ''));
$row[] = array('data' => $breadcrumb->breadcrumb_type);
$row[] = array('data' => check_plain($breadcrumb->titles));
$row[] = array('data' => check_plain($breadcrumb->paths));
if ($multilingual) {
$row[] = array('data' => module_invoke('locale', 'language_name', $breadcrumb->language));
}
$row[] = l(t('edit'), 'admin/build/custom_breadcrumbs/'. $breadcrumb->breadcrumb_type .'/edit/'. $breadcrumb->bid);
$rows[] = $row;
}
if (count($rows) == 0) {
$rows[] = array(array('data' => t('You can define custom breadcrumbs at Custom Breadcrumbs Administration Page.', array('@link' => url('admin/build/custom_breadcrumbs'))), 'colspan' => 5 + (int)$multilingual));
}
return theme('table', $header, $rows);
}