function path_breadcrumbs_ui_argument_context_form in Path Breadcrumbs 7.2
Same name and namespace in other branches
- 7.3 path_breadcrumbs_ui/path_breadcrumbs_ui.module \path_breadcrumbs_ui_argument_context_form()
Provide form that allows to match arguments with contexts.
_state
Parameters
$form:
Return value
array
2 string references to 'path_breadcrumbs_ui_argument_context_form'
- path_breadcrumbs_ui_change_arguments_page in path_breadcrumbs_ui/
path_breadcrumbs_ui.pages.inc - Page callback for settings form for arguments.
- path_breadcrumbs_ui_configure_arguments_page in path_breadcrumbs_ui/
path_breadcrumbs_ui.pages.inc - Page callback for arguments configuration in path.
File
- path_breadcrumbs_ui/
path_breadcrumbs_ui.module, line 925 - Provide user interface for CRUD operations with path breadcrumbs.
Code
function path_breadcrumbs_ui_argument_context_form($form, &$form_state) {
$form['#prefix'] = '<div id="path-breadcrumbs-ui-argument-context-form-wrapper">';
$form['#suffix'] = '</div>';
$form['#tree'] = TRUE;
// Load values from form storage.
$path_name = $form_state['storage']['path_name'];
$keyword = $form_state['storage']['keyword'];
// Load breadcrumb from cache.
$breadcrumb = path_breadcrumbs_object_cache_get($path_name);
if (!$breadcrumb) {
return array();
}
// Get current form step.
if (!isset($form_state['storage']['step'])) {
$form_state['storage']['step'] = 1;
}
// Include ctools library for contexts.
ctools_include('context');
switch ($form_state['storage']['step']) {
// Show form with selection radios.
case 1:
// Get ctools plugins for arguments.
$options = array();
$plugins = ctools_get_arguments();
foreach ($plugins as $id => $plugin) {
if (empty($plugin['no ui'])) {
$options[$id] = $plugin['title'];
}
}
asort($options);
$options = array(
'' => t('No context selected'),
) + $options;
$form['argument'] = array(
'#type' => 'radios',
'#options' => $options,
);
// Apply default value for argument.
if (isset($breadcrumb->arguments[$keyword]['argument'])) {
$form['argument']['#default_value'] = $breadcrumb->arguments[$keyword]['argument'];
}
// Attach buttons to form.
_path_breadcrumbs_ui_form_attach_buttons($form, array(
'next',
), 'path_breadcrumbs_ui_argument_context_form');
break;
case 2:
// Load argument's plugin.
$plugins = ctools_get_arguments();
$plugin = $plugins[$form_state['storage']['argument']];
$form['settings']['identifier'] = array(
'#title' => t('Context identifier'),
'#type' => 'textfield',
'#default_value' => $plugin['title'],
);
// Apply plugin's settings form to previously builded form.
if ($function = (string) ctools_plugin_get_function($plugin, 'settings form')) {
$settings_form = $settings_form_state = array();
$function($settings_form, $settings_form_state);
$form['settings'] += $settings_form['settings'];
}
// Apply argument's stored values as default form values.
if (!empty($breadcrumb->arguments[$keyword]['settings'])) {
foreach ($breadcrumb->arguments[$keyword]['settings'] as $name => $value) {
if (isset($form['settings'][$name])) {
$form['settings'][$name]['#default_value'] = $value;
}
}
}
// Attach buttons to the form.
_path_breadcrumbs_ui_form_attach_buttons($form, array(
'prev',
'finish',
), 'path_breadcrumbs_ui_argument_context_form');
break;
}
return $form;
}