function pathauto_entity_alias_form in Pathauto Entity 7
Uses for elements from the Path module
1 call to pathauto_entity_alias_form()
- pathauto_entity_form_alter in ./
pathauto_entity.module - Implements hook_form_alter().
File
- ./
pathauto_entity.module, line 420 - Implements custom entity type support for Pathauto module.
Code
function pathauto_entity_alias_form($form, $form_state, $form_id, $entity_type) {
// Set access to pathauto override
if (user_access('create url aliases') || user_access('administer url aliases')) {
// Add additional settings if they are not alread present
if (!isset($form['additional_settings'])) {
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
);
}
$path = array();
$default_uri = entity_uri($entity_type, $form_state[$entity_type]);
$entity_info = entity_get_info($entity_type);
if (!empty($form_state[$entity_type]->{$entity_info['entity keys']['id']})) {
$conditions = array(
'source' => $default_uri['path'],
);
$langcode = pathauto_entity_language($entity_type, $form_state[$entity_type]);
if ($langcode != LANGUAGE_NONE) {
$conditions['language'] = $langcode;
}
$path = path_load($conditions);
if ($path === FALSE) {
$path = array();
}
}
// Determine if another module already add $form['path']
$path += array(
'pid' => NULL,
'source' => isset($form_state[$entity_type]->{$entity_info['entity keys']['id']}) ? $default_uri['path'] : 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'],
);
pathauto_field_attach_form($entity_type, $form_state[$entity_type], $form, $form_state, isset($langcode) ? $langcode : LANGUAGE_NONE);
$form['#submit'][] = 'pathatuo_entity_alias_form_submit';
return $form;
}
}