function _nodesymlinks_form_alter in NodeSymlinks 6
Implementation of hook_form_alter().
Adds nodesymlinks item fields to the node form.
1 call to _nodesymlinks_form_alter()
- nodesymlinks_form_alter in ./
nodesymlinks.module - Implementation of hook_form_alter(). Adds nodesymlinks item fields to the node form.
File
- ./
nodesymlinks.inc, line 323
Code
function _nodesymlinks_form_alter(&$form, $form_state, $form_id) {
// Note - doing this to make sure the delete checkbox stays in the form.
$form['#cache'] = TRUE;
$node = $form['#node'];
if (isset($form_state['values'])) {
$nodesymlinks = !empty($form_state['values']['menu']['nodesymlinks']['items']) ? (array) $form_state['values']['menu']['nodesymlinks']['items'] : array();
}
else {
$nodesymlinks = (array) $node->nodesymlinks['items'];
}
$collapsed = count($nodesymlinks) ? FALSE : TRUE;
$form['menu']['nodesymlinks'] = array(
'#type' => 'fieldset',
'#title' => t('Show in More Locations'),
// TODO: check in hook_requirements that user roles with 'administer nodesymlinks' has also 'administer menu' permission
'#access' => user_access('administer menu') && user_access('administer nodesymlinks'),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#tree' => TRUE,
'#weight' => 1,
'#attributes' => array(
'class' => 'nodesymlinks-items-form',
),
);
// Submenu Tree Settings & Siblingmenu Tree Settings.
// We want to display Symlinks after Menu Links and before SubmenuTree Settings
if (isset($form['menu']['submenutree'])) {
$form['menu']['submenutree']['#weight'] = 2;
$form['menu']['siblingmenutree']['#weight'] = 2;
}
$form['menu']['nodesymlinks']['items'] = array(
'#tree' => TRUE,
'#theme' => 'nodesymlinks_form_items',
);
// Add JavaScript that will disable the path textfield when the automatic
// alias checkbox is checked.
drupal_add_js(drupal_get_path('module', 'nodesymlinks') . '/nodesymlinks.js');
$delta = 0;
foreach ($nodesymlinks as $item) {
$form['menu']['nodesymlinks']['items'][$delta++] = _nodesymlinks_form_field($item, $node);
}
if (isset($form_state['item_count']['nodesymlinks'])) {
$new_max_delta = $form_state['item_count']['nodesymlinks'] - 1;
for ($delta; $delta <= $new_max_delta; ++$delta) {
$new_item = array(
'new_item' => TRUE,
'link_title' => $node->title,
);
$form['menu']['nodesymlinks']['items'][$delta] = _nodesymlinks_form_field($new_item, $node);
}
}
$description = t('This module allows you to show this node\'s content within multiple places in your site.<br />');
$description .= '<b>' . t('Parent item') . ':</b> ' . t('The place where this page\'s content will appear. It will use the selected parent\'s breadcrumbs and sidebar. Items in the hierarchy deeper than ' . (MENU_MAX_DEPTH - 1) . ' levels may not appear.', array(
'!maxdepth' => MENU_MAX_DEPTH,
));
$description .= ' <br /><b>' . t('Link title') . ':</b> ' . t('The link text corresponding to this item that should appear in the menu.');
if (user_access('create url aliases')) {
if (module_exists('pathauto')) {
$description .= ' <br /><b>' . t('Pathauto') . ':</b> ' . t('Optional. When checked, path alias will be generated using Pathauto.');
$description .= ' <br /><b>' . t('Path') . ':</b> ' . t('Optional. When Pathauto checkbox is unchecked you can write custom unique path alias here.');
}
elseif (module_exists('path')) {
$description .= ' <br /><b>' . t('Path') . ':</b> ' . t('Optional. You can write custom unique path alias here. If you leave this field empty and node path alias is filled in (URL path settings), default alias will be generated using following pattern: <em><node-path-alias>_<menu-link-id></em>');
}
}
$description .= ' <br /><b>' . t('Weight') . ':</b> ' . t('Optional. In the menu, a higher weight number will sink down and a lower weight will be positioned closer to the top.');
$description .= ' <br /><b>' . t('Delete') . ':</b> ' . t('To delete nodesymlinks, first check the "Delete" checkbox in the desired rows, then click "Delete Location(s)".');
$description .= ' <br /><b>' . t('Saving') . ': ' . t('When you are done editing, you must click "Save" at the very bottom of the page to save your changes.') . '</b>';
$form['menu']['nodesymlinks']['#description'] = $description;
$form['menu']['nodesymlinks']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete Location(s)'),
'#submit' => array(
'nodesymlinks_node_form_submit_delete',
),
'#ahah' => array(
'path' => 'nodesymlinks/ahah',
'wrapper' => 'nodesymlinks-items-ahah',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['menu']['nodesymlinks']['add'] = array(
'#type' => 'submit',
'#value' => t('Add Location'),
'#submit' => array(
'nodesymlinks_node_form_submit_add',
),
'#ahah' => array(
'path' => 'nodesymlinks/ahah',
'wrapper' => 'nodesymlinks-items-ahah',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['#validate'][] = 'nodesymlinks_node_form_validate';
if (isset($form_state['clicked_button'])) {
$clicked_val = $form_state['clicked_button']['#value'];
if ($clicked_val == t('Add Location') || $clicked_val == t('Delete Location(s)')) {
$form['menu']['#collapsed'] = FALSE;
$form['menu']['nodesymlinks']['#collapsed'] = FALSE;
}
}
}