@@ -25,7 +25,7 @@ class BlockFactory
2525 *
2626 * @var \Magento\Framework\ObjectManager\ConfigInterface
2727 */
28- protected $ config ;
28+ private $ config ;
2929
3030 /**
3131 * Constructor
@@ -51,16 +51,9 @@ public function __construct(
5151 */
5252 public function createBlock ($ blockName , array $ arguments = [])
5353 {
54- $ blockName = ltrim ($ blockName , '\\' );
55- $ configArguments = $ this ->config ->getArguments ($ blockName );
56- if ($ configArguments != null && isset ($ configArguments ['data ' ])) {
57- if ($ arguments != null && isset ($ arguments ['data ' ])) {
58- $ arguments ['data ' ] = array_merge ($ arguments ['data ' ], $ configArguments ['data ' ]);
59- } else {
60- $ arguments ['data ' ] = $ configArguments ['data ' ];
61- }
62- }
63- $ block = $ this ->objectManager ->create ($ blockName , $ arguments );
54+ $ blockName = ltrim ($ blockName , '\\' );
55+ $ arguments = $ this ->getConfigArguments ($ blockName , $ arguments );
56+ $ block = $ this ->objectManager ->create ($ blockName , $ arguments );
6457 if (!$ block instanceof BlockInterface) {
6558 throw new \LogicException ($ blockName . ' does not implement BlockInterface ' );
6659 }
@@ -69,4 +62,24 @@ public function createBlock($blockName, array $arguments = [])
6962 }
7063 return $ block ;
7164 }
65+
66+ /**
67+ * Get All Config Arguments based on Block Name
68+ *
69+ * @param string $blockName
70+ * @param array $arguments
71+ * @return array $arguments
72+ */
73+ private function getConfigArguments ($ blockName , array $ arguments = [])
74+ {
75+ $ configArguments = $ this ->config ->getArguments ($ blockName );
76+ if ($ configArguments && isset ($ configArguments ['data ' ])) {
77+ if ($ arguments && isset ($ arguments ['data ' ])) {
78+ $ arguments ['data ' ] = array_merge ($ arguments ['data ' ], $ configArguments ['data ' ]);
79+ } else {
80+ $ arguments ['data ' ] = $ configArguments ['data ' ];
81+ }
82+ }
83+ return $ arguments ;
84+ }
7285}
0 commit comments