function _path_breadcrumbs_ui_form_step_breadcrumbs_settings in Path Breadcrumbs 7.2
Same name and namespace in other branches
- 7.3 path_breadcrumbs_ui/path_breadcrumbs_ui.module \_path_breadcrumbs_ui_form_step_breadcrumbs_settings()
FOURTH STEP. Provide form for breadcrumb settings.
_state
Parameters
$form:
Return value
mixed
File
- path_breadcrumbs_ui/
path_breadcrumbs_ui.module, line 621 - Provide user interface for CRUD operations with path breadcrumbs.
Code
function _path_breadcrumbs_ui_form_step_breadcrumbs_settings(&$form, &$form_state) {
// Load breadcrumb from the cache.
$breadcrumb = path_breadcrumbs_object_cache_get($form_state['storage']['machine_name']);
if (empty($breadcrumb)) {
return;
}
$form['translatable'] = array(
'#type' => 'checkbox',
'#title' => t('Translatable'),
'#description' => t('Every breadcrumb will be available for translation.'),
'#default_value' => isset($breadcrumb->translatable) ? $breadcrumb->translatable : 0,
);
$form['home'] = array(
'#type' => 'checkbox',
'#title' => t('Prepend Home link to the breadcrumb'),
'#description' => t('First breadcrumb will be a link to the front page. This setting will override the default behavior.'),
'#default_value' => isset($breadcrumb->home) ? $breadcrumb->home : variable_get('path_breadcrumbs_home_link_enabled', 1),
);
$form['breadcrumbs_table'] = array(
'#tree' => TRUE,
);
// Initialize default amount of rows for titles and paths.
if (empty($form_state['storage']['rows_count'])) {
$form_state['storage']['rows_count'] = 1;
}
// If breadcrumb already has titles and paths we should build appropriate amount of rows.
if (isset($breadcrumb->titles) && isset($breadcrumb->paths)) {
$count = count($breadcrumb->titles);
if ($count > $form_state['storage']['rows_count']) {
$form_state['storage']['rows_count'] = $count;
}
}
for ($i = 0; $i < $form_state['storage']['rows_count']; $i++) {
// Unique hash required for updating form values in browser when deleting title-and-path row.
$unique_hash = md5(rand());
$form['breadcrumbs_table'][$unique_hash]['left_value'] = array(
'#type' => 'textfield',
'#default_value' => isset($breadcrumb->titles[$i]) ? $breadcrumb->titles[$i] : '',
);
$form['breadcrumbs_table'][$unique_hash]['right_value'] = array(
'#type' => 'textfield',
'#default_value' => isset($breadcrumb->paths[$i]) ? $breadcrumb->paths[$i] : '',
);
$form['breadcrumbs_table'][$unique_hash]['delete'] = array(
'#name' => 'delete_' . $unique_hash,
'#type' => 'submit',
'#value' => t('Delete'),
'#ajax' => array(
'callback' => '_path_breadcrumbs_ui_form_step_breadcrumbs_settings_ajax',
'wrapper' => 'path-breadcrumbs-ui-form-wrapper',
),
);
}
// Button allows add new empty title-and-path row.
$form['more'] = array(
'#type' => 'submit',
'#value' => t('Add more'),
'#ajax' => array(
'callback' => '_path_breadcrumbs_ui_form_step_breadcrumbs_settings_ajax',
'wrapper' => 'path-breadcrumbs-ui-form-wrapper',
),
);
$rows = array();
// Build module substitutions.
$rows[] = array(
check_plain('<front>'),
t('Used for the link path to provide link to the front page.'),
);
$rows[] = array(
check_plain('<none>'),
t('Used for the link path to bring a breadcrumb as plain text.'),
);
$rows[] = array(
'!page_title',
t('Current page title'),
);
// Build context substitutions.
if (!empty($breadcrumb->arguments)) {
// Include ctools library for contexts.
ctools_include('context');
foreach ($breadcrumb->arguments as $keyword => $arg) {
// Provide module placeholder for arguments.
$rows[] = array(
'!' . $keyword,
t('Unprocessed value of placeholder as it presented in the page url.'),
);
// Load argument plugin with its settings.
$argument = ctools_get_argument($arg['argument']);
if (isset($arg['settings'])) {
$argument += $arg['settings'];
$argument['id'] = 1;
}
// Provide tokens for selected contexts.
$context = ctools_context_get_context_from_argument($argument, $keyword, TRUE);
$converters = ctools_context_get_converters('%' . check_plain($keyword) . ':', $context);
foreach ($converters as $substitution => $title) {
$rows[] = array(
check_plain($substitution),
t($title),
);
}
}
}
$form['contexts'] = array(
'#type' => 'fieldset',
'#title' => t('Substitutions'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['contexts']['placeholders'] = array(
'#markup' => theme('table', array(
'header' => array(
t('Keyword'),
t('Value'),
),
'rows' => $rows,
)),
);
$form['#validate'][] = '_path_breadcrumbs_ui_form_step_breadcrumbs_settings_validate';
$form['#submit'][] = '_path_breadcrumbs_ui_form_step_breadcrumbs_settings_submit';
_path_breadcrumbs_ui_form_attach_buttons($form, array(
'prev',
'finish',
), 'path_breadcrumbs_ui_add_form');
if (isset($form_state['storage']['machine_name'])) {
_path_breadcrumbs_ui_form_apply_default_values($form, $form_state['storage']['machine_name']);
}
}