Skip to content

Commit

Permalink
Merge pull request #1564 from magento-honey-badgers/MAGETWO-81188
Browse files Browse the repository at this point in the history
[honey badgers] MAGETWO-81188: Make block class not mandatory
  • Loading branch information
cpartica authored Oct 7, 2017
2 parents 0e29169 + 945faf9 commit 9304040
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\View\Layout\Generator\Block">
<arguments>
<argument name="defaultClass" xsi:type="string">Magento\Backend\Block\Template</argument>
</arguments>
</type>
</config>
16 changes: 14 additions & 2 deletions lib/internal/Magento/Framework/View/Layout/Generator/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Framework\App\State;
use Magento\Framework\ObjectManager\Config\Reader\Dom;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Layout;

/**
Expand Down Expand Up @@ -60,6 +61,13 @@ class Block implements Layout\GeneratorInterface
*/
protected $exceptionHandlerBlockFactory;

/**
* Default block class name. Will be used if no class name is specified in block configuration
*
* @var string
*/
private $defaultClass;

/**
* @param \Magento\Framework\View\Element\BlockFactory $blockFactory
* @param \Magento\Framework\Data\Argument\InterpreterInterface $argumentInterpreter
Expand All @@ -69,6 +77,7 @@ class Block implements Layout\GeneratorInterface
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
* @param \Magento\Framework\View\Element\ExceptionHandlerBlockFactory $exceptionHandlerBlockFactory
* @param State $appState
* @param string $defaultClass
*/
public function __construct(
\Magento\Framework\View\Element\BlockFactory $blockFactory,
Expand All @@ -78,7 +87,8 @@ public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\ScopeResolverInterface $scopeResolver,
\Magento\Framework\View\Element\ExceptionHandlerBlockFactory $exceptionHandlerBlockFactory,
State $appState
State $appState,
$defaultClass = Template::class
) {
$this->blockFactory = $blockFactory;
$this->argumentInterpreter = $argumentInterpreter;
Expand All @@ -88,6 +98,7 @@ public function __construct(
$this->scopeResolver = $scopeResolver;
$this->exceptionHandlerBlockFactory = $exceptionHandlerBlockFactory;
$this->appState = $appState;
$this->defaultClass = $defaultClass;
}

/**
Expand Down Expand Up @@ -210,7 +221,8 @@ protected function generateBlock(
}

// create block
$className = $attributes['class'];
$className = isset($attributes['class']) && !empty($attributes['class']) ?
$attributes['class'] : $this->defaultClass ;
$block = $this->createBlock($className, $elementName, [
'data' => $this->evaluateArguments($data['arguments'])
]);
Expand Down

0 comments on commit 9304040

Please sign in to comment.