updated core and modules
This commit is contained in:
@@ -69,63 +69,63 @@ class PathController extends ControllerBase {
|
||||
// alias with a language.
|
||||
$multilanguage = ($this->moduleHandler()->moduleExists('language') || $this->aliasStorage->languageAliasExists());
|
||||
|
||||
$header = array();
|
||||
$header[] = array('data' => $this->t('Alias'), 'field' => 'alias', 'sort' => 'asc');
|
||||
$header[] = array('data' => $this->t('System'), 'field' => 'source');
|
||||
$header = [];
|
||||
$header[] = ['data' => $this->t('Alias'), 'field' => 'alias', 'sort' => 'asc'];
|
||||
$header[] = ['data' => $this->t('System'), 'field' => 'source'];
|
||||
if ($multilanguage) {
|
||||
$header[] = array('data' => $this->t('Language'), 'field' => 'langcode');
|
||||
$header[] = ['data' => $this->t('Language'), 'field' => 'langcode'];
|
||||
}
|
||||
$header[] = $this->t('Operations');
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
$destination = $this->getDestinationArray();
|
||||
foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
|
||||
$row = array();
|
||||
$row = [];
|
||||
// @todo Should Path module store leading slashes? See
|
||||
// https://www.drupal.org/node/2430593.
|
||||
$row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUserInput($data->source, array(
|
||||
'attributes' => array('title' => $data->alias),
|
||||
)));
|
||||
$row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUserInput($data->source, array(
|
||||
$row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUserInput($data->source, [
|
||||
'attributes' => ['title' => $data->alias],
|
||||
]));
|
||||
$row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUserInput($data->source, [
|
||||
'alias' => TRUE,
|
||||
'attributes' => array('title' => $data->source),
|
||||
)));
|
||||
'attributes' => ['title' => $data->source],
|
||||
]));
|
||||
if ($multilanguage) {
|
||||
$row['data']['language_name'] = $this->languageManager()->getLanguageName($data->langcode);
|
||||
}
|
||||
|
||||
$operations = array();
|
||||
$operations['edit'] = array(
|
||||
$operations = [];
|
||||
$operations['edit'] = [
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => Url::fromRoute('path.admin_edit', ['pid' => $data->pid], ['query' => $destination]),
|
||||
);
|
||||
$operations['delete'] = array(
|
||||
];
|
||||
$operations['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('path.delete', ['pid' => $data->pid], ['query' => $destination]),
|
||||
);
|
||||
$row['data']['operations'] = array(
|
||||
'data' => array(
|
||||
];
|
||||
$row['data']['operations'] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $operations,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// If the system path maps to a different URL alias, highlight this table
|
||||
// row to let the user know of old aliases.
|
||||
if ($data->alias != $this->aliasManager->getAliasByPath($data->source, $data->langcode)) {
|
||||
$row['class'] = array('warning');
|
||||
$row['class'] = ['warning'];
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$build['path_table'] = array(
|
||||
$build['path_table'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => $this->t('No URL aliases available. <a href=":link">Add URL alias</a>.', array(':link' => $this->url('path.admin_add'))),
|
||||
);
|
||||
$build['path_pager'] = array('#type' => 'pager');
|
||||
'#empty' => $this->t('No URL aliases available. <a href=":link">Add URL alias</a>.', [':link' => $this->url('path.admin_add')]),
|
||||
];
|
||||
$build['path_pager'] = ['#type' => 'pager'];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ class AddForm extends PathFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildPath($pid) {
|
||||
return array(
|
||||
return [
|
||||
'source' => '',
|
||||
'alias' => '',
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
'pid' => NULL,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class DeleteForm extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return t('Are you sure you want to delete path alias %title?', array('%title' => $this->pathAlias['alias']));
|
||||
return t('Are you sure you want to delete path alias %title?', ['%title' => $this->pathAlias['alias']]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ class DeleteForm extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
|
||||
$this->pathAlias = $this->aliasStorage->load(array('pid' => $pid));
|
||||
$this->pathAlias = $this->aliasStorage->load(['pid' => $pid]);
|
||||
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
@@ -82,7 +82,7 @@ class DeleteForm extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->aliasStorage->delete(array('pid' => $this->pathAlias['pid']));
|
||||
$this->aliasStorage->delete(['pid' => $this->pathAlias['pid']]);
|
||||
|
||||
$form_state->setRedirect('path.admin_overview');
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class EditForm extends PathFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildPath($pid) {
|
||||
return $this->aliasStorage->load(array('pid' => $pid));
|
||||
return $this->aliasStorage->load(['pid' => $pid]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,27 +31,27 @@ class EditForm extends PathFormBase {
|
||||
$form = parent::buildForm($form, $form_state, $pid);
|
||||
|
||||
$form['#title'] = $this->path['alias'];
|
||||
$form['pid'] = array(
|
||||
$form['pid'] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $this->path['pid'],
|
||||
);
|
||||
];
|
||||
|
||||
$url = new Url('path.delete', array(
|
||||
$url = new Url('path.delete', [
|
||||
'pid' => $this->path['pid'],
|
||||
));
|
||||
]);
|
||||
|
||||
if ($this->getRequest()->query->has('destination')) {
|
||||
$url->setOption('query', $this->getDestinationArray());
|
||||
}
|
||||
|
||||
$form['actions']['delete'] = array(
|
||||
$form['actions']['delete'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Delete'),
|
||||
'#url' => $url,
|
||||
'#attributes' => array(
|
||||
'class' => array('button', 'button--danger'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['button', 'button--danger'],
|
||||
],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -21,32 +21,31 @@ class PathFilterForm extends FormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $keys = NULL) {
|
||||
$form['#attributes'] = array('class' => array('search-form'));
|
||||
$form['basic'] = array(
|
||||
$form['#attributes'] = ['class' => ['search-form']];
|
||||
$form['basic'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Filter aliases'),
|
||||
'#open' => TRUE,
|
||||
'#attributes' => array('class' => array('container-inline')),
|
||||
);
|
||||
$form['basic']['filter'] = array(
|
||||
'#attributes' => ['class' => ['container-inline']],
|
||||
];
|
||||
$form['basic']['filter'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => 'Path alias',
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $keys,
|
||||
'#maxlength' => 128,
|
||||
'#size' => 25,
|
||||
);
|
||||
$form['basic']['submit'] = array(
|
||||
];
|
||||
$form['basic']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#button_type' => 'primary',
|
||||
'#value' => $this->t('Filter'),
|
||||
);
|
||||
];
|
||||
if ($keys) {
|
||||
$form['basic']['reset'] = array(
|
||||
$form['basic']['reset'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Reset'),
|
||||
'#submit' => array('::resetForm'),
|
||||
);
|
||||
'#submit' => ['::resetForm'],
|
||||
];
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
@@ -55,9 +54,9 @@ class PathFilterForm extends FormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$form_state->setRedirect('path.admin_overview_filter', array(), array(
|
||||
'query' => array('search' => trim($form_state->getValue('filter'))),
|
||||
));
|
||||
$form_state->setRedirect('path.admin_overview_filter', [], [
|
||||
'query' => ['search' => trim($form_state->getValue('filter'))],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,7 +95,7 @@ abstract class PathFormBase extends FormBase {
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
|
||||
$this->path = $this->buildPath($pid);
|
||||
$form['source'] = array(
|
||||
$form['source'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Existing system path'),
|
||||
'#default_value' => $this->path['source'],
|
||||
@@ -104,27 +104,27 @@ abstract class PathFormBase extends FormBase {
|
||||
'#description' => $this->t('Specify the existing path you wish to alias. For example: /node/28, /forum/1, /taxonomy/term/1.'),
|
||||
'#field_prefix' => $this->requestContext->getCompleteBaseUrl(),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['alias'] = array(
|
||||
];
|
||||
$form['alias'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Path alias'),
|
||||
'#default_value' => $this->path['alias'],
|
||||
'#maxlength' => 255,
|
||||
'#size' => 45,
|
||||
'#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page. Use a relative path with a slash in front.'),
|
||||
'#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.'),
|
||||
'#field_prefix' => $this->requestContext->getCompleteBaseUrl(),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
// A hidden value unless language.module is enabled.
|
||||
if (\Drupal::moduleHandler()->moduleExists('language')) {
|
||||
$languages = \Drupal::languageManager()->getLanguages();
|
||||
$language_options = array();
|
||||
$language_options = [];
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$language_options[$langcode] = $language->getName();
|
||||
}
|
||||
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Language'),
|
||||
'#options' => $language_options,
|
||||
@@ -133,21 +133,21 @@ abstract class PathFormBase extends FormBase {
|
||||
'#default_value' => $this->path['langcode'],
|
||||
'#weight' => -10,
|
||||
'#description' => $this->t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as <em>- None -</em>.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $this->path['langcode']
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ 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.", array('@link_path' => $source)));
|
||||
$form_state->setErrorByName('source', t("The path '@link_path' is either invalid or you do not have access to it.", ['@link_path' => $source]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,4 +21,17 @@ class PathFieldItemList extends FieldItemList {
|
||||
return AccessResult::allowedIfHasPermissions($account, ['create url aliases', 'administer url aliases'], 'OR')->cachePerPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete() {
|
||||
// Delete all aliases associated with this entity in the current language.
|
||||
$entity = $this->getEntity();
|
||||
$conditions = [
|
||||
'source' => '/' . $entity->toUrl()->getInternalPath(),
|
||||
'langcode' => $entity->language()->getId(),
|
||||
];
|
||||
\Drupal::service('path.alias_storage')->delete($conditions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class PathItem extends FieldItemBase {
|
||||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
|
||||
$properties['alias'] = DataDefinition::create('string')
|
||||
->setLabel(t('Path alias'));
|
||||
$properties['pid'] = DataDefinition::create('string')
|
||||
$properties['pid'] = DataDefinition::create('integer')
|
||||
->setLabel(t('Path id'));
|
||||
return $properties;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class PathItem extends FieldItemBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ class PathItem extends FieldItemBase {
|
||||
else {
|
||||
// Delete old alias if user erased it.
|
||||
if ($this->pid && !$this->alias) {
|
||||
\Drupal::service('path.alias_storage')->delete(array('pid' => $this->pid));
|
||||
\Drupal::service('path.alias_storage')->delete(['pid' => $this->pid]);
|
||||
}
|
||||
// Only save a non-empty alias.
|
||||
elseif ($this->alias) {
|
||||
@@ -72,15 +72,6 @@ class PathItem extends FieldItemBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete() {
|
||||
// Delete all aliases associated with this entity.
|
||||
$entity = $this->getEntity();
|
||||
\Drupal::service('path.alias_storage')->delete(array('source' => '/' . $entity->urlInfo()->getInternalPath()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -26,47 +26,47 @@ class PathWidget extends WidgetBase {
|
||||
*/
|
||||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
|
||||
$entity = $items->getEntity();
|
||||
$path = array();
|
||||
$path = [];
|
||||
if (!$entity->isNew()) {
|
||||
$conditions = array('source' => '/' . $entity->urlInfo()->getInternalPath());
|
||||
$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 = array();
|
||||
$path = [];
|
||||
}
|
||||
}
|
||||
$path += array(
|
||||
$path += [
|
||||
'pid' => NULL,
|
||||
'source' => !$entity->isNew() ? '/' . $entity->urlInfo()->getInternalPath() : NULL,
|
||||
'alias' => '',
|
||||
'langcode' => $items->getLangcode(),
|
||||
);
|
||||
];
|
||||
|
||||
$element += array(
|
||||
'#element_validate' => array(array(get_class($this), 'validateFormElement')),
|
||||
);
|
||||
$element['alias'] = array(
|
||||
$element += [
|
||||
'#element_validate' => [[get_class($this), 'validateFormElement']],
|
||||
];
|
||||
$element['alias'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $element['#title'],
|
||||
'#default_value' => $path['alias'],
|
||||
'#required' => $element['#required'],
|
||||
'#maxlength' => 255,
|
||||
'#description' => $this->t('The alternative URL for this content. Use a relative path. For example, enter "/about" for the about page.'),
|
||||
);
|
||||
$element['pid'] = array(
|
||||
'#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'],
|
||||
);
|
||||
$element['source'] = array(
|
||||
];
|
||||
$element['source'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $path['source'],
|
||||
);
|
||||
$element['langcode'] = array(
|
||||
];
|
||||
$element['langcode'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $path['langcode'],
|
||||
);
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
@@ -87,12 +87,12 @@ class PathWidget extends WidgetBase {
|
||||
// Validate that the submitted alias does not exist yet.
|
||||
$is_exists = \Drupal::service('path.alias_storage')->aliasExists($alias, $element['langcode']['#value'], $element['source']['#value']);
|
||||
if ($is_exists) {
|
||||
$form_state->setError($element, t('The alias is already in use.'));
|
||||
$form_state->setError($element['alias'], t('The alias is already in use.'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($alias && $alias[0] !== '/') {
|
||||
$form_state->setError($element, t('The alias needs to start with a slash.'));
|
||||
$form_state->setError($element['alias'], t('The alias needs to start with a slash.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,16 +58,24 @@ class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterfac
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$source = $row->getDestinationProperty('source');
|
||||
$alias = $row->getDestinationProperty('alias');
|
||||
$langcode = $row->getDestinationProperty('langcode');
|
||||
$pid = $old_destination_id_values ? $old_destination_id_values[0] : NULL;
|
||||
|
||||
$path = $this->aliasStorage->save(
|
||||
$row->getDestinationProperty('source'),
|
||||
$row->getDestinationProperty('alias'),
|
||||
$row->getDestinationProperty('langcode'),
|
||||
$old_destination_id_values ? $old_destination_id_values[0] : NULL
|
||||
);
|
||||
// Check if this alias is for a node and if that node is a translation.
|
||||
if (preg_match('/^\/node\/\d+$/', $source) && $row->hasDestinationProperty('node_translation')) {
|
||||
|
||||
return array($path['pid']);
|
||||
// Replace the alias source with the translation source path.
|
||||
$node_translation = $row->getDestinationProperty('node_translation');
|
||||
$source = '/node/' . $node_translation[0];
|
||||
$langcode = $node_translation[1];
|
||||
}
|
||||
|
||||
$path = $this->aliasStorage->save($source, $alias, $langcode, $pid);
|
||||
|
||||
return [$path['pid']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,17 +13,21 @@ abstract class UrlAliasBase extends DrupalSqlBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('url_alias', 'ua')->fields('ua');
|
||||
// The order of the migration is significant since
|
||||
// \Drupal\Core\Path\AliasStorage::lookupPathAlias() orders by pid before
|
||||
// returning a result. Postgres does not automatically order by primary key
|
||||
// therefore we need to add a specific order by.
|
||||
return $this->select('url_alias', 'ua')->fields('ua')->orderBy('pid');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'pid' => $this->t('The numeric identifier of the path alias.'),
|
||||
'language' => $this->t('The language code of the URL alias.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,9 @@ use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Provides a base class for testing the Path module.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\path\Functional\PathTestBase instead.
|
||||
*/
|
||||
abstract class PathTestBase extends WebTestBase {
|
||||
|
||||
@@ -14,15 +17,15 @@ abstract class PathTestBase extends WebTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'path');
|
||||
public static $modules = ['node', 'path'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create Basic page and Article node types.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user