7
7
8
8
use Magento \Framework \App \State ;
9
9
use Magento \Framework \ObjectManager \Config \Reader \Dom ;
10
+ use Magento \Framework \View \Element \Template ;
10
11
use Magento \Framework \View \Layout ;
11
12
12
13
/**
@@ -60,6 +61,13 @@ class Block implements Layout\GeneratorInterface
60
61
*/
61
62
protected $ exceptionHandlerBlockFactory ;
62
63
64
+ /**
65
+ * Default block class name. Will be used if no class name is specified in block configuration.
66
+ *
67
+ * @var string
68
+ */
69
+ private $ defaultClass ;
70
+
63
71
/**
64
72
* @param \Magento\Framework\View\Element\BlockFactory $blockFactory
65
73
* @param \Magento\Framework\Data\Argument\InterpreterInterface $argumentInterpreter
@@ -69,6 +77,7 @@ class Block implements Layout\GeneratorInterface
69
77
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
70
78
* @param \Magento\Framework\View\Element\ExceptionHandlerBlockFactory $exceptionHandlerBlockFactory
71
79
* @param State $appState
80
+ * @param string $defaultClass
72
81
*/
73
82
public function __construct (
74
83
\Magento \Framework \View \Element \BlockFactory $ blockFactory ,
@@ -78,7 +87,8 @@ public function __construct(
78
87
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
79
88
\Magento \Framework \App \ScopeResolverInterface $ scopeResolver ,
80
89
\Magento \Framework \View \Element \ExceptionHandlerBlockFactory $ exceptionHandlerBlockFactory ,
81
- State $ appState
90
+ State $ appState ,
91
+ $ defaultClass = Template::class
82
92
) {
83
93
$ this ->blockFactory = $ blockFactory ;
84
94
$ this ->argumentInterpreter = $ argumentInterpreter ;
@@ -88,6 +98,7 @@ public function __construct(
88
98
$ this ->scopeResolver = $ scopeResolver ;
89
99
$ this ->exceptionHandlerBlockFactory = $ exceptionHandlerBlockFactory ;
90
100
$ this ->appState = $ appState ;
101
+ $ this ->defaultClass = $ defaultClass ;
91
102
}
92
103
93
104
/**
@@ -210,7 +221,8 @@ protected function generateBlock(
210
221
}
211
222
212
223
// create block
213
- $ className = $ attributes ['class ' ];
224
+ $ className = isset ($ attributes ['class ' ]) && !empty ($ attributes ['class ' ]) ?
225
+ $ attributes ['class ' ] : $ this ->defaultClass ;
214
226
$ block = $ this ->createBlock ($ className , $ elementName , [
215
227
'data ' => $ this ->evaluateArguments ($ data ['arguments ' ])
216
228
]);
0 commit comments