Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
PLAT-556 Update pathauto
Browse files Browse the repository at this point in the history
  • Loading branch information
Saphyel committed Oct 31, 2016
1 parent 25bdf34 commit 541e40e
Show file tree
Hide file tree
Showing 55 changed files with 516 additions and 438 deletions.
2 changes: 1 addition & 1 deletion profiles/cr/drupal-org.make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ projects:
branch: 8.x-1.x
revision: 2065f39
pathauto:
version: 1.0-alpha3
version: 1.0-beta1
redirect:
version: 1.0-alpha1
token:
Expand Down
10 changes: 0 additions & 10 deletions profiles/cr/modules/contrib/pathauto/composer.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enabled_entity_types:
- user
punctuation:
hyphen: 1
verbose : FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
pathauto.settings:
type: config_object
mapping:
enabled_entity_types:
label: Enabled entity types
type: sequence
sequence:
type: string
punctuation:
type: sequence
sequence:
Expand Down
9 changes: 5 additions & 4 deletions profiles/cr/modules/contrib/pathauto/pathauto.api.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

use Drupal\Core\Language\Language;

/**
* @file
* Documentation for pathauto API.
*
*/

use Drupal\Core\Language\Language;

/**
* @todo Update for 8.x-1.x
*
* It may be helpful to review some examples of integration from
Expand Down Expand Up @@ -56,7 +58,6 @@
*
* @param array &$definitions
* Alias type definitions.
*
*/
function hook_path_alias_types_alter(array &$definitions) {
}
Expand Down
14 changes: 7 additions & 7 deletions profiles/cr/modules/contrib/pathauto/pathauto.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ description : 'Provides a mechanism for modules to automatically generate aliase
type: module

dependencies:
- ctools
- path
- token
- ctools:ctools
- drupal:path
- token:token

configure: entity.pathauto_pattern.collection

recommends:
- redirect
- redirect:redirect

# Information added by Drupal.org packaging script on 2016-04-18
version: '8.x-1.0-alpha3'
# Information added by Drupal.org packaging script on 2016-09-19
version: '8.x-1.0-beta1'
core: '8.x'
project: 'pathauto'
datestamp: 1461007782
datestamp: 1474313341
10 changes: 10 additions & 0 deletions profiles/cr/modules/contrib/pathauto/pathauto.install
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,13 @@ function pathauto_update_8104() {
function pathauto_update_8105() {
_pathauto_ensure_url_alias_table_exists();
}

/**
* Update default configuration for enabled entity types.
*/
function pathauto_update_8106() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('pathauto.settings');
$config->set('enabled_entity_types', ['user']);
$config->save();
}
61 changes: 34 additions & 27 deletions profiles/cr/modules/contrib/pathauto/pathauto.module
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**
* @file
* @defgroup pathauto Pathauto: Automatically generates aliases for content
*
* The Pathauto module automatically generates path aliases for various kinds of
Expand All @@ -19,10 +20,10 @@
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\pathauto\PathautoState;

/**
Expand All @@ -49,16 +50,19 @@ function pathauto_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.pathauto':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides a mechanism for modules to automatically generate aliases for the content they manage.') . '</p>';
$output .= '<h3>' . t('Configuration') . '</h3>';
$output .= '<ol>';
$output .= '<li>' . t('Configure the module at admin/config/search/path/patterns.') . '</li>';
$output .= '<li>' . t('When you save new content from now on, it should automatically be assigned an alternative URL.') . '</li>';
$output .= '</ol>';
$output .= '<h3>' . t('Settings') . '</h3>';
$output .= '<p>' . t('The Pathauto module provides a mechanism to automate the creation of <a href="path">path</a> aliases. This makes URLs more readable and helps search engines index content more effectively. For more information, see the <a href=":online">online documentation for Pathauto</a>.', [':online' => 'https://www.drupal.org/documentation/modules/pathauto']) . '</p>';
$output .= '<dl>';
$output .= '<dt>' . t('Maximum alias and component length') . '</dt>';
$output .= '<dd>' . t('The <strong>maximum alias length</strong> and <strong>maximum component length</strong> values default to 100 and have a limit of @max from Pathauto. This length is limited by the length of the "alias" column of the url_alias database table. The default database schema for this column is @max. If you set a length that is equal to that of the one set in the "alias" column it will cause problems in situations where the system needs to append additional words to the aliased URL. You should enter a value that is the length of the "alias" column minus the length of any strings that might get added to the end of the URL. The length of strings that might get added to the end of your URLs depends on which modules you have enabled and on your Pathauto settings. The recommended and default value is 100.', array('@max' => \Drupal::service('pathauto.alias_storage_helper')->getAliasSchemaMaxlength())) . '</dd>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dd>' . t('Pathauto is accessed from the tabs it adds to the list of <a href=":aliases">URL aliases</a>.', [':aliases' => Url::fromRoute('path.admin_overview')->toString()]) . '</dd>';
$output .= '<dt>' . t('Creating Pathauto Patterns') . '</dt>';
$output .= '<dd>' . t('The <a href=":pathauto_pattern">"Patterns"</a> page is used to configure automatic path aliasing. New patterns are created here using the <a href=":add_form">Add Pathauto pattern</a> button which presents a form to simplify pattern creation thru the use of <a href="token">available tokens</a>. The patterns page provides a list of all patterns on the site and allows you to edit and reorder them. An alias is generated for the first pattern that applies.', [':pathauto_pattern' => Url::fromRoute('entity.pathauto_pattern.collection')->toString(), ':add_form' => Url::fromRoute('entity.pathauto_pattern.add_form')->toString()]) . '</dd>';
$output .= '<dt>' . t('Pathauto Settings') . '</dt>';
$output .= '<dd>' . t('The <a href=":settings">"Settings"</a> page is used to customize global Pathauto settings for automated pattern creation.', [':settings' => Url::fromRoute('pathauto.settings.form')->toString()]) . '</dd>';
$output .= '<dd>' . t('The <strong>maximum alias length</strong> and <strong>maximum component length</strong> values default to 100 and have a limit of @max from Pathauto. You should enter a value that is the length of the "alias" column of the url_alias database table minus the length of any strings that might get added to the end of the URL. The recommended and default value is 100.', array('@max' => \Drupal::service('pathauto.alias_storage_helper')->getAliasSchemaMaxlength())) . '</dd>';
$output .= '<dt>' . t('Bulk Generation') . '</dt>';
$output .= '<dd>' . t('The <a href=":pathauto_bulk">"Bulk Generate"</a> page allows you to create 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.', [':pathauto_bulk' => Url::fromRoute('pathauto.bulk.update.form')->toString()]) . '</dd>';
$output .= '<dt>' . t('Delete Aliases') . '</dt>';
$output .= '<dd>' . t('The <a href=":pathauto_delete">"Delete Aliases"</a> page allows you to remove URL aliases from items that have previously been assigned aliases using pathauto.', [':pathauto_delete' => Url::fromRoute('pathauto.admin.delete')->toString()]) . '</dd>';
$output .= '</dl>';
return $output;

Expand All @@ -67,7 +71,7 @@ function pathauto_help($route_name, RouteMatchInterface $route_match) {
return $output;

case 'entity.pathauto_pattern.add_form':
$output = '<p>' . t('You need to select a pattern type, then a pattern and filter, and a label.') . '</p>';
$output = '<p>' . t('You need to select a pattern type, then a pattern and filter, and a label. Additional types can be enabled on the <a href=":settings">Settings</a> page.', [':settings' => Url::fromRoute('pathauto.settings.form')->toString()]) . '</p>';
return $output;

case 'pathauto.bulk.update.form':
Expand Down Expand Up @@ -139,21 +143,24 @@ function pathauto_field_widget_info_alter(&$widgets) {
* Implements hook_entity_base_field_info().
*/
function pathauto_entity_base_field_info(EntityTypeInterface $entity_type) {
// @todo: Make this configurable and/or remove if
// https://drupal.org/node/476294 is resolved.
if ($entity_type->id() === 'user') {
$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;
$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;
}
}
}

Expand All @@ -179,7 +186,7 @@ function pathauto_pattern_validate($element, FormStateInterface $form_state) {
$invalid_characters = ['#', '?', '&'];
$invalid_characters_used = [];

foreach($invalid_characters as $invalid_character) {
foreach ($invalid_characters as $invalid_character) {
if (strpos($element['#value'], $invalid_character) !== FALSE) {
$invalid_characters_used[] = $invalid_character;
}
Expand Down
6 changes: 4 additions & 2 deletions profiles/cr/modules/contrib/pathauto/pathauto.services.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
services:
pathauto.generator:
class: Drupal\pathauto\PathautoGenerator
arguments: ['@config.factory', '@module_handler', '@token', '@pathauto.alias_cleaner', '@pathauto.alias_storage_helper', '@pathauto.alias_uniquifier', '@pathauto.verbose_messenger', '@string_translation', '@token.entity_mapper']
arguments: ['@config.factory', '@module_handler', '@token', '@pathauto.alias_cleaner', '@pathauto.alias_storage_helper', '@pathauto.alias_uniquifier', '@pathauto.verbose_messenger', '@string_translation', '@token.entity_mapper', '@entity_type.manager']
pathauto.alias_cleaner:
class: Drupal\pathauto\AliasCleaner
arguments: ['@config.factory', '@pathauto.alias_storage_helper', '@language_manager', '@cache.discovery', '@transliteration', '@module_handler']
pathauto.alias_storage_helper:
class: Drupal\pathauto\AliasStorageHelper
arguments: ['@config.factory', '@path.alias_storage', '@database','@pathauto.verbose_messenger', '@string_translation']
tags:
- { name: backend_overridable }
pathauto.alias_uniquifier:
class: Drupal\pathauto\AliasUniquifier
arguments: ['@config.factory', '@pathauto.alias_storage_helper','@module_handler', '@router.no_access_checks', '@path.alias_manager']
arguments: ['@config.factory', '@pathauto.alias_storage_helper','@module_handler', '@router.route_provider', '@path.alias_manager']
pathauto.verbose_messenger:
class: Drupal\pathauto\VerboseMessenger
arguments: ['@config.factory', '@current_user']
Expand Down
1 change: 0 additions & 1 deletion profiles/cr/modules/contrib/pathauto/pathauto.tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Token integration for the Pathauto module.
*/

use Drupal\Core\Render\Element;
use Drupal\Core\Render\BubbleableMetadata;

/**
Expand Down
5 changes: 0 additions & 5 deletions profiles/cr/modules/contrib/pathauto/src/AliasCleaner.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

/**
* @file
* Contains Drupal\pathauto\AliasCleaner
*/

namespace Drupal\pathauto;

use Drupal\Component\Render\PlainTextOutput;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php

/**
* @file
* Contains Drupal\pathauto\AliasCleanerInterface
*/
namespace Drupal\pathauto;

/**
Expand Down Expand Up @@ -103,4 +99,5 @@ public function cleanTokenValues(&$replacements, $data = array(), $options = arr
* Resets internal caches.
*/
public function resetCaches();

}
93 changes: 59 additions & 34 deletions profiles/cr/modules/contrib/pathauto/src/AliasStorageHelper.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

/**
* @file
* Contains Drupal\pathauto\AliasSchemaHelper
*/

namespace Drupal\pathauto;

use Drupal\Core\Config\ConfigFactoryInterface;
Expand Down Expand Up @@ -155,63 +150,93 @@ public function save(array $path, $existing_alias = NULL, $op = NULL) {
* {@inheritdoc}
*/
public function loadBySource($source, $language = LanguageInterface::LANGCODE_NOT_SPECIFIED) {
// @todo convert this to be a query on alias storage.
$pid = $this->database->queryRange("SELECT pid FROM {url_alias} WHERE source = :source AND langcode IN (:language, :language_none) ORDER BY langcode DESC, pid DESC", 0, 1, array(
':source' => $source,
':language' => $language,
':language_none' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
))->fetchField();
return $this->aliasStorage->load(array('pid' => $pid));
$alias = $this->aliasStorage->load([
'source' => $source,
'langcode' => $language,
]);
// If no alias was fetched and if a language was specified, fallbacks to
// undefined language.
if (!$alias && ($language !== LanguageInterface::LANGCODE_NOT_SPECIFIED)) {
$alias = $this->aliasStorage->load([
'source' => $source,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
}
return $alias;
}

/**
* {@inheritdoc}
*/
public function exists($alias, $source, $language = LanguageInterface::LANGCODE_NOT_SPECIFIED) {
return (bool) $this->database->queryRange("SELECT pid FROM {url_alias} WHERE source <> :source AND alias = :alias AND langcode IN (:language, :language_none) ORDER BY langcode DESC, pid DESC", 0, 1, array(
':source' => $source,
':alias' => $alias,
':language' => $language,
':language_none' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
))->fetchField();
public function deleteBySourcePrefix($source) {
$pids = $this->loadBySourcePrefix($source);
if ($pids) {
$this->deleteMultiple($pids);
}
}

/**
* {@inheritdoc}
*/
public function deleteAll($source) {
$pids = $this->loadBySourcePrefix($source);
if ($pids) {
$this->deleteMultiple($pids);
}
public function deleteAll() {
$this->database->truncate('url_alias')->execute();
}

/**
* {@inheritdoc}
*/
public function deleteEntityPathAll(EntityInterface $entity, $default_uri = NULL) {
$this->deleteAll('/'. $entity->toUrl('canonical')->getInternalPath());
$this->deleteBySourcePrefix('/' . $entity->toUrl('canonical')->getInternalPath());
if (isset($default_uri) && $entity->toUrl('canonical')->toString() != $default_uri) {
$this->deleteAll($default_uri);
$this->deleteBySourcePrefix($default_uri);
}
}

/**
* {@inheritdoc}
*/
public function deleteMultiple($pids) {
foreach ($pids as $pid) {
$this->aliasStorage->delete(array('pid' => $pid));
}
public function loadBySourcePrefix($source) {
return $this->database->select('url_alias', 'u')
->fields('u', array('pid'))
->condition('source', $source . '%', 'LIKE')
->execute()
->fetchCol();
}

/**
* {@inheritdoc}
*/
public function loadBySourcePrefix($source) {
return $this->database->query("SELECT pid FROM {url_alias} WHERE source = :source OR source LIKE :source_wildcard",
[':source' => $source, ':source_wildcard' => $source . '/%'])
->fetchCol();
public function countBySourcePrefix($source) {
return $this->database->select('url_alias')
->condition('source', $source . '%', 'LIKE')
->countQuery()
->execute()
->fetchField();
}

/**
* {@inheritdoc}
*/
public function countAll() {
return $this->database->select('url_alias')
->countQuery()
->execute()
->fetchField();
}

/**
* Delete multiple URL aliases.
*
* Intent of this is to abstract a potential path_delete_multiple() function
* for Drupal 7 or 8.
*
* @param int[] $pids
* An array of path IDs to delete.
*/
protected function deleteMultiple($pids) {
foreach ($pids as $pid) {
$this->aliasStorage->delete(array('pid' => $pid));
}
}

}
Loading

0 comments on commit 541e40e

Please sign in to comment.