'pathauto')); } /** * Implements hook_help(). */ function pathauto_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.pathauto': $output = '
' . t('The Pathauto module provides a mechanism to automate the creation of path aliases. This makes URLs more readable and helps search engines index content more effectively. For more information, see the online documentation for Pathauto.', [':online' => 'https://www.drupal.org/documentation/modules/pathauto']) . '
'; $output .= '' . t('This page provides a list of all patterns on the site and allows you to edit and reorder them.') . '
'; return $output; case 'entity.pathauto_pattern.add_form': $output = '' . t('You need to select a pattern type, then a pattern and filter, and a label. Additional types can be enabled on the Settings page.', [':settings' => Url::fromRoute('pathauto.settings.form')->toString()]) . '
'; return $output; case 'pathauto.bulk.update.form': $output = '' . t('Bulk generation can be used to generate URL aliases for items that currently have no aliases. This is typically used when installing Pathauto on a site that has existing un-aliased content that needs to be aliased in bulk.') . '
';
$output .= t('It can also be used to regenerate URL aliases for items that have an old alias and for which the Pathauto pattern has been changed.') . '
' . t('Note that this will only affect items which are configured to have their URL alias automatically set. Items whose URL alias is manually set are not affected.') . '
'; return $output; } } /** * Implements hook_field_info_alter(). */ function pathauto_field_info_alter(&$info) { $info['path']['class'] = PathautoItem::class; $info['path']['list_class'] = PathautoFieldItemList::class; } /** * Implements hook_field_widget_info_alter(). */ function pathauto_field_widget_info_alter(&$widgets) { $widgets['path']['class'] = 'Drupal\pathauto\PathautoWidget'; } /** * Implements hook_entity_base_field_info(). */ function pathauto_entity_base_field_info(EntityTypeInterface $entity_type) { $config = \Drupal::config('pathauto.settings'); // Verify that the configuration data isn't null (as is the case before the // module's initialization, in tests), so that in_array() won't fail. if ($enabled_entity_types = $config->get('enabled_entity_types')) { if (in_array($entity_type->id(), $enabled_entity_types)) { $fields['path'] = BaseFieldDefinition::create('path') ->setCustomStorage(TRUE) ->setLabel(t('URL alias')) ->setTranslatable(TRUE) ->setComputed(TRUE) ->setDisplayOptions('form', array( 'type' => 'path', 'weight' => 30, )) ->setDisplayConfigurable('form', TRUE); return $fields; } } } /** * Validate the pattern field, to ensure it doesn't contain any characters that * are invalid in URLs. */ function pathauto_pattern_validate($element, FormStateInterface $form_state) { if (isset($element['#value'])) { $title = empty($element['#title']) ? $element['#parents'][0] : $element['#title']; $invalid_characters = ['#', '?', '&']; $invalid_characters_used = []; foreach ($invalid_characters as $invalid_character) { if (strpos($element['#value'], $invalid_character) !== FALSE) { $invalid_characters_used[] = $invalid_character; } } if (!empty($invalid_characters_used)) { $form_state->setError($element, t('The %element-title is using the following invalid characters: @invalid-characters.', array('%element-title' => $title, '@invalid-characters' => implode(', ', $invalid_characters_used)))); } if (preg_match('/(\s$)+/', $element['#value'])) { $form_state->setError($element, t('The %element-title doesn\'t allow the patterns ending with whitespace.', array('%element-title' => $title))); } } return $element; }