Skip to content

Commit

Permalink
Merge pull request #11 from hummer2k/feature/remove-block-property
Browse files Browse the repository at this point in the history
remove blocks via remove property
  • Loading branch information
hummer2k committed Oct 17, 2015
2 parents f8c91e2 + 49614d4 commit d66ae5c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 47 deletions.
13 changes: 8 additions & 5 deletions docs/layout-instructions.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Layout instructions

Currently there are 5 layout instructions:
Currently there are 4 layout instructions:

1. [`layout`](#1-layout)
2. [`blocks`](#2-blocks)
3. [`remove_blocks`](#3-remove_blocks)
4. [`view_helpers`](#4-view_helpers)
5. [`include`](#5-include)
3. [`view_helpers`](#4-view_helpers)
4. [`include`](#5-include)

## 1. `layout`

Expand Down Expand Up @@ -83,12 +82,16 @@ return [
* if false, wrapper will be disabled: 'wrapper' => false,
*
* defaults: tag: 'div', 'template: 'blocks/wrapper'
*/
*/
'wrapper' => [
'template' => 'blocks/wrapper',
'class' => 'col-xs-12',
'tag' => 'div'
],
/**
* remove this block
*/
'remove' => true,
// just set a custom template
'wrapper' => 'my/wrapper',
// or add more attributes for the wrapper tag
Expand Down
11 changes: 6 additions & 5 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ It is assumed that you already have set up a
[ZendDeveloperTools](https://github.com/zendframework/ZendDeveloperTools) and
installed the ConLayout module.
We will cover basic configuration on module-basis and you will get to know the
layout instructions `layout`, `blocks`, `remove_blocks` and
`include`.
layout instructions `layout`, `blocks` and `include`.

## Table of contents

Expand Down Expand Up @@ -577,7 +576,7 @@ view action.

## 9. Remove blocks from a specific page

We can remove blocks with the instruction `remove_blocks`
We can remove blocks with the property `remove`

As an example, we edit our layout update file for the handle
`application/index/include`:
Expand All @@ -587,8 +586,10 @@ return [
'include' => [
'application/index/view' => true
],
'remove_blocks' => [
'latest.articles' => true
'blocks' => [
'latest.articles' => [
'remove' => true
]
]
];
````
Expand Down
42 changes: 10 additions & 32 deletions src/ConLayout/Layout/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ class Layout implements
*/
protected $blocksGenerated = false;

/**
* flag if blocks have already been removed from layout structure
*
* @var bool
*/
protected $blocksRemoved = false;

/**
*
* @var LayoutUpdaterInterface
Expand Down Expand Up @@ -116,7 +109,7 @@ protected function generateBlocks()
$blocks = $blocks->toArray();
}
foreach ($blocks as $blockId => $specs) {
if ($this->isBlockRemoved($blockId)) {
if ($this->isBlockRemoved($blockId, $specs)) {
continue;
}
$block = $this->blockFactory->createBlock($blockId, $specs);
Expand All @@ -126,36 +119,21 @@ protected function generateBlocks()
}
}

/**
* removes blocks defined in layout instructions
*/
protected function removeBlocksByInstructions()
{
if (!$this->blocksRemoved) {
$removedBlocks = $this->updater->getLayoutStructure()
->get(LayoutUpdaterInterface::INSTRUCTION_REMOVE_BLOCKS, []);
if ($removedBlocks instanceof Config) {
$removedBlocks = $removedBlocks->toArray();
foreach ($removedBlocks as $removedBlockId => $value) {
if ($value) {
$this->removeBlock($removedBlockId);
}
}
}
$this->blocksRemoved = true;
}
}

/**
* check if block has been removed
*
* @param string $blockId
* @param string $blockId
* @param array $specs
* @return boolean
*/
protected function isBlockRemoved($blockId)
protected function isBlockRemoved($blockId, array $specs)
{
$this->removeBlocksByInstructions();
return isset($this->removedBlocks[$blockId]);
if ((isset($specs['remove']) && $specs['remove']) ||
isset($this->removedBlocks[$blockId])
) {
return true;
}
return false;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/ConLayout/Updater/LayoutUpdaterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface LayoutUpdaterInterface
{
const INSTRUCTION_LAYOUT_TEMPLATE = 'layout';
const INSTRUCTION_BLOCKS = 'blocks';
const INSTRUCTION_REMOVE_BLOCKS = 'remove_blocks';
const INSTRUCTION_VIEW_HELPERS = 'view_helpers';
const INSTRUCTION_INCLUDE = 'include';

Expand Down
1 change: 1 addition & 0 deletions src/ConLayout/View/Helper/Proxy/HeadLinkProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* @package ConLayout
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
* @codeCoverageIgnore
*/
class HeadLinkProxy extends AbstractViewHelperProxy
{
Expand Down
1 change: 1 addition & 0 deletions src/ConLayout/View/Helper/Proxy/HeadMetaProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @package ConLayout
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
* @codeCoverageIgnore
*/
class HeadMetaProxy extends AbstractViewHelperProxy
{
Expand Down
1 change: 1 addition & 0 deletions src/ConLayout/View/Helper/Proxy/HeadScriptProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @package ConLayout
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
* @codeCoverageIgnore
*/
class HeadScriptProxy extends AbstractViewHelperProxy
{
Expand Down
1 change: 1 addition & 0 deletions src/ConLayout/View/Helper/Proxy/HeadTitleProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @package ConLayout
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
* @codeCoverageIgnore
*/
class HeadTitleProxy extends AbstractViewHelperProxy
{
Expand Down
1 change: 1 addition & 0 deletions src/ConLayout/View/Helper/Proxy/InlineScriptProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @package ConLayout
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
* @codeCoverageIgnore
*/
class InlineScriptProxy extends HeadScriptProxy
{
Expand Down
7 changes: 3 additions & 4 deletions tests/ConLayoutTest/Layout/_files/layout-structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
'widget.1.child' => [
'capture_to' => 'widget.1::childHtml'
],
'some.removed.block' => []
],
LayoutUpdaterInterface::INSTRUCTION_REMOVE_BLOCKS => [
'some.removed.block' => true
'some.removed.block' => [
'remove' => true
]
]
];

0 comments on commit d66ae5c

Please sign in to comment.