Exemplo n.º 1
0
 /**
  * Triggered after block was removed from DB.
  *
  * All cached blocks are automatically removed.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Block\Model\Entity\Block $block The block entity that was deleted
  * @param \ArrayObject $options Additional options given as an array
  * @return void
  */
 public function afterDelete(Event $event, Block $block, ArrayObject $options = null)
 {
     $block->afterDelete();
     $this->clearCache();
 }
Exemplo n.º 2
0
 /**
  * Renders the given block.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Block\Model\Entity\Block $block Block entity to be rendered
  * @param array $options Additional options, will be passed to the template
  *  element being rendered
  * @return string The rendered block
  */
 public function renderBlock(Event $event, Block $block, $options = [])
 {
     return $block->render();
 }
Exemplo n.º 3
0
 /**
  * Prepares incoming data from Form's POST and patches the given entity.
  *
  * @param \Block\Model\Entity\Block $block BLock to patch with incoming
  *  POST data
  * @return \Cake\Datasource\EntityInterface Patched entity
  */
 protected function _patchEntity($block)
 {
     $this->loadModel('Block.Blocks');
     $data = ['region' => []];
     foreach ($this->request->data() as $column => $value) {
         if ($column == 'region') {
             foreach ($value as $theme => $region) {
                 $tmp = ['theme' => $theme, 'region' => $region];
                 foreach ((array) $block->region as $blockRegion) {
                     if ($blockRegion->theme == $theme) {
                         $tmp['id'] = $blockRegion->id;
                         break;
                     }
                 }
                 $data[$column][] = $tmp;
             }
         } else {
             $data[$column] = $value;
         }
     }
     if ($block->isNew()) {
         $data['handler'] = 'Block\\Widget\\CustomBlockWidget';
         $block->set('handler', 'Block\\Widget\\CustomBlockWidget');
     }
     $validator = $block->isCustom() ? 'custom' : 'widget';
     return $this->Blocks->patchEntity($block, $data, ['validate' => $validator, 'entity' => $block]);
 }
Exemplo n.º 4
0
 /**
  * Checks if the given block can be rendered.
  *
  * @param \Block\Model\Entity\Block $block Block entity
  * @return bool True if can be rendered
  */
 protected function _filterBlock(Block $block)
 {
     $cacheKey = "allowed_{$block->id}";
     $cache = static::cache($cacheKey);
     if ($cache !== null) {
         return $cache;
     }
     if (!empty($block->locale) && !in_array(I18n::locale(), (array) $block->locale)) {
         return static::cache($cacheKey, false);
     }
     if (!$block->isAccessible()) {
         return static::cache($cacheKey, false);
     }
     $allowed = false;
     switch ($block->visibility) {
         case 'except':
             // Show on all pages except listed pages
             $allowed = !$this->_urlMatch($block->pages);
             break;
         case 'only':
             // Show only on listed pages
             $allowed = $this->_urlMatch($block->pages);
             break;
         case 'php':
             // Use custom PHP code to determine visibility
             $allowed = php_eval($block->pages, ['view' => &$this->_View, 'block' => &$block]) === true;
             break;
     }
     if (!$allowed) {
         return static::cache($cacheKey, false);
     }
     return static::cache($cacheKey, true);
 }