Skip to content

Commit

Permalink
ENGCOM-1062: [Backport] Can't cancel removal of a block or container …
Browse files Browse the repository at this point in the history
…in layout by setting remove attribute value to false #14198
  • Loading branch information
Stanislav Idolov authored Mar 26, 2018
2 parents a03aa45 + 8eb1ea7 commit b5700ce
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ public function testRemove()
$this->assertTrue($layout->isBlock('child_block2'));
}

/**
* @magentoAppIsolation enabled
*/
public function testRemoveCancellation()
{
$layout = $this->_getLayoutModel('remove_cancellation.xml');
$this->assertTrue($layout->isContainer('container1'));
$this->assertTrue($layout->isBlock('child_block1'));
$this->assertTrue($layout->isBlock('no_name2'));
$this->assertFalse($layout->getBlock('not_exist'));
}

/**
* @magentoAppIsolation enabled
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout>
<container name="container1" label="Container 1">
<block class="Magento\Framework\View\Element\Text" name="no_name2"/>
</container>
<referenceContainer name="container1" remove="true"/>
<referenceBlock name="child_block1" remove="true"/>
<block class="Magento\Framework\View\Element\Text" name="block_container" as="block.container">
<block class="Magento\Framework\View\Element\Text" name="child_block1"/>
<block class="Magento\Framework\View\Element\Text" name="child_block2"/>
</block>
<referenceContainer name="not_exist" remove="false"/>
<referenceContainer name="container1" remove="false"/>
<referenceBlock name="child_block1" remove="false"/>
</layout>
14 changes: 8 additions & 6 deletions lib/internal/Magento/Framework/View/Layout/Reader/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ protected function scheduleReference(
$elementRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);
if ($elementRemove) {
$scheduledStructure->setElementToRemoveList($elementName);
} else {
$data = $scheduledStructure->getStructureElementData($elementName, []);
$data['attributes'] = $this->mergeBlockAttributes($data, $currentElement);
$this->updateScheduledData($currentElement, $data);
$this->evaluateArguments($currentElement, $data);
$scheduledStructure->setStructureElementData($elementName, $data);
return;
} elseif ($currentElement->getAttribute('remove')) {
$scheduledStructure->unsetElementFromListToRemove($elementName);
}
$data = $scheduledStructure->getStructureElementData($elementName, []);
$data['attributes'] = $this->mergeBlockAttributes($data, $currentElement);
$this->updateScheduledData($currentElement, $data);
$this->evaluateArguments($currentElement, $data);
$scheduledStructure->setStructureElementData($elementName, $data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ protected function containerReference(
) {
$containerName = $currentElement->getAttribute('name');
$containerRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);

if ($containerRemove) {
$scheduledStructure->setElementToRemoveList($containerName);
} else {
$this->mergeContainerAttributes($scheduledStructure, $currentElement);
return;
} elseif ($currentElement->getAttribute('remove')) {
$scheduledStructure->unsetElementFromListToRemove($containerName);
}
$this->mergeContainerAttributes($scheduledStructure, $currentElement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ public function testProcessReference(
$setCondition,
$setRemoveCondition
) {
if ($literal == 'referenceBlock' && $remove == 'false') {
$this->scheduledStructure->expects($this->once())
->method('unsetElementFromListToRemove')
->with($literal);
}

$this->context->expects($this->once())->method('getScheduledStructure')
->will($this->returnValue($this->scheduledStructure));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public function testProcess(
->with($contextMock, $elementCurrent)
->willReturnSelf();

if ($elementCurrent->getAttribute('remove') == 'false') {
$scheduledStructureMock->expects($this->once())
->method('unsetElementFromListToRemove')
->with($elementCurrent->getAttribute('name'));
}

$this->container->interpret($contextMock, $elementCurrent);
}

Expand Down

0 comments on commit b5700ce

Please sign in to comment.