diff --git a/config/install/pathauto.settings.yml b/config/install/pathauto.settings.yml index bdae42e..76e9523 100644 --- a/config/install/pathauto.settings.yml +++ b/config/install/pathauto.settings.yml @@ -6,7 +6,6 @@ max_length : 100 max_component_length: 100 transliterate : FALSE reduce_ascii : FALSE -ignore_words : ', in, is,that, the , this, with, ' case : 1 ignore_words : 'a, an, as, at, before, but, by, for, from, is, in, into, like, of, off, on, onto, per, since, than, the, this, that, to, up, via, with' -update_action : 2 +update_action : 0 diff --git a/pathauto.module b/pathauto.module index 7484750..4ad3f57 100644 --- a/pathauto.module +++ b/pathauto.module @@ -131,8 +131,8 @@ function pathauto_path_delete_all($source) { * The optional default uri path for the entity. */ function pathauto_entity_path_delete_all(EntityInterface $entity, $default_uri = NULL) { - pathauto_path_delete_all($entity->getSystemPath()); - if (isset($default_uri) && $entity->getSystemPath() != $default_uri) { + pathauto_path_delete_all($entity->urlInfo()); + if (isset($default_uri) && $entity->urlInfo() != $default_uri) { pathauto_path_delete_all($default_uri); } } diff --git a/src/AliasStorageHelper.php b/src/AliasStorageHelper.php index 55c9f95..c2da253 100644 --- a/src/AliasStorageHelper.php +++ b/src/AliasStorageHelper.php @@ -13,6 +13,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Path\AliasStorageInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\Url; /** * Provides helper methods for accessing alias storage. @@ -83,7 +84,7 @@ class AliasStorageHelper implements AliasStorageHelperInterface { */ public function getAliasSchemaMaxLength() { if (!isset($this->aliasSchemaMaxLength)) { - $schema = drupal_get_schema('url_alias'); + $schema = drupal_get_module_schema('system', 'url_alias'); $this->aliasSchemaMaxLength = $schema['fields']['alias']['length']; } return $this->aliasSchemaMaxLength; diff --git a/src/AliasUniquifier.php b/src/AliasUniquifier.php index 09eaac7..10554a1 100644 --- a/src/AliasUniquifier.php +++ b/src/AliasUniquifier.php @@ -143,7 +143,7 @@ class AliasUniquifier implements AliasUniquifierInterface { } try { - $this->urlMatcher->match('/' . $path); + $this->urlMatcher->match($path); return TRUE; } catch (ResourceNotFoundException $e) { diff --git a/src/Form/PathautoSettingsForm.php b/src/Form/PathautoSettingsForm.php index 6819c08..8801332 100644 --- a/src/Form/PathautoSettingsForm.php +++ b/src/Form/PathautoSettingsForm.php @@ -8,7 +8,7 @@ namespace Drupal\pathauto\Form; use Drupal\Core\Form\ConfigFormBase; -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\SafeMarkup; use Drupal\pathauto\PathautoManagerInterface; use Drupal\Core\Form\FormStateInterface; @@ -159,7 +159,7 @@ class PathautoSettingsForm extends ConfigFormBase { } $form['punctuation']['punctuation' . $name] = array( '#type' => 'select', - '#title' => $details['name'] . ' (' . String::checkPlain($details['value']) . ')', + '#title' => $details['name'] . ' (' . SafeMarkup::checkPlain($details['value']) . ')', '#default_value' => $details['default'], '#options' => array( PathautoManagerInterface::PUNCTUATION_REMOVE => t('Remove'), diff --git a/src/PathautoManager.php b/src/PathautoManager.php index 84ea8ee..ccaa15f 100644 --- a/src/PathautoManager.php +++ b/src/PathautoManager.php @@ -7,7 +7,7 @@ namespace Drupal\pathauto; -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; @@ -221,7 +221,7 @@ class PathautoManager implements PathautoManagerInterface { } // Remove all HTML tags from the string. - $output = strip_tags(String::decodeEntities($string)); + $output = strip_tags(Html::decodeEntities($string)); // Optionally transliterate. if ($this->cleanStringCache['transliterate']) { @@ -338,7 +338,7 @@ class PathautoManager implements PathautoManagerInterface { $context = array( 'module' => $module, 'op' => $op, - 'source' => $source, + 'source' => '/' . $source->getInternalPath(), 'data' => $data, 'type' => $type, 'language' => &$langcode, @@ -353,7 +353,7 @@ class PathautoManager implements PathautoManagerInterface { // Special handling when updating an item which is already aliased. $existing_alias = NULL; if ($op == 'update' || $op == 'bulkupdate') { - if ($existing_alias = $this->aliasStorageHelper->loadBySource($source, $langcode)) { + if ($existing_alias = $this->aliasStorageHelper->loadBySource($context['source'], $langcode)) { switch ($config->get('update_action')) { case PathautoManagerInterface::UPDATE_ACTION_NO_NEW: // If an alias already exists, @@ -382,10 +382,9 @@ class PathautoManager implements PathautoManagerInterface { return NULL; } - $alias = $this->aliasCleaner->cleanAlias($alias); + $alias = '/' . $this->aliasCleaner->cleanAlias($alias); // Allow other modules to alter the alias. - $context['source'] = &$source; $context['pattern'] = $pattern; $this->moduleHandler->alter('pathauto_alias', $alias, $context); @@ -396,7 +395,7 @@ class PathautoManager implements PathautoManagerInterface { // If the alias already exists, generate a new, hopefully unique, variant. $original_alias = $alias; - $this->aliasUniquifier->uniquify($alias, $source, $langcode); + $this->aliasUniquifier->uniquify($alias, $context['source'], $langcode); if ($original_alias != $alias) { // Alert the user why this happened. $this->messenger->addMessage($this->t('The automatically generated alias %original_alias conflicted with an existing alias. Alias changed to %alias.', array( @@ -410,9 +409,14 @@ class PathautoManager implements PathautoManagerInterface { return $alias; } + // If there is no differences with the existing alias, stop here. + if ($existing_alias['alias'] == $alias) { + return NULL; + } + // Build the new path alias array and send it off to be created. $path = array( - 'source' => $source, + 'source' => $context['source'], 'alias' => $alias, 'language' => $langcode, ); @@ -491,7 +495,7 @@ class PathautoManager implements PathautoManagerInterface { } $result = $this->createAlias( - $type, $op, $entity->getSystemPath(), array($type => $entity), $bundle, $options['language']); + $type, $op, $entity->urlInfo(), array($type => $entity), $bundle, $options['language']); if ($type == 'taxonomy_term' && empty($options['is_child'])) { // For all children generate new aliases. diff --git a/src/Plugin/Field/FieldWidget/PathautoWidget.php b/src/Plugin/Field/FieldWidget/PathautoWidget.php index 8acde06..f0c2875 100644 --- a/src/Plugin/Field/FieldWidget/PathautoWidget.php +++ b/src/Plugin/Field/FieldWidget/PathautoWidget.php @@ -61,9 +61,9 @@ class PathautoWidget extends PathWidget { if (!isset($entity->path->pathauto)) { if (!$entity->isNew()) { module_load_include('inc', 'pathauto'); - $path = \Drupal::service('path.alias_manager')->getAliasByPath($entity->getSystemPath(), $entity->language()->getId()); - $pathauto_alias = \Drupal::service('pathauto.manager')->createAlias($entity->getEntityTypeId(), 'return', $entity->getSystemPath(), array($entity->getEntityType()->id() => $entity), $entity->bundle(), $entity->language()->getId()); - $entity->path->pathauto = ($path != $entity->getSystemPath() && $path == $pathauto_alias); + $path = \Drupal::service('path.alias_manager')->getAliasByPath($entity->urlInfo(), $entity->language()->getId()); + $pathauto_alias = \Drupal::service('pathauto.manager')->createAlias($entity->getEntityTypeId(), 'return', $entity->urlInfo(), array($entity->getEntityType()->id() => $entity), $entity->bundle(), $entity->language()->getId()); + $entity->path->pathauto = ($path != $entity->urlInfo() && $path == $pathauto_alias); } else { $entity->path->pathauto = TRUE; diff --git a/src/Tests/PathautoNodeWebTest.php b/src/Tests/PathautoNodeWebTest.php index 1e2626a..8f76d61 100644 --- a/src/Tests/PathautoNodeWebTest.php +++ b/src/Tests/PathautoNodeWebTest.php @@ -82,7 +82,7 @@ class PathautoNodeWebTest extends WebTestBase { 'path[0][pathauto]' => FALSE, 'path[0][alias]' => $manual_alias, ); - $this->drupalPostForm("{$node->getSystemPath()}/edit", $edit, t('Save and keep published')); + $this->drupalPostForm("{$node->urlInfo()}/edit", $edit, t('Save and keep published')); $this->assertRaw(t('@type %title has been updated.', array('@type' => 'page', '%title' => $title))); // Check that the automatic alias checkbox is now unchecked by default. @@ -132,7 +132,7 @@ class PathautoNodeWebTest extends WebTestBase { $node = $this->drupalGetNodeByTitle($edit['title']); // Pathauto checkbox should still not exist. - $this->drupalGet($node->getSystemPath() . '/edit'); + $this->drupalGet($node->urlInfo() . '/edit'); $this->assertNoFieldById('edit-path-0-pathauto'); $this->assertFieldByName('path[0][alias]', ''); $this->assertNoEntityAlias($node); diff --git a/src/Tests/PathautoTestHelperTrait.php b/src/Tests/PathautoTestHelperTrait.php index 304cb50..4a51ca0 100644 --- a/src/Tests/PathautoTestHelperTrait.php +++ b/src/Tests/PathautoTestHelperTrait.php @@ -33,7 +33,7 @@ trait PathautoTestHelperTrait { if (!$langcode) { $langcode = $entity->language()->getId(); } - return $this->saveAlias($entity->getSystemPath(), $alias, $langcode); + return $this->saveAlias($entity->urlInfo(), $alias, $langcode); } public function assertEntityAlias(EntityInterface $entity, $expected_alias, $langcode = NULL) { @@ -41,11 +41,11 @@ trait PathautoTestHelperTrait { if (!$langcode) { $langcode = $entity->language()->getId(); } - $this->assertAlias($entity->getSystemPath(), $expected_alias, $langcode); + $this->assertAlias($entity->urlInfo(), $expected_alias, $langcode); } public function assertEntityAliasExists(EntityInterface $entity) { - return $this->assertAliasExists(array('source' => $entity->getSystemPath())); + return $this->assertAliasExists(array('source' => $entity->urlInfo())); } public function assertNoEntityAlias(EntityInterface $entity, $langcode = NULL) { @@ -53,11 +53,11 @@ trait PathautoTestHelperTrait { if (!$langcode) { $langcode = $entity->language()->getId(); } - $this->assertEntityAlias($entity, $entity->getSystemPath(), $langcode); + $this->assertEntityAlias($entity, $entity->urlInfo(), $langcode); } public function assertNoEntityAliasExists(EntityInterface $entity) { - $this->assertNoAliasExists(array('source' => $entity->getSystemPath())); + $this->assertNoAliasExists(array('source' => $entity->urlInfo())); } public function assertAlias($source, $expected_alias, $langcode = Language::LANGCODE_NOT_SPECIFIED) { diff --git a/src/Tests/PathautoUnitTest.php b/src/Tests/PathautoUnitTest.php index 04dfc99..4fa3799 100644 --- a/src/Tests/PathautoUnitTest.php +++ b/src/Tests/PathautoUnitTest.php @@ -8,7 +8,7 @@ namespace Drupal\pathauto\Tests; use Drupal\Core\Language\Language; -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\SafeMarkup; use Drupal\pathauto\PathautoManagerInterface; use Drupal\simpletest\KernelTestBase; @@ -134,7 +134,7 @@ class PathautoUnitTest extends KernelTestBase { // Test that HTML tags are removed. $tests['This text has
HTML tags.'] = 'text-has-html-tags'; - $tests[String::checkPlain('This text has
HTML tags.')] = 'text-has-html-tags'; + $tests[SafeMarkup::checkPlain('This text has
HTML tags.')] = 'text-has-html-tags'; // Transliteration. $tests['ľščťžýáíéňô'] = 'lsctzyaieno'; @@ -214,7 +214,7 @@ class PathautoUnitTest extends KernelTestBase { $node->setTitle('Third title'); $node->save(); $this->assertEntityAlias($node, 'content/third-title'); - $this->assertAliasExists(array('source' => $node->getSystemPath(), 'alias' => 'content/second-title')); + $this->assertAliasExists(array('source' => $node->urlInfo(), 'alias' => 'content/second-title')); $config->set('update_action', PathautoManagerInterface::UPDATE_ACTION_DELETE); $config->save(); @@ -223,7 +223,7 @@ class PathautoUnitTest extends KernelTestBase { $this->assertEntityAlias($node, 'content/fourth-title'); $this->assertNoAliasExists(array('alias' => 'content/third-title')); // The older second alias is not deleted yet. - $older_path = $this->assertAliasExists(array('source' => $node->getSystemPath(), 'alias' => 'content/second-title')); + $older_path = $this->assertAliasExists(array('source' => $node->urlInfo(), 'alias' => 'content/second-title')); \Drupal::service('path.alias_storage')->delete($older_path); $config->set('update_action', PathautoManagerInterface::UPDATE_ACTION_NO_NEW);