예제 #1
0
파일: AclBehavior.php 프로젝트: cakephp/acl
 /**
  * Creates a new ARO/ACO node bound to this record
  *
  * @param Event $event The afterSave event that was fired
  * @param Entity $entity The entity being saved
  * @return void
  */
 public function afterSave(Event $event, Entity $entity)
 {
     $model = $event->subject();
     $types = $this->_typeMaps[$this->config('type')];
     if (!is_array($types)) {
         $types = [$types];
     }
     foreach ($types as $type) {
         $parent = $entity->parentNode();
         if (!empty($parent)) {
             $parent = $this->node($parent, $type)->first();
         }
         $data = ['parent_id' => isset($parent->id) ? $parent->id : null, 'model' => $model->alias(), 'foreign_key' => $entity->id];
         if (!$entity->isNew()) {
             $node = $this->node($entity, $type)->first();
             $data['id'] = isset($node->id) ? $node->id : null;
             $newData = $model->{$type}->patchEntity($node, $data);
         } else {
             $newData = $model->{$type}->newEntity($data);
         }
         $saved = $model->{$type}->target()->save($newData);
     }
 }