@@ -48,22 +48,31 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
48
48
*/
49
49
private $ categoryRepository ;
50
50
51
+ /**
52
+ * @var \Magento\Backend\App\Area\FrontNameResolver
53
+ */
54
+ private $ frontNameResolver ;
55
+
51
56
/**
52
57
* @param CategoryUrlPathGenerator $categoryUrlPathGenerator
53
58
* @param ChildrenCategoriesProvider $childrenCategoriesProvider
54
59
* @param \Magento\CatalogUrlRewrite\Service\V1\StoreViewService $storeViewService
55
60
* @param CategoryRepositoryInterface $categoryRepository
61
+ * @param \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver
56
62
*/
57
63
public function __construct (
58
64
CategoryUrlPathGenerator $ categoryUrlPathGenerator ,
59
65
ChildrenCategoriesProvider $ childrenCategoriesProvider ,
60
66
StoreViewService $ storeViewService ,
61
- CategoryRepositoryInterface $ categoryRepository
67
+ CategoryRepositoryInterface $ categoryRepository ,
68
+ \Magento \Backend \App \Area \FrontNameResolver $ frontNameResolver = null
62
69
) {
63
70
$ this ->categoryUrlPathGenerator = $ categoryUrlPathGenerator ;
64
71
$ this ->childrenCategoriesProvider = $ childrenCategoriesProvider ;
65
72
$ this ->storeViewService = $ storeViewService ;
66
73
$ this ->categoryRepository = $ categoryRepository ;
74
+ $ this ->frontNameResolver = $ frontNameResolver ?: \Magento \Framework \App \ObjectManager::getInstance ()
75
+ ->get (\Magento \Backend \App \Area \FrontNameResolver::class);
67
76
}
68
77
69
78
/**
@@ -102,12 +111,12 @@ private function updateUrlKey($category, $urlKey)
102
111
throw new \Magento \Framework \Exception \LocalizedException (__ ('Invalid URL key ' ));
103
112
}
104
113
105
- if (in_array ($ urlKey , $ this ->invalidValues )) {
114
+ if (in_array ($ urlKey , $ this ->getInvalidValues () )) {
106
115
throw new \Magento \Framework \Exception \LocalizedException (
107
116
__ (
108
117
'URL key "%1" conflicts with reserved endpoint names: %2. Try another url key. ' ,
109
118
$ urlKey ,
110
- implode (', ' , $ this ->invalidValues )
119
+ implode (', ' , $ this ->getInvalidValues () )
111
120
)
112
121
);
113
122
}
@@ -122,6 +131,16 @@ private function updateUrlKey($category, $urlKey)
122
131
}
123
132
}
124
133
134
+ /**
135
+ * Get reserved endpoint names.
136
+ *
137
+ * @return array
138
+ */
139
+ private function getInvalidValues ()
140
+ {
141
+ return array_unique (array_merge ($ this ->invalidValues , [$ this ->frontNameResolver ->getFrontName ()]));
142
+ }
143
+
125
144
/**
126
145
* Update url path for children category.
127
146
*
0 commit comments