function path_form_node_form_alter
Implements hook_form_BASE_FORM_ID_alter() for node_form().
See also
File
-
modules/
path/ path.module, line 98
Code
function path_form_node_form_alter(&$form, $form_state) {
$path = array();
if (!empty($form['#node']->nid)) {
$conditions = array(
'source' => 'node/' . $form['#node']->nid,
);
$langcode = entity_language('node', $form['#node']);
if ($langcode != LANGUAGE_NONE) {
$conditions['language'] = $langcode;
}
$path = path_load($conditions);
if ($path === FALSE) {
$path = array();
}
}
$path += array(
'pid' => NULL,
'source' => isset($form['#node']->nid) ? 'node/' . $form['#node']->nid : NULL,
'alias' => '',
'language' => isset($langcode) ? $langcode : LANGUAGE_NONE,
);
$form['path'] = array(
'#type' => 'fieldset',
'#title' => t('URL path settings'),
'#collapsible' => TRUE,
'#collapsed' => empty($path['alias']),
'#group' => 'additional_settings',
'#attributes' => array(
'class' => array(
'path-form',
),
),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'path') . '/path.js',
),
),
'#access' => user_access('create url aliases') || user_access('administer url aliases'),
'#weight' => 30,
'#tree' => TRUE,
'#element_validate' => array(
'path_form_element_validate',
),
);
$form['path']['alias'] = array(
'#type' => 'textfield',
'#title' => t('URL alias'),
'#default_value' => $path['alias'],
'#maxlength' => 255,
'#description' => t('Optionally specify an alternative URL by which this content can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'),
);
$form['path']['pid'] = array(
'#type' => 'value',
'#value' => $path['pid'],
);
$form['path']['source'] = array(
'#type' => 'value',
'#value' => $path['source'],
);
$form['path']['language'] = array(
'#type' => 'value',
'#value' => $path['language'],
);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.