示例#1
0
 /**
  * Here we set default values for block's settings (used by Widget Blocks).
  *
  * Triggers the `Block.<handler>.settingsDefaults` event, event listeners
  * should catch the event and return an array as `key` => `value` with default
  * values.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Block\Model\Entity\Block $block The block where to put those values
  * @return array
  */
 public function settingsDefaultValues(Event $event, Block $block)
 {
     if (!$block->isCustom()) {
         return (array) $block->defaultSettings();
     }
     return [];
 }
 /**
  * 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]);
 }