1 path.admin.inc | path_patterns_form($form, $form_state) |
Form builder; Configure the URL alias patterns.
See also
Related topics
File
- core/
modules/ path/ path.admin.inc, line 349 - Admin page callbacks for the Path module.
Code
function path_patterns_form($form, $form_state) {
$config = config('path.settings');
$form['help'] = array(
'#type' => 'help',
'#markup' => t('URL patterns automatically alias new content based on wildcards called <em>tokens</em>. For example the URL <code>node/10</code> might be automatically aliased to <code>blog/my-first-post</code> using the pattern <code>blog/[node:title]</code>.'),
);
$all_path_info = path_get_info();
foreach ($all_path_info as $path_type => $path_info) {
$pattern_description = $path_info['pattern description'];
$group_header = t('!label URL alias patterns', array('!label' => $path_info['label']));
$token_types = array();
if (isset($path_info['entity type'])) {
$entity_type = entity_get_info($path_info['entity type']);
if (isset($entity_type['token type'])) {
$token_types[] = $entity_type['token type'];
}
}
$form[$path_type] = array(
'#type' => 'fieldset',
'#title' => $group_header,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// Prompt for the default URL alias pattern for this path type.
$variable = $path_type . '_pattern';
$form[$path_type][$variable] = array(
'#type' => 'textfield',
'#title' => $pattern_description,
'#default_value' => $config->get($variable),
'#size' => 65,
'#maxlength' => 1280,
'#element_validate' => array('token_element_validate'),
'#after_build' => array('token_element_validate'),
'#token_types' => $token_types,
'#min_tokens' => 1,
'#parents' => array($variable),
);
// Set up specialized patterns for this path type (e.g. node types).
if (isset($path_info['pattern items'])) {
foreach ($path_info['pattern items'] as $item_name => $item_label) {
$variable = $path_type . '_' . $item_name . '_pattern';
$form[$path_type][$variable] = array(
'#type' => 'textfield',
'#title' => $item_label,
'#default_value' => $config->get($variable),
'#size' => 65,
'#maxlength' => 1280,
'#element_validate' => array('token_element_validate'),
'#after_build' => array('token_element_validate'),
'#token_types' => $token_types,
'#min_tokens' => 1,
'#parents' => array($variable),
);
}
}
// Display the user documentation of placeholders supported by this path
// type as a description on the last pattern.
$variables = array(
'token_types' => $token_types,
'text' => t('Browse available tokens for @type.', array('@type' => $path_info['label'])),
);
$form[$path_type]['#description'] = '<p>' . t('Each of the fields below support tokens.') . ' ' . theme('token_tree_link', $variables) . '</p>';
}
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}