Skip to content

setting target Module Name when generating a block #1287

@dbsdsun

Description

@dbsdsun

Problem:

  1. One block may template files. The Module Name is used to determine the template file location.
  2. MoudleB_BlockB can extend ModuleA_BlockA by specification in di.xml as following:

In this case, the MoudleB_BlockB should use ModuleA as its module name, rather than MoudleB.

Solution:

Set target module name when generating a block as follwing. And this is last chance to set target module name.
in file lib/internal/Magento/Framework/View/Layout/Generator/Block.php, after line 157, add one line
line155. $block = $this->createBlock($className, $elementName, [
line156. 'data' => $this->evaluateArguments($data['arguments'])
line157. ]);
new line. $block->setModuleName($block->extractModuleName($className));
line158. if (!empty($attributes['template'])) {
line159. $block->setTemplate($attributes['template']);
line160. }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions