' . t('About') . ''; $output .= '

' . 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 Pathauto. For more information, see the online documentation for the Path module.', [':path' => 'https://www.drupal.org/documentation/modules/path', ':pathauto' => 'https://www.drupal.org/project/pathauto']) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Creating aliases') . '
'; $output .= '
' . t('If you create or edit a taxonomy term you can add an alias (for example music/jazz) in the field "URL alias". When creating or editing content you can add an alias (for example about-us/team) under the section "URL path settings" in the field "URL alias". Aliases for any other path can be added through the page URL aliases. To add aliases a user needs the permission Create and edit URL aliases.', [':aliases' => \Drupal::url('path.admin_overview'), ':permissions' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-path'])]) . '
'; $output .= '
' . t('Managing aliases') . '
'; $output .= '
' . t('The Path module provides a way to search and view a list of all aliases that are in use on your website. Aliases can be added, edited and deleted through this list.', [':aliases' => \Drupal::url('path.admin_overview')]) . '
'; $output .= '
'; return $output; case 'path.admin_overview': return '

' . 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.") . '

'; case 'path.admin_add': return '

' . t('Enter the path you wish to create the alias for, followed by the name of the new alias.') . '

'; } } /** * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm. */ function path_form_node_form_alter(&$form, FormStateInterface $form_state) { $node = $form_state->getFormObject()->getEntity(); $form['path_settings'] = [ '#type' => 'details', '#title' => t('URL path settings'), '#open' => !empty($form['path']['widget'][0]['alias']['#value']), '#group' => 'advanced', '#access' => !empty($form['path']['#access']) && $node->hasField('path') && $node->get('path')->access('edit'), '#attributes' => [ 'class' => ['path-form'], ], '#attached' => [ 'library' => ['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'] = BaseFieldDefinition::create('path') ->setLabel(t('URL alias')) ->setTranslatable(TRUE) ->setDisplayOptions('form', [ 'type' => 'path', 'weight' => 30, ]) ->setDisplayConfigurable('form', TRUE) ->setComputed(TRUE); return $fields; } }