Skip to content

Commit

Permalink
Created initializeBlocks method so we can use the Trait everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Òscar Casajuana committed Jul 1, 2016
1 parent 401d30f commit 795e72e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
8 changes: 1 addition & 7 deletions src/Controller/Component/BlockComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public function __construct(ComponentRegistry $registry, array $config = [])
{
parent::__construct($registry, $config);

$this->table = Configure::read('Blocks.table');

if ($this->config('table')) {
$this->table = $this->config('table');
}

$this->Blocks = TableRegistry::get($this->table);
$this->initializeBlocks($config);
}
}
20 changes: 20 additions & 0 deletions src/Utility/BlocksTrait.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace Cirici\Blocks\Utility;

use Cake\Core\Configure;
use Cake\ORM\TableRegistry;

trait BlocksTrait
{
/**
Expand All @@ -16,6 +19,23 @@ trait BlocksTrait
*/
protected $Blocks;

/**
* Used to initialize the BlocksTable instance.
*
* @param array $config Array of additional configuration options.
* @return void
*/
public function initializeBlocks(array $config = [])
{
$this->table = Configure::read('Blocks.table');

if (isset($config['table'])) {
$this->table = $config['table'];
}

$this->Blocks = TableRegistry::get($this->table);
}

/**
* Retrieves an entire block from given identifier
*
Expand Down
8 changes: 1 addition & 7 deletions src/View/Helper/BlockHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ public function __construct(View $view, array $config = [])
{
parent::__construct($view, $config);

$this->table = Configure::read('Blocks.table');

if ($this->config('table')) {
$this->table = $this->config('table');
}

$this->Blocks = TableRegistry::get($this->table);
$this->initializeBlocks($config);
}
}

0 comments on commit 795e72e

Please sign in to comment.