Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove blocks via remove property #11

Merged
merged 3 commits into from
Oct 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
]
]
];