98 lines
4.1 KiB
Plaintext
98 lines
4.1 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Enables users to rename URLs.
|
|
*/
|
|
|
|
use Drupal\Core\Entity\EntityTypeInterface;
|
|
use Drupal\Core\Language\Language;
|
|
use Drupal\Core\Entity\EntityInterface;
|
|
use Drupal\Core\Entity\ContentEntityInterface;
|
|
use Drupal\Core\Field\FieldDefinition;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function path_help($route_name, Request $request) {
|
|
switch ($route_name) {
|
|
case 'help.page.path':
|
|
$output = '';
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
$output .= '<p>' . t('The Path module allows you to specify an alias, or custom URL, for any existing internal system path. Aliases should not be confused with URL redirects, which allow you to forward a changed or inactive URL to a new URL. In addition to making URLs more readable, aliases also help search engines index content more effectively. Multiple aliases may be used for a single internal system path. To automate the aliasing of paths, you can install the contributed module <a href="@pathauto">Pathauto</a>. For more information, see the online handbook entry for the <a href="@path">Path module</a>.', array('@path' => 'http://drupal.org/documentation/modules/path', '@pathauto' => 'http://drupal.org/project/pathauto')) . '</p>';
|
|
$output .= '<h3>' . t('Uses') . '</h3>';
|
|
$output .= '<dl>';
|
|
$output .= '<dt>' . t('Creating aliases') . '</dt>';
|
|
$output .= '<dd>' . t('Users with sufficient <a href="@permissions">permissions</a> can create aliases under the <em>URL path settings</em> section when they create or edit content. Some examples of aliases are: ', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-path'))));
|
|
$output .= '<ul><li>' . t('<em>member/jane-smith</em> aliased to internal path <em>user/123</em>') . '</li>';
|
|
$output .= '<li>' . t('<em>about-us/team</em> aliased to internal path <em>node/456</em>') . '</li>';
|
|
$output .= '</ul></dd>';
|
|
$output .= '<dt>' . t('Managing aliases') . '</dt>';
|
|
$output .= '<dd>' . t('The Path module provides a way to search and view a <a href="@aliases">list of all aliases</a> that are in use on your website. Aliases can be added, edited and deleted through this list.', array('@aliases' => url('admin/config/search/path'))) . '</dd>';
|
|
$output .= '</dl>';
|
|
return $output;
|
|
|
|
case 'path.admin_overview':
|
|
return '<p>' . t("An alias defines a different name for an existing URL path - for example, the alias 'about' for the URL path 'node/1'. A URL path can have multiple aliases.") . '</p>';
|
|
|
|
case 'path.admin_add':
|
|
return '<p>' . t('Enter the path you wish to create the alias for, followed by the name of the new alias.') . '</p>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_permission().
|
|
*/
|
|
function path_permission() {
|
|
return array(
|
|
'administer url aliases' => array(
|
|
'title' => t('Administer URL aliases'),
|
|
),
|
|
'create url aliases' => array(
|
|
'title' => t('Create and edit URL aliases'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_form_BASE_FORM_ID_alter() for node_form().
|
|
*/
|
|
function path_form_node_form_alter(&$form, $form_state) {
|
|
$node = $form_state['controller']->getEntity();
|
|
if ($node->hasField('path') && $node->get('path')->access('edit')) {
|
|
$form['path_settings'] = array(
|
|
'#type' => 'details',
|
|
'#title' => t('URL path settings'),
|
|
'#open' => !empty($form['path']['widget'][0]['alias']['#value']),
|
|
'#group' => 'advanced',
|
|
'#attributes' => array(
|
|
'class' => array('path-form'),
|
|
),
|
|
'#attached' => array(
|
|
'library' => array('path/drupal.path'),
|
|
),
|
|
'#weight' => 30,
|
|
);
|
|
$form['path']['#group'] = 'path_settings';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_entity_base_field_info().
|
|
*/
|
|
function path_entity_base_field_info(EntityTypeInterface $entity_type) {
|
|
if ($entity_type->id() === 'taxonomy_term' || $entity_type->id() === 'node') {
|
|
$fields['path'] = FieldDefinition::create('path')
|
|
->setLabel(t('URL alias'))
|
|
->setTranslatable(TRUE)
|
|
->setDisplayOptions('form', array(
|
|
'type' => 'path',
|
|
'weight' => 30,
|
|
))
|
|
->setDisplayConfigurable('form', TRUE);
|
|
|
|
return $fields;
|
|
}
|
|
}
|