Implements hook_form_BASE_FORM_ID_alter() for node_form().
function path_form_node_form_alter(&$form, $form_state) {
$node = $form_state['controller']
->getEntity($form_state);
$path = array();
if (!empty($node->nid)) {
$conditions = array(
'source' => 'node/' . $node->nid,
);
if ($node->langcode != LANGUAGE_NOT_SPECIFIED) {
$conditions['langcode'] = $node->langcode;
}
$path = drupal_container()
->get('path.crud')
->load($conditions);
if ($path === FALSE) {
$path = array();
}
}
$path += array(
'pid' => NULL,
'source' => isset($node->nid) ? 'node/' . $node->nid : NULL,
'alias' => '',
'langcode' => isset($node->langcode) ? $node->langcode : LANGUAGE_NOT_SPECIFIED,
);
$form['path'] = array(
'#type' => 'details',
'#title' => t('URL path settings'),
'#collapsible' => TRUE,
'#collapsed' => empty($path['alias']),
'#group' => 'additional_settings',
'#attributes' => array(
'class' => array(
'path-form',
),
),
'#attached' => array(
'library' => array(
array(
'path',
'drupal.path',
),
),
),
'#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('The alternative URL for this content. Use a relative path without a trailing slash. For example, enter "about" for the about page.'),
);
$form['path']['pid'] = array(
'#type' => 'value',
'#value' => $path['pid'],
);
$form['path']['source'] = array(
'#type' => 'value',
'#value' => $path['source'],
);
$form['path']['langcode'] = array(
'#type' => 'value',
'#value' => $path['langcode'],
);
}