\Block\ViewRegion

Region class.

Represents a single region of a theme.

Summary

Methods
Properties
Constants
__construct()
name()
theme()
blocks()
count()
blockLimit()
merge()
homogenize()
render()
__toString()
__debugInfo()
cache()
dropCache()
No public properties found
No constants found
_prepareBlocks()
_filterBlock()
_urlMatch()
$_machineName
$_blocks
$_blockLimit
$_theme
$_View
$_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_machineName

$_machineName : string

machine name of this region. e.g. 'left-sidebar'

Type

string

$_blocks

$_blocks : \Cake\Collection\Collection

Collection of blocks for this region.

Type

\Cake\Collection\Collection

$_blockLimit

$_blockLimit : null|integer

Maximum number of blocks this region can holds.

Type

null|integer

$_cache

$_cache : array

Used internally.

Type

array

Methods

__construct()

__construct(\QuickApps\View\View $view, string $name, array $options)

Constructor.

Valid options are:

  • fixMissing: When creating a region that is not defined by the theme, it will try to fix it by adding it to theme's regions if this option is set to TRUE. Defaults to NULL which automatically enables when debug is enabled. This option will not work when using QuickAppsCMS's core themes. (NOTE: This option will alter theme's composer.json file)

  • theme: Name of the theme this regions belongs to. Defaults to auto-detect.

Parameters

\QuickApps\View\View $view

Instance of View class to use

string $name

Machine name of the region. e.g.: left-sidebar

array $options

Options given as an array

name()

name() : string

Returns the name of this region.

Returns

string

theme()

theme() : \Block\View\QuickApps\Core\Package\PluginPackage

Returns information of the theme this regions belongs to.

Usage:

$theme = $this->region('left-sidebar')->theme();

Returns

\Block\View\QuickApps\Core\Package\PluginPackage

blocks()

blocks(\Cake\Collection\Collection $blocks) : \Cake\Collection\Collection

Gets or sets the block collection of this region.

When passing a collection of blocks as first argument, all blocks in the collection will be homogenized, see homogenize() for details.

Parameters

\Cake\Collection\Collection $blocks

Blocks collection if you want to overwrite current collection, leave empty to return current collection

Returns

\Cake\Collection\Collection

count()

count() : integer

Counts the number of blocks within this region.

Returns

integer

blockLimit()

blockLimit(null|integer $number) : \Block\View\Region

Limits the number of blocks in this region.

Null means unlimited number.

Parameters

null|integer $number

Defaults to null

Returns

\Block\View\Region

merge()

merge(\Block\View\Region $region, boolean $homogenize) : \Block\View\Region

Merge blocks from another region.

You can not merge regions with the same machine-name, new blocks are appended to this region.

Parameters

\Block\View\Region $region

Region to merge with

boolean $homogenize

Set to true to make sure all blocks in the collection are marked as they belongs to this region

Returns

\Block\View\Region

This region with $region's blocks appended

homogenize()

homogenize() : \Block\View\Region

Makes sure that every block in this region is actually marked as it belongs to this region.

Used when merging blocks from another region.

Returns

\Block\View\Region

This region with homogenized blocks

render()

render() : string

Render all the blocks within this region.

Returns

string

__toString()

__toString() : string

Magic method for rendering this region.

echo $this->region('left-sidebar');

Returns

string

__debugInfo()

__debugInfo() : array

Returns an array that can be used to describe the internal state of this object.

Returns

array

cache()

cache(null|string $key, mixed $value) : mixed

Reads, writes or search internal class's cache.

Usages:

  • When reading if no cache key is found NULL will be returned. e.g. $null = static::cache('invalid-key');
  • When writing, this method return the value that was written. e.g. $value = static::cache('key', 'value');
  • Set both arguments to NULL to read the whole cache content at the moment. e.g. $allCache = static::cache()
  • Set key to null and value to anything to find the first key holding the given value. e.g. $key = static::cache(null, 'search key for this value'), if no key for the given value is found NULL will be returned.

Examples:

Writing cache:

static::cache('user_name', 'John');
// returns 'John'

static::cache('user_last', 'Locke');
// returns 'Locke'

Reading cache:

static::cache('user_name');
// returns: John

static::cache('unexisting_key');
// returns: null

static::cache();
// Reads the entire cache
// returns: ['user_name' => 'John', 'user_last' => 'Locke']

Searching keys:

static::cache(null, 'Locke');
// returns: user_last

static::cache(null, 'Unexisting Value');
// returns: null

Parameters

null|string $key

Cache key to read or write, set both $key and $value to get the whole cache information

mixed $value

Values to write into the given $key, or null indicates reading from cache

Returns

mixed

dropCache()

dropCache(string|null $key) : void

Drops the entire cache or a specific key.

Usage:

static::dropCache('user_cache'); // removes "user_cache" only
static::dropCache(); // removes every key

Parameters

string|null $key

Cache key to clear, if NULL the entire cache will be erased.

_prepareBlocks()

_prepareBlocks() : void

Fetches all block entities that could be rendered within this region.

_filterBlock()

_filterBlock(\Block\Model\Entity\Block $block) : boolean

Checks if the given block can be rendered.

Parameters

\Block\Model\Entity\Block $block

Block entity

Returns

boolean —

True if can be rendered

_urlMatch()

_urlMatch(string $patterns) : boolean

Check if a current URL matches any pattern in a set of patterns.

Parameters

string $patterns

String containing a set of patterns separated by \n, \r or \r\n

Returns

boolean —

TRUE if the path matches a pattern, FALSE otherwise