original_string: 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]);
      }
code: 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]);
      }
code_tokens: 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 ] ) ; }
docstring: 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
docstring_tokens: Prepares incoming data from Form s POST and patches the given entity .