7
7
8
8
use Magento \Catalog \Helper \Data ;
9
9
use Magento \Framework \App \Config \ScopeConfigInterface ;
10
+ use Magento \Framework \App \ObjectManager ;
10
11
use Magento \Framework \DataObject ;
12
+ use Magento \Framework \Escaper ;
13
+ use Magento \Framework \Serialize \Serializer \Json ;
11
14
use Magento \Framework \View \Element \Block \ArgumentInterface ;
12
15
13
16
/**
@@ -27,18 +30,33 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
27
30
*/
28
31
private $ scopeConfig ;
29
32
33
+ /**
34
+ * @var Json
35
+ */
36
+ private $ json ;
37
+ /**
38
+ * @var Escaper
39
+ */
40
+ private $ escaper ;
41
+
30
42
/**
31
43
* @param Data $catalogData
32
44
* @param ScopeConfigInterface $scopeConfig
45
+ * @param Json $json
46
+ * @param Escaper $escaper
33
47
*/
34
48
public function __construct (
35
49
Data $ catalogData ,
36
- ScopeConfigInterface $ scopeConfig
50
+ ScopeConfigInterface $ scopeConfig ,
51
+ Json $ json = null ,
52
+ Escaper $ escaper = null
37
53
) {
38
54
parent ::__construct ();
39
55
40
56
$ this ->catalogData = $ catalogData ;
41
57
$ this ->scopeConfig = $ scopeConfig ;
58
+ $ this ->json = $ json ?: ObjectManager::getInstance ()->get (Json::class);
59
+ $ this ->escaper = $ escaper ?: ObjectManager::getInstance ()->get (Escaper::class);
42
60
}
43
61
44
62
/**
@@ -78,4 +96,20 @@ public function getProductName()
78
96
? $ this ->catalogData ->getProduct ()->getName ()
79
97
: '' ;
80
98
}
99
+
100
+ /**
101
+ * Returns breadcrumb json.
102
+ *
103
+ * @return string
104
+ */
105
+ public function getJsonConfiguration ()
106
+ {
107
+ return $ this ->escaper ->escapeHtml ($ this ->json ->serialize ([
108
+ 'breadcrumbs ' => [
109
+ 'categoryUrlSuffix ' => $ this ->escaper ->escapeHtml ($ this ->getCategoryUrlSuffix ()),
110
+ 'userCategoryPathInUrl ' => (int )$ this ->isCategoryUsedInProductUrl (),
111
+ 'product ' => $ this ->getProductName ()
112
+ ]
113
+ ]));
114
+ }
81
115
}
0 commit comments