Skip to content

Commit 0cda619

Browse files
committed
AC-1077::Unable to pass data argument by di.xml for block instance
1 parent 9295fe6 commit 0cda619

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

lib/internal/Magento/Framework/View/Element/BlockFactory.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)