Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -2,6 +2,7 @@ id: d6_url_alias
|
|||
label: URL aliases
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Content
|
||||
source:
|
||||
plugin: d6_url_alias
|
||||
constants:
|
||||
|
@ -26,7 +27,9 @@ process:
|
|||
source: src
|
||||
delimiter: /
|
||||
-
|
||||
# If the source path has no slashes return a dummy default value.
|
||||
plugin: extract
|
||||
default: 'INVALID_NID'
|
||||
index:
|
||||
- 1
|
||||
-
|
|
@ -2,6 +2,7 @@ id: d7_url_alias
|
|||
label: URL aliases
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
source:
|
||||
plugin: d7_url_alias
|
||||
constants:
|
||||
|
@ -24,7 +25,9 @@ process:
|
|||
source: source
|
||||
delimiter: /
|
||||
-
|
||||
# If the source path has no slashes return a dummy default value.
|
||||
plugin: extract
|
||||
default: 'INVALID_NID'
|
||||
index:
|
||||
- 1
|
||||
-
|
|
@ -15,9 +15,9 @@
|
|||
*
|
||||
* @param array $path
|
||||
* The array structure is identical to that of the return value of
|
||||
* \Drupal\Core\Path\PathInterface::save().
|
||||
* \Drupal\Core\Path\AliasStorageInterface::save().
|
||||
*
|
||||
* @see \Drupal\Core\Path\PathInterface::save()
|
||||
* @see \Drupal\Core\Path\AliasStorageInterface::save()
|
||||
*/
|
||||
function hook_path_insert($path) {
|
||||
db_insert('mytable')
|
||||
|
@ -33,9 +33,9 @@ function hook_path_insert($path) {
|
|||
*
|
||||
* @param array $path
|
||||
* The array structure is identical to that of the return value of
|
||||
* \Drupal\Core\Path\PathInterface::save().
|
||||
* \Drupal\Core\Path\AliasStorageInterface::save().
|
||||
*
|
||||
* @see \Drupal\Core\Path\PathInterface::save()
|
||||
* @see \Drupal\Core\Path\AliasStorageInterface::save()
|
||||
*/
|
||||
function hook_path_update($path) {
|
||||
if ($path['alias'] != $path['original']['alias']) {
|
||||
|
@ -51,9 +51,9 @@ function hook_path_update($path) {
|
|||
*
|
||||
* @param array $path
|
||||
* The array structure is identical to that of the return value of
|
||||
* \Drupal\Core\Path\PathInterface::save().
|
||||
* \Drupal\Core\Path\AliasStorageInterface::save().
|
||||
*
|
||||
* @see \Drupal\Core\Path\PathInterface::delete()
|
||||
* @see \Drupal\Core\Path\AliasStorageInterface::delete()
|
||||
*/
|
||||
function hook_path_delete($path) {
|
||||
db_delete('mytable')
|
||||
|
|
27
web/core/modules/path/path.es6.js
Normal file
27
web/core/modules/path/path.es6.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Path module.
|
||||
*/
|
||||
(function($, Drupal) {
|
||||
/**
|
||||
* Behaviors for settings summaries on path edit forms.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches summary behavior on path edit forms.
|
||||
*/
|
||||
Drupal.behaviors.pathDetailsSummaries = {
|
||||
attach(context) {
|
||||
$(context)
|
||||
.find('.path-form')
|
||||
.drupalSetSummary(context => {
|
||||
const path = $('.js-form-item-path-0-alias input').val();
|
||||
|
||||
return path
|
||||
? Drupal.t('Alias: @alias', { '@alias': path })
|
||||
: Drupal.t('No alias');
|
||||
});
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal);
|
|
@ -1,29 +1,18 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Path module.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Behaviors for settings summaries on path edit forms.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches summary behavior on path edit forms.
|
||||
*/
|
||||
Drupal.behaviors.pathDetailsSummaries = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
$(context).find('.path-form').drupalSetSummary(function (context) {
|
||||
var path = $('.js-form-item-path-0-alias input').val();
|
||||
|
||||
return path ?
|
||||
Drupal.t('Alias: @alias', {'@alias': path}) :
|
||||
Drupal.t('No alias');
|
||||
return path ? Drupal.t('Alias: @alias', { '@alias': path }) : Drupal.t('No alias');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal);
|
||||
})(jQuery, Drupal);
|
|
@ -5,9 +5,9 @@
|
|||
* Enables users to rename URLs.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
|
@ -36,33 +36,11 @@ function path_help($route_name, RouteMatchInterface $route_match) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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') {
|
||||
if (in_array($entity_type->id(), ['taxonomy_term', 'node', 'media'], TRUE)) {
|
||||
$fields['path'] = BaseFieldDefinition::create('path')
|
||||
->setLabel(t('URL alias'))
|
||||
->setTranslatable(TRUE)
|
||||
|
@ -76,3 +54,17 @@ function path_entity_base_field_info(EntityTypeInterface $entity_type) {
|
|||
return $fields;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_translation_create().
|
||||
*/
|
||||
function path_entity_translation_create(ContentEntityInterface $translation) {
|
||||
foreach ($translation->getFieldDefinitions() as $field_name => $field_definition) {
|
||||
if ($field_definition->getType() === 'path' && $translation->get($field_name)->pid) {
|
||||
// If there are values and a path ID, update the langcode and unset the
|
||||
// path ID to save this as a new alias.
|
||||
$translation->get($field_name)->langcode = $translation->language()->getId();
|
||||
$translation->get($field_name)->pid = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ class PathController extends ControllerBase {
|
|||
* The request object.
|
||||
*
|
||||
* @return array
|
||||
* A render array as expected by drupal_render().
|
||||
* A render array as expected by
|
||||
* \Drupal\Core\Render\RendererInterface::render().
|
||||
*/
|
||||
public function adminOverview(Request $request) {
|
||||
$keys = $request->query->get('search');
|
||||
|
|
|
@ -6,6 +6,8 @@ use Drupal\Core\Language\LanguageInterface;
|
|||
|
||||
/**
|
||||
* Provides the path add form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class AddForm extends PathFormBase {
|
||||
|
||||
|
|
|
@ -10,20 +10,22 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Builds the form to delete a path alias.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DeleteForm extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* The alias storage service.
|
||||
*
|
||||
* @var AliasStorageInterface $path
|
||||
* @var \Drupal\Core\Path\AliasStorageInterface
|
||||
*/
|
||||
protected $aliasStorage;
|
||||
|
||||
/**
|
||||
* The path alias being deleted.
|
||||
*
|
||||
* @var array $pathAlias
|
||||
* @var array
|
||||
*/
|
||||
protected $pathAlias;
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ use Drupal\Core\Url;
|
|||
|
||||
/**
|
||||
* Provides the path edit form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class EditForm extends PathFormBase {
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
|
||||
/**
|
||||
* Provides the path admin overview filter form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PathFilterForm extends FormBase {
|
||||
|
||||
|
@ -30,7 +32,7 @@ class PathFilterForm extends FormBase {
|
|||
];
|
||||
$form['basic']['filter'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => 'Path alias',
|
||||
'#title' => $this->t('Path alias'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $keys,
|
||||
'#maxlength' => 128,
|
||||
|
|
|
@ -138,7 +138,7 @@ abstract class PathFormBase extends FormBase {
|
|||
else {
|
||||
$form['langcode'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $this->path['langcode']
|
||||
'#value' => $this->path['langcode'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -191,9 +191,8 @@ abstract class PathFormBase extends FormBase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$this->pathValidator->isValid(trim($source, '/'))) {
|
||||
$form_state->setErrorByName('source', t("The path '@link_path' is either invalid or you do not have access to it.", ['@link_path' => $source]));
|
||||
$form_state->setErrorByName('source', t("Either the path '@link_path' is invalid or you do not have access to it.", ['@link_path' => $source]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,7 +212,7 @@ abstract class PathFormBase extends FormBase {
|
|||
|
||||
$this->aliasStorage->save($source, $alias, $langcode, $pid);
|
||||
|
||||
drupal_set_message($this->t('The alias has been saved.'));
|
||||
$this->messenger()->addStatus($this->t('The alias has been saved.'));
|
||||
$form_state->setRedirect('path.admin_overview');
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,42 @@ namespace Drupal\path\Plugin\Field\FieldType;
|
|||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Field\FieldItemList;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\TypedData\ComputedItemListTrait;
|
||||
|
||||
/**
|
||||
* Represents a configurable entity path field.
|
||||
*/
|
||||
class PathFieldItemList extends FieldItemList {
|
||||
|
||||
use ComputedItemListTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function computeValue() {
|
||||
// Default the langcode to the current language if this is a new entity or
|
||||
// there is no alias for an existent entity.
|
||||
// @todo Set the langcode to not specified for untranslatable fields
|
||||
// in https://www.drupal.org/node/2689459.
|
||||
$value = ['langcode' => $this->getLangcode()];
|
||||
|
||||
$entity = $this->getEntity();
|
||||
if (!$entity->isNew()) {
|
||||
// @todo Support loading language neutral aliases in
|
||||
// https://www.drupal.org/node/2511968.
|
||||
$alias = \Drupal::service('path.alias_storage')->load([
|
||||
'source' => '/' . $entity->toUrl()->getInternalPath(),
|
||||
'langcode' => $this->getLangcode(),
|
||||
]);
|
||||
|
||||
if ($alias) {
|
||||
$value = $alias;
|
||||
}
|
||||
}
|
||||
|
||||
$this->list[0] = $this->createItem(0, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,8 @@ use Drupal\Core\TypedData\DataDefinition;
|
|||
* description = @Translation("An entity field containing a path alias and related data."),
|
||||
* no_ui = TRUE,
|
||||
* default_widget = "path",
|
||||
* list_class = "\Drupal\path\Plugin\Field\FieldType\PathFieldItemList"
|
||||
* list_class = "\Drupal\path\Plugin\Field\FieldType\PathFieldItemList",
|
||||
* constraints = {"PathAlias" = {}},
|
||||
* )
|
||||
*/
|
||||
class PathItem extends FieldItemBase {
|
||||
|
@ -30,6 +31,8 @@ class PathItem extends FieldItemBase {
|
|||
->setLabel(t('Path alias'));
|
||||
$properties['pid'] = DataDefinition::create('integer')
|
||||
->setLabel(t('Path id'));
|
||||
$properties['langcode'] = DataDefinition::create('string')
|
||||
->setLabel(t('Language Code'));
|
||||
return $properties;
|
||||
}
|
||||
|
||||
|
@ -40,11 +43,20 @@ class PathItem extends FieldItemBase {
|
|||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEmpty() {
|
||||
return ($this->alias === NULL || $this->alias === '') && ($this->pid === NULL || $this->pid === '') && ($this->langcode === NULL || $this->langcode === '');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preSave() {
|
||||
$this->alias = trim($this->alias);
|
||||
if ($this->alias !== NULL) {
|
||||
$this->alias = trim($this->alias);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +89,7 @@ class PathItem extends FieldItemBase {
|
|||
*/
|
||||
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
|
||||
$random = new Random();
|
||||
$values['alias'] = str_replace(' ', '-', strtolower($random->sentences(3)));
|
||||
$values['alias'] = '/' . str_replace(' ', '-', strtolower($random->sentences(3)));
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Drupal\path\Plugin\Field\FieldWidget;
|
|||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\WidgetBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||
|
||||
/**
|
||||
|
@ -26,23 +25,6 @@ class PathWidget extends WidgetBase {
|
|||
*/
|
||||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
|
||||
$entity = $items->getEntity();
|
||||
$path = [];
|
||||
if (!$entity->isNew()) {
|
||||
$conditions = ['source' => '/' . $entity->urlInfo()->getInternalPath()];
|
||||
if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
|
||||
$conditions['langcode'] = $items->getLangcode();
|
||||
}
|
||||
$path = \Drupal::service('path.alias_storage')->load($conditions);
|
||||
if ($path === FALSE) {
|
||||
$path = [];
|
||||
}
|
||||
}
|
||||
$path += [
|
||||
'pid' => NULL,
|
||||
'source' => !$entity->isNew() ? '/' . $entity->urlInfo()->getInternalPath() : NULL,
|
||||
'alias' => '',
|
||||
'langcode' => $items->getLangcode(),
|
||||
];
|
||||
|
||||
$element += [
|
||||
'#element_validate' => [[get_class($this), 'validateFormElement']],
|
||||
|
@ -50,23 +32,44 @@ class PathWidget extends WidgetBase {
|
|||
$element['alias'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $element['#title'],
|
||||
'#default_value' => $path['alias'],
|
||||
'#default_value' => $items[$delta]->alias,
|
||||
'#required' => $element['#required'],
|
||||
'#maxlength' => 255,
|
||||
'#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.'),
|
||||
];
|
||||
$element['pid'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $path['pid'],
|
||||
'#value' => $items[$delta]->pid,
|
||||
];
|
||||
$element['source'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $path['source'],
|
||||
];
|
||||
'#value' => !$entity->isNew() ? '/' . $entity->toUrl()->getInternalPath() : NULL,
|
||||
];
|
||||
$element['langcode'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $path['langcode'],
|
||||
'#value' => $items[$delta]->langcode,
|
||||
];
|
||||
|
||||
// If the advanced settings tabs-set is available (normally rendered in the
|
||||
// second column on wide-resolutions), place the field as a details element
|
||||
// in this tab-set.
|
||||
if (isset($form['advanced'])) {
|
||||
$element += [
|
||||
'#type' => 'details',
|
||||
'#title' => t('URL path settings'),
|
||||
'#open' => !empty($items[$delta]->alias),
|
||||
'#group' => 'advanced',
|
||||
'#access' => $entity->get('path')->access('edit'),
|
||||
'#attributes' => [
|
||||
'class' => ['path-form'],
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => ['path/drupal.path'],
|
||||
],
|
||||
];
|
||||
$element['#weight'] = 30;
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\path\Plugin\Validation\Constraint;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* Validation constraint for changing path aliases in pending revisions.
|
||||
*
|
||||
* @Constraint(
|
||||
* id = "PathAlias",
|
||||
* label = @Translation("Path alias.", context = "Validation"),
|
||||
* )
|
||||
*/
|
||||
class PathAliasConstraint extends Constraint {
|
||||
|
||||
public $message = 'You can only change the URL alias for the <em>published</em> version of this content.';
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\path\Plugin\Validation\Constraint;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
/**
|
||||
* Constraint validator for changing path aliases in pending revisions.
|
||||
*/
|
||||
class PathAliasConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
private $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Creates a new PathAliasConstraintValidator instance.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($value, Constraint $constraint) {
|
||||
$entity = !empty($value->getParent()) ? $value->getEntity() : NULL;
|
||||
|
||||
if ($entity && !$entity->isNew() && !$entity->isDefaultRevision()) {
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $original */
|
||||
$original = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
|
||||
if ($value->alias != $original->path->alias) {
|
||||
$this->context->addViolation($constraint->message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@ class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterfac
|
|||
/**
|
||||
* The alias storage service.
|
||||
*
|
||||
* @var \Drupal\Core\Path\AliasStorage $aliasStorage
|
||||
* @var \Drupal\Core\Path\AliasStorage
|
||||
*/
|
||||
protected $aliasStorage;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use Drupal\path\Plugin\migrate\source\UrlAliasBase;
|
|||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_url_alias",
|
||||
* source_provider = "path"
|
||||
* source_module = "path"
|
||||
* )
|
||||
*/
|
||||
class UrlAlias extends UrlAliasBase {
|
||||
|
|
|
@ -9,7 +9,7 @@ use Drupal\path\Plugin\migrate\source\UrlAliasBase;
|
|||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_url_alias",
|
||||
* source_provider = "path"
|
||||
* source_module = "path"
|
||||
* )
|
||||
*/
|
||||
class UrlAlias extends UrlAliasBase {
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Drupal\Tests\path\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Add, edit, delete, and change alias and verify its consistency in the
|
||||
|
@ -25,7 +25,7 @@ class PathAliasTest extends PathTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create test user and log in.
|
||||
$web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer url aliases', 'create url aliases']);
|
||||
$web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer url aliases', 'create url aliases', 'access content overview']);
|
||||
$this->drupalLogin($web_user);
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ class PathAliasTest extends PathTestBase {
|
|||
$this->drupalGet($edit['alias']);
|
||||
$this->assertText($node1->label(), 'Alias works lower case.');
|
||||
$this->assertResponse(200);
|
||||
$this->drupalGet(Unicode::strtoupper($edit['alias']));
|
||||
$this->drupalGet(mb_strtoupper($edit['alias']));
|
||||
$this->assertText($node1->label(), 'Alias works upper case.');
|
||||
$this->assertResponse(200);
|
||||
|
||||
|
@ -92,7 +92,8 @@ class PathAliasTest extends PathTestBase {
|
|||
$pid = $this->getPID($edit['alias']);
|
||||
|
||||
$previous = $edit['alias'];
|
||||
$edit['alias'] = '/alias' . // Lower-case letters.
|
||||
// Lower-case letters.
|
||||
$edit['alias'] = '/alias' .
|
||||
// "Special" ASCII characters.
|
||||
"- ._~!$'\"()*@[]?&+%#,;=:" .
|
||||
// Characters that look like a percent-escaped string.
|
||||
|
@ -110,7 +111,7 @@ class PathAliasTest extends PathTestBase {
|
|||
$this->drupalPostForm('admin/config/search/path/edit/' . $pid, $edit, t('Save'));
|
||||
|
||||
// Confirm that the alias works.
|
||||
$this->drupalGet(Unicode::strtoupper($edit['alias']));
|
||||
$this->drupalGet(mb_strtoupper($edit['alias']));
|
||||
$this->assertText($node1->label(), 'Changed alias works.');
|
||||
$this->assertResponse(200);
|
||||
|
||||
|
@ -132,7 +133,7 @@ class PathAliasTest extends PathTestBase {
|
|||
$this->assertRaw(t('The alias %alias is already in use in this language.', ['%alias' => $edit['alias']]), 'Attempt to move alias was rejected.');
|
||||
|
||||
$edit_upper = $edit;
|
||||
$edit_upper['alias'] = Unicode::strtoupper($edit['alias']);
|
||||
$edit_upper['alias'] = mb_strtoupper($edit['alias']);
|
||||
$this->drupalPostForm('admin/config/search/path/add', $edit_upper, t('Save'));
|
||||
$this->assertRaw(t('The alias %alias could not be added because it is already in use in this language with different capitalization: %stored_alias.', [
|
||||
'%alias' => $edit_upper['alias'],
|
||||
|
@ -246,7 +247,8 @@ class PathAliasTest extends PathTestBase {
|
|||
|
||||
$previous = $edit['path[0][alias]'];
|
||||
// Change alias to one containing "exotic" characters.
|
||||
$edit['path[0][alias]'] = '/alias' . // Lower-case letters.
|
||||
// Lower-case letters.
|
||||
$edit['path[0][alias]'] = '/alias' .
|
||||
// "Special" ASCII characters.
|
||||
"- ._~!$'\"()*@[]?&+%#,;=:" .
|
||||
// Characters that look like a percent-escaped string.
|
||||
|
@ -264,7 +266,7 @@ class PathAliasTest extends PathTestBase {
|
|||
$this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Confirm that the alias works.
|
||||
$this->drupalGet(Unicode::strtoupper($edit['path[0][alias]']));
|
||||
$this->drupalGet(mb_strtoupper($edit['path[0][alias]']));
|
||||
$this->assertText($node1->label(), 'Changed alias works.');
|
||||
$this->assertResponse(200);
|
||||
|
||||
|
@ -326,6 +328,34 @@ class PathAliasTest extends PathTestBase {
|
|||
$node5->delete();
|
||||
$path_alias = \Drupal::service('path.alias_storage')->lookupPathAlias('/node/' . $node5->id(), $node5->language()->getId());
|
||||
$this->assertFalse($path_alias, 'Alias was successfully deleted when the referenced node was deleted.');
|
||||
|
||||
// Create sixth test node.
|
||||
$node6 = $this->drupalCreateNode();
|
||||
|
||||
// Create an invalid alias with two leading slashes and verify that the
|
||||
// extra slash is removed when the link is generated. This ensures that URL
|
||||
// aliases cannot be used to inject external URLs.
|
||||
// @todo The user interface should either display an error message or
|
||||
// automatically trim these invalid aliases, rather than allowing them to
|
||||
// be silently created, at which point the functional aspects of this
|
||||
// test will need to be moved elsewhere and switch to using a
|
||||
// programmatically-created alias instead.
|
||||
$alias = $this->randomMachineName(8);
|
||||
$edit = ['path[0][alias]' => '//' . $alias];
|
||||
$this->drupalPostForm($node6->toUrl('edit-form'), $edit, t('Save'));
|
||||
$this->drupalGet(Url::fromRoute('system.admin_content'));
|
||||
// This checks the link href before clicking it, rather than using
|
||||
// \Drupal\Tests\BrowserTestBase::assertSession()->addressEquals() after
|
||||
// clicking it, because the test browser does not always preserve the
|
||||
// correct number of slashes in the URL when it visits internal links;
|
||||
// using \Drupal\Tests\BrowserTestBase::assertSession()->addressEquals()
|
||||
// would actually make the test pass unconditionally on the testbot (or
|
||||
// anywhere else where Drupal is installed in a subdirectory).
|
||||
$link_xpath = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $node6->getTitle()]);
|
||||
$link_href = $link_xpath[0]->getAttribute('href');
|
||||
$this->assertEquals($link_href, base_path() . $alias);
|
||||
$this->clickLink($node6->getTitle());
|
||||
$this->assertResponse(404);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\path\Functional;
|
||||
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
|
||||
|
||||
/**
|
||||
* Tests path aliases with Content Moderation.
|
||||
*
|
||||
* @group content_moderation
|
||||
* @group path
|
||||
*/
|
||||
class PathContentModerationTest extends BrowserTestBase {
|
||||
|
||||
use ContentModerationTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'path', 'content_moderation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Created a content type.
|
||||
$node_type = NodeType::create(['name' => 'moderated', 'type' => 'moderated']);
|
||||
$node_type->save();
|
||||
|
||||
// Set the content type as moderated.
|
||||
$workflow = $this->createEditorialWorkflow();
|
||||
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
|
||||
$workflow->save();
|
||||
|
||||
$this->drupalLogin($this->rootUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests node path aliases on a moderated content type.
|
||||
*/
|
||||
public function testNodePathAlias() {
|
||||
// Create some moderated content with a path alias.
|
||||
$this->drupalGet('node/add/moderated');
|
||||
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
|
||||
$this->drupalPostForm(NULL, [
|
||||
'title[0][value]' => 'moderated content',
|
||||
'path[0][alias]' => '/moderated-content',
|
||||
'moderation_state[0][state]' => 'published',
|
||||
], t('Save'));
|
||||
$node = $this->getNodeByTitle('moderated content');
|
||||
|
||||
// Add a pending revision with the same alias.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->assertSession()->fieldValueEquals('path[0][alias]', '/moderated-content');
|
||||
$this->drupalPostForm(NULL, [
|
||||
'title[0][value]' => 'pending revision',
|
||||
'path[0][alias]' => '/moderated-content',
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
], t('Save'));
|
||||
$this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
|
||||
|
||||
// Create some moderated content with no path alias.
|
||||
$this->drupalGet('node/add/moderated');
|
||||
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
|
||||
$this->drupalPostForm(NULL, [
|
||||
'title[0][value]' => 'moderated content 2',
|
||||
'path[0][alias]' => '',
|
||||
'moderation_state[0][state]' => 'published',
|
||||
], t('Save'));
|
||||
$node = $this->getNodeByTitle('moderated content 2');
|
||||
|
||||
// Add a pending revision with a new alias.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
|
||||
$this->drupalPostForm(NULL, [
|
||||
'title[0][value]' => 'pending revision',
|
||||
'path[0][alias]' => '/pending-revision',
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
], t('Save'));
|
||||
$this->assertSession()->pageTextContains('You can only change the URL alias for the published version of this content.');
|
||||
|
||||
// Create some moderated content with no path alias.
|
||||
$this->drupalGet('node/add/moderated');
|
||||
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
|
||||
$this->drupalPostForm(NULL, [
|
||||
'title[0][value]' => 'moderated content 3',
|
||||
'path[0][alias]' => '',
|
||||
'moderation_state[0][state]' => 'published',
|
||||
], t('Save'));
|
||||
$node = $this->getNodeByTitle('moderated content 3');
|
||||
|
||||
// Add a pending revision with no path alias.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->assertSession()->fieldValueEquals('path[0][alias]', '');
|
||||
$this->drupalPostForm(NULL, [
|
||||
'title[0][value]' => 'pending revision',
|
||||
'path[0][alias]' => '',
|
||||
'moderation_state[0][state]' => 'draft',
|
||||
], t('Save'));
|
||||
$this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\path\Functional;
|
||||
|
||||
use Drupal\media\Entity\MediaType;
|
||||
|
||||
/**
|
||||
* Tests the path media form UI.
|
||||
*
|
||||
* @group path
|
||||
*/
|
||||
class PathMediaFormTest extends PathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['media', 'media_test_source'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create test user and log in.
|
||||
$web_user = $this->drupalCreateUser(['create media', 'create url aliases']);
|
||||
$this->drupalLogin($web_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the media form UI.
|
||||
*/
|
||||
public function testMediaForm() {
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
// Create media type.
|
||||
$media_type_id = 'foo';
|
||||
$media_type = MediaType::create([
|
||||
'id' => $media_type_id,
|
||||
'label' => $media_type_id,
|
||||
'source' => 'test',
|
||||
'source_configuration' => [],
|
||||
'field_map' => [],
|
||||
'new_revision' => FALSE,
|
||||
]);
|
||||
$media_type->save();
|
||||
|
||||
$this->drupalGet('media/add/' . $media_type_id);
|
||||
|
||||
// Make sure we have a vertical tab fieldset and 'Path' field.
|
||||
$assert_session->elementContains('css', '.form-type-vertical-tabs #edit-path-0 summary', 'URL alias');
|
||||
$assert_session->fieldExists('path[0][alias]');
|
||||
|
||||
// Disable the 'Path' field for this content type.
|
||||
entity_get_form_display('media', $media_type_id, 'default')
|
||||
->removeComponent('path')
|
||||
->save();
|
||||
|
||||
$this->drupalGet('media/add/' . $media_type_id);
|
||||
|
||||
// See if the whole fieldset is gone now.
|
||||
$assert_session->elementNotExists('css', '.form-type-vertical-tabs #edit-path-0');
|
||||
$assert_session->fieldNotExists('path[0][alias]');
|
||||
}
|
||||
|
||||
}
|
|
@ -28,13 +28,15 @@ class PathNodeFormTest extends PathTestBase {
|
|||
* Tests the node form ui.
|
||||
*/
|
||||
public function testNodeForm() {
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
// Make sure we have a Path fieldset and Path fields.
|
||||
$this->assertRaw(' id="edit-path-settings"', 'Path settings details exists');
|
||||
$this->assertFieldByName('path[0][alias]', NULL, 'Path alias field exists');
|
||||
// Make sure we have a vertical tab fieldset and 'Path' fields.
|
||||
$assert_session->elementContains('css', '.form-type-vertical-tabs #edit-path-0 summary', 'URL alias');
|
||||
$assert_session->fieldExists('path[0][alias]');
|
||||
|
||||
// Disable the Path field for this content type.
|
||||
// Disable the 'Path' field for this content type.
|
||||
entity_get_form_display('node', 'page', 'default')
|
||||
->removeComponent('path')
|
||||
->save();
|
||||
|
@ -42,8 +44,8 @@ class PathNodeFormTest extends PathTestBase {
|
|||
$this->drupalGet('node/add/page');
|
||||
|
||||
// See if the whole fieldset is gone now.
|
||||
$this->assertNoRaw(' id="edit-path-settings"', 'Path settings details does not exist');
|
||||
$this->assertNoFieldByName('path[0][alias]', NULL, 'Path alias field does not exist');
|
||||
$assert_session->elementNotExists('css', '.form-type-vertical-tabs #edit-path-0');
|
||||
$assert_session->fieldNotExists('path[0][alias]');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,14 @@ class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language', 'content_translation', 'path', 'menu_ui'];
|
||||
public static $modules = [
|
||||
'language',
|
||||
'content_translation',
|
||||
'path',
|
||||
'menu_ui',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -68,7 +75,7 @@ class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
|
|||
];
|
||||
$path = \Drupal::service('path.alias_storage')->load($conditions);
|
||||
$this->assertPath('1', $conditions, $path);
|
||||
$this->assertIdentical($id_map->lookupDestinationID([$path['pid']]), ['1'], "Test IdMap");
|
||||
$this->assertIdentical($id_map->lookupDestinationId([$path['pid']]), ['1'], "Test IdMap");
|
||||
|
||||
$conditions = [
|
||||
'source' => '/node/2',
|
||||
|
@ -103,6 +110,14 @@ class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
|
|||
];
|
||||
$path = \Drupal::service('path.alias_storage')->load($conditions);
|
||||
$this->assertPath('3', $conditions, $path);
|
||||
|
||||
$path = \Drupal::service('path.alias_storage')->load(['alias' => '/source-noslash']);
|
||||
$conditions = [
|
||||
'source' => '/admin',
|
||||
'alias' => '/source-noslash',
|
||||
'langcode' => 'und',
|
||||
];
|
||||
$this->assertPath('2', $conditions, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,8 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
|
|||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'path',
|
||||
'text',
|
||||
|
@ -48,7 +50,9 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
|
|||
* Test the URL alias migration.
|
||||
*/
|
||||
public function testUrlAlias() {
|
||||
$path = \Drupal::service('path.alias_storage')->load([
|
||||
$alias_storage = $this->container->get('path.alias_storage');
|
||||
|
||||
$path = $alias_storage->load([
|
||||
'source' => '/taxonomy/term/4',
|
||||
'alias' => '/term33',
|
||||
'langcode' => 'und',
|
||||
|
@ -56,6 +60,11 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
|
|||
$this->assertIdentical('/taxonomy/term/4', $path['source']);
|
||||
$this->assertIdentical('/term33', $path['alias']);
|
||||
$this->assertIdentical('und', $path['langcode']);
|
||||
|
||||
// Alias with no slash.
|
||||
$path = $alias_storage->load(['alias' => '/source-noslash']);
|
||||
$this->assertSame('/admin', $path['source']);
|
||||
$this->assertSame('und', $path['langcode']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
206
web/core/modules/path/tests/src/Kernel/PathItemTest.php
Normal file
206
web/core/modules/path/tests/src/Kernel/PathItemTest.php
Normal file
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\path\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Tests loading and storing data using PathItem.
|
||||
*
|
||||
* @group path
|
||||
*/
|
||||
class PathItemTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['path', 'node', 'user', 'system', 'language', 'content_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
$this->installSchema('node', ['node_access']);
|
||||
|
||||
$node_type = NodeType::create(['type' => 'foo']);
|
||||
$node_type->save();
|
||||
|
||||
$this->installConfig(['language']);
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating, loading, updating and deleting aliases through PathItem.
|
||||
*/
|
||||
public function testPathItem() {
|
||||
|
||||
/** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */
|
||||
$alias_storage = \Drupal::service('path.alias_storage');
|
||||
|
||||
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
|
||||
$node = Node::create([
|
||||
'title' => 'Testing create()',
|
||||
'type' => 'foo',
|
||||
'path' => ['alias' => '/foo'],
|
||||
]);
|
||||
$this->assertFalse($node->get('path')->isEmpty());
|
||||
$this->assertEquals('/foo', $node->get('path')->alias);
|
||||
|
||||
$node->save();
|
||||
$this->assertFalse($node->get('path')->isEmpty());
|
||||
$this->assertEquals('/foo', $node->get('path')->alias);
|
||||
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
|
||||
$this->assertEquals('/foo', $stored_alias);
|
||||
|
||||
$node_storage->resetCache();
|
||||
|
||||
/** @var \Drupal\node\NodeInterface $loaded_node */
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/foo', $loaded_node->get('path')->alias);
|
||||
$node_storage->resetCache();
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$this->assertEquals('/foo', $loaded_node->get('path')[0]->get('alias')->getValue());
|
||||
|
||||
$node_storage->resetCache();
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$values = $loaded_node->get('path')->getValue();
|
||||
$this->assertEquals('/foo', $values[0]['alias']);
|
||||
|
||||
$node_storage->resetCache();
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$this->assertEquals('/foo', $loaded_node->path->alias);
|
||||
|
||||
// Add a translation, verify it is being saved as expected.
|
||||
$translation = $loaded_node->addTranslation('de', $loaded_node->toArray());
|
||||
$translation->get('path')->alias = '/furchtbar';
|
||||
$translation->save();
|
||||
|
||||
// Assert the alias on the English node, the German translation, and the
|
||||
// stored aliases.
|
||||
$node_storage->resetCache();
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$this->assertEquals('/foo', $loaded_node->path->alias);
|
||||
$translation = $loaded_node->getTranslation('de');
|
||||
$this->assertEquals('/furchtbar', $translation->path->alias);
|
||||
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
|
||||
$this->assertEquals('/foo', $stored_alias);
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $translation->language()->getId());
|
||||
$this->assertEquals('/furchtbar', $stored_alias);
|
||||
|
||||
$loaded_node->get('path')->alias = '/bar';
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
|
||||
|
||||
$loaded_node->save();
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
|
||||
|
||||
$node_storage->resetCache();
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
|
||||
|
||||
$loaded_node->get('path')->alias = '/bar';
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
|
||||
|
||||
$loaded_node->save();
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/bar', $loaded_node->get('path')->alias);
|
||||
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
|
||||
$this->assertEquals('/bar', $stored_alias);
|
||||
|
||||
$old_alias = $alias_storage->lookupPathSource('/foo', $node->language()->getId());
|
||||
$this->assertFalse($old_alias);
|
||||
|
||||
// Reload the node to make sure that it is possible to set a value
|
||||
// immediately after loading.
|
||||
$node_storage->resetCache();
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$loaded_node->get('path')->alias = '/foobar';
|
||||
$loaded_node->save();
|
||||
|
||||
$node_storage->resetCache();
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/foobar', $loaded_node->get('path')->alias);
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
|
||||
$this->assertEquals('/foobar', $stored_alias);
|
||||
|
||||
$old_alias = $alias_storage->lookupPathSource('/bar', $node->language()->getId());
|
||||
$this->assertFalse($old_alias);
|
||||
|
||||
$loaded_node->get('path')->alias = '';
|
||||
$this->assertEquals('', $loaded_node->get('path')->alias);
|
||||
|
||||
$loaded_node->save();
|
||||
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
|
||||
$this->assertFalse($stored_alias);
|
||||
|
||||
// Check that reading, updating and reading the computed alias again in the
|
||||
// same request works without clearing any caches in between.
|
||||
$loaded_node = $node_storage->load($node->id());
|
||||
$loaded_node->get('path')->alias = '/foo';
|
||||
$loaded_node->save();
|
||||
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/foo', $loaded_node->get('path')->alias);
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
|
||||
$this->assertEquals('/foo', $stored_alias);
|
||||
|
||||
$loaded_node->get('path')->alias = '/foobar';
|
||||
$loaded_node->save();
|
||||
|
||||
$this->assertFalse($loaded_node->get('path')->isEmpty());
|
||||
$this->assertEquals('/foobar', $loaded_node->get('path')->alias);
|
||||
$stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId());
|
||||
$this->assertEquals('/foobar', $stored_alias);
|
||||
|
||||
// Check that \Drupal\Core\Field\FieldItemList::equals() for the path field
|
||||
// type.
|
||||
$node = Node::create([
|
||||
'title' => $this->randomString(),
|
||||
'type' => 'foo',
|
||||
'path' => ['alias' => '/foo'],
|
||||
]);
|
||||
$second_node = Node::create([
|
||||
'title' => $this->randomString(),
|
||||
'type' => 'foo',
|
||||
'path' => ['alias' => '/foo'],
|
||||
]);
|
||||
$this->assertTrue($node->get('path')->equals($second_node->get('path')));
|
||||
|
||||
// Change the alias for the second node to a different one and try again.
|
||||
$second_node->get('path')->alias = '/foobar';
|
||||
$this->assertFalse($node->get('path')->equals($second_node->get('path')));
|
||||
|
||||
// Test the generateSampleValue() method.
|
||||
$node = Node::create([
|
||||
'title' => $this->randomString(),
|
||||
'type' => 'foo',
|
||||
'path' => ['alias' => '/foo'],
|
||||
]);
|
||||
$node->save();
|
||||
$path_field = $node->get('path');
|
||||
$path_field->generateSampleItems();
|
||||
$node->save();
|
||||
$this->assertStringStartsWith('/', $node->get('path')->alias);
|
||||
}
|
||||
|
||||
}
|
|
@ -42,7 +42,7 @@ class PathNoCanonicalLinkTest extends KernelTestBase {
|
|||
public function testNoCanonicalLinkTemplate() {
|
||||
$entity_type = EntityTestTranslatableUISkip::create([
|
||||
'name' => 'name english',
|
||||
'language' => 'en'
|
||||
'language' => 'en',
|
||||
]);
|
||||
$entity_type->save();
|
||||
|
||||
|
|
Reference in a new issue