66namespace Magento \Framework \View \Element ;
77
88use Magento \Framework \ObjectManagerInterface ;
9+ use Magento \Framework \ObjectManager \ConfigInterface ;
10+ use Magento \Framework \App \ObjectManager ;
911
1012/**
1113 * Creates Blocks
1618class BlockFactory
1719{
1820 /**
19- * Object manager
20- *
2121 * @var ObjectManagerInterface
2222 */
2323 protected $ objectManager ;
2424
25+ /**
26+ * Object manager config
27+ *
28+ * @var ConfigInterface
29+ */
30+ private $ config ;
31+
2532 /**
2633 * Constructor
2734 *
2835 * @param ObjectManagerInterface $objectManager
36+ * @param ConfigInterface $config
2937 */
30- public function __construct (ObjectManagerInterface $ objectManager )
31- {
38+ public function __construct (
39+ ObjectManagerInterface $ objectManager ,
40+ ?ConfigInterface $ config = null
41+ ) {
3242 $ this ->objectManager = $ objectManager ;
43+ $ this ->config = $ config ?: ObjectManager::getInstance ()->get (ConfigInterface::class);
3344 }
3445
3546 /**
@@ -42,8 +53,9 @@ public function __construct(ObjectManagerInterface $objectManager)
4253 */
4354 public function createBlock ($ blockName , array $ arguments = [])
4455 {
45- $ blockName = ltrim ($ blockName , '\\' );
46- $ block = $ this ->objectManager ->create ($ blockName , $ arguments );
56+ $ blockName = ltrim ($ blockName , '\\' );
57+ $ arguments = $ this ->getConfigArguments ($ blockName , $ arguments );
58+ $ block = $ this ->objectManager ->create ($ blockName , $ arguments );
4759 if (!$ block instanceof BlockInterface) {
4860 throw new \LogicException ($ blockName . ' does not implement BlockInterface ' );
4961 }
@@ -52,4 +64,24 @@ public function createBlock($blockName, array $arguments = [])
5264 }
5365 return $ block ;
5466 }
67+
68+ /**
69+ * Get All Config Arguments based on Block Name
70+ *
71+ * @param string $blockName
72+ * @param array $arguments
73+ * @return array $arguments
74+ */
75+ private function getConfigArguments ($ blockName , array $ arguments = [])
76+ {
77+ if (!$ this ->config ) {
78+ return $ arguments ;
79+ }
80+ $ configArguments = $ this ->config ->getArguments ($ blockName );
81+ if ($ configArguments && isset ($ configArguments ['data ' ])) {
82+ $ arguments ['data ' ] = ($ arguments && isset ($ arguments ['data ' ])) ?
83+ array_merge ($ arguments ['data ' ], $ configArguments ['data ' ]) : $ configArguments ['data ' ];
84+ }
85+ return $ arguments ;
86+ }
5587}
0 commit comments