Skip to content

Commit f943d88

Browse files
author
Mohan Ahuja
committed
ACP2E-345: Unable to save product URL key with a hyphen "-" at end.
- Added tooltip for message and link to follow for more info. - Updated validation to just validate trailing hyphen in the URL key.
1 parent 7d77259 commit f943d88

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

app/code/Magento/Catalog/Setup/Patch/Data/UpdateProductUrlKey.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public function apply()
5252
\Magento\Catalog\Model\Product::ENTITY,
5353
'url_key',
5454
[
55-
'note' => 'The URL key should consist of lowercase characters with hyphens to separate words',
56-
'frontend_class' => 'validate-identifier-clean'
55+
'frontend_class' => 'validate-trailing-hyphen'
5756
]
5857
);
5958
return $this;

app/code/Magento/Catalog/Ui/DataProvider/CatalogEavValidationRules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function mapRules($class, array $rules)
7070
case 'validate-digits':
7171
case 'validate-email':
7272
case 'validate-url':
73-
case 'validate-identifier-clean':
73+
case 'validate-trailing-hyphen':
7474
case 'validate-alpha':
7575
case 'validate-alphanum':
7676
$rules = array_merge($rules, [$class => true]);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public function modifyMeta(array $meta)
150150
$meta = $this->customizeWeightField($meta);
151151
$meta = $this->customizeNewDateRangeField($meta);
152152
$meta = $this->customizeNameListeners($meta);
153+
$meta = $this->customizeUrlKeyField($meta);
153154

154155
return $meta;
155156
}
@@ -399,6 +400,31 @@ protected function customizeNameListeners(array $meta)
399400
);
400401
}
401402

403+
/**
404+
* Customize URL KEY field
405+
*
406+
* @param array $meta
407+
* @return array
408+
* @since 101.0.0
409+
*/
410+
protected function customizeUrlKeyField(array $meta): array
411+
{
412+
$tooltip = [
413+
'link' => 'https://docs.magento.com/user-guide/catalog/catalog-urls.html',
414+
'description' => __(
415+
'The URL key should consist of lowercase characters with hyphens to separate words.'
416+
),
417+
];
418+
$switcherConfig = [
419+
'tooltip' => $tooltip,
420+
];
421+
422+
$path = $this->arrayManager->findPath(ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY, $meta, null, 'children');
423+
$meta = $this->arrayManager->merge($path . static::META_CONFIG_PATH, $meta, $switcherConfig);
424+
425+
return $meta;
426+
}
427+
402428
/**
403429
* The getter function to get the locale currency for real application code
404430
*

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,9 @@ define([
817817
},
818818
$.mage.__('Please enter a valid URL Key (Ex: "example-page", "example-page.html" or "anotherlevel/example-page").')//eslint-disable-line max-len
819819
],
820-
'validate-identifier-clean': [
820+
'validate-trailing-hyphen': [
821821
function (value) {
822-
return utils.isEmptyNoTrim(value) || /^[a-z0-9]+(-[a-z0-9]+)*$/.test(value);
822+
return utils.isEmptyNoTrim(value) || /^(?!-)(?!.*-$).+$/.test(value);
823823
},
824824
$.mage.__('Please enter a valid URL Key (Ex: example-page).')
825825
],

0 commit comments

Comments
 (0)