1616 */
1717class GlobalSearch extends \Magento \Backend \Block \Template
1818{
19- const ENTITY_TYPE_PRODUCTS = 'Products ' ;
20- const ENTITY_TYPE_ORDERS = 'Orders ' ;
21- const ENTITY_TYPE_CUSTOMERS = 'Customers ' ;
22- const ENTITY_TYPE_PAGES = 'Pages ' ;
23-
24- /**
25- * Affiliation between entity types for global search and corresponding admin resources.
26- *
27- * @var array
28- */
29- private $ entityTypes = [
30- self ::ENTITY_TYPE_PRODUCTS => \Magento \Catalog \Controller \Adminhtml \Product::ADMIN_RESOURCE ,
31- self ::ENTITY_TYPE_ORDERS => \Magento \Sales \Controller \Adminhtml \Order::ADMIN_RESOURCE ,
32- self ::ENTITY_TYPE_CUSTOMERS => \Magento \Customer \Controller \Adminhtml \Index::ADMIN_RESOURCE ,
33- self ::ENTITY_TYPE_PAGES => \Magento \Cms \Controller \Adminhtml \Page \Index::ADMIN_RESOURCE ,
34- ];
35-
3619 /**
3720 * @var SearchEntityFactory
3821 */
@@ -43,19 +26,34 @@ class GlobalSearch extends \Magento\Backend\Block\Template
4326 */
4427 protected $ _template = 'Magento_Backend::system/search.phtml ' ;
4528
29+ /**
30+ * @var array
31+ */
32+ private $ entityResources ;
33+
34+ /**
35+ * @var array
36+ */
37+ private $ entityPaths ;
38+
4639 /**
4740 * @param Template\Context $context
4841 * @param array $data
42+ * @param array $entityResources
43+ * @param array $entityPaths
4944 * @param SearchEntityFactory|null $searchEntityFactory
5045 */
5146 public function __construct (
5247 Template \Context $ context ,
5348 array $ data = [],
49+ array $ entityResources = [],
50+ array $ entityPaths = [],
5451 SearchEntityFactory $ searchEntityFactory = null
5552 ) {
56- $ this ->searchEntityFactory = $ searchEntityFactory ?: ObjectManager::getInstance ()->get (
57- SearchEntityFactory::class
58- );
53+ $ this ->entityResources = $ entityResources ;
54+ $ this ->entityPaths = $ entityPaths ;
55+ $ this ->searchEntityFactory = $ searchEntityFactory ?: ObjectManager::getInstance ()
56+ ->get (SearchEntityFactory::class);
5957
6058 parent ::__construct ($ context , $ data );
6159 }
@@ -89,7 +87,7 @@ public function getEntitiesToShow()
8987 $ allowedEntityTypes = [];
9088 $ entitiesToShow = [];
9189
92- foreach ($ this ->entityTypes as $ entityType => $ resource ) {
90+ foreach ($ this ->entityResources as $ entityType => $ resource ) {
9391 if ($ this ->getAuthorization ()->isAllowed ($ resource )) {
9492 $ allowedEntityTypes [] = $ entityType ;
9593 }
@@ -118,22 +116,7 @@ public function getEntitiesToShow()
118116 */
119117 private function getUrlEntityType (string $ entityType )
120118 {
121- $ urlPath = '' ;
122-
123- switch ($ entityType ) {
124- case self ::ENTITY_TYPE_PRODUCTS :
125- $ urlPath = 'catalog/product/index/ ' ;
126- break ;
127- case self ::ENTITY_TYPE_ORDERS :
128- $ urlPath = 'sales/order/index/ ' ;
129- break ;
130- case self ::ENTITY_TYPE_CUSTOMERS :
131- $ urlPath = 'customer/index/index/ ' ;
132- break ;
133- case self ::ENTITY_TYPE_PAGES :
134- $ urlPath = 'cms/page/index/ ' ;
135- break ;
136- }
119+ $ urlPath = $ this ->entityPaths [$ entityType ] ?? '' ;
137120
138121 return $ this ->getUrl ($ urlPath );
139122 }
0 commit comments