Jarves\Admin\ObjectCrud::patch PHP Method

patch() public method

Patches a object entry. This means, only defined fields will be saved. Fields which are not defined will not be overwritten.
public patch ( array $pk, Request | array $requestOrData ) : boolean
$pk array
$requestOrData Symfony\Component\HttpFoundation\Request | array
return boolean
    public function patch($pk, $requestOrData)
    {
        $storageController = $this->objects->getStorageController($this->getObject());
        $pk = $storageController->normalizePrimaryKey($pk);
        $this->primaryKey = $pk;
        $values = $this->collectData($requestOrData);
        $args = ['pk' => $pk, 'values' => &$values, 'controller' => $this, 'mode' => 'update'];
        $eventPre = new GenericEvent($this->getObject(), $args);
        $this->eventDispatcher->dispatch('core/object/modify-pre', $eventPre);
        $this->eventDispatcher->dispatch('core/object/patch-pre', $eventPre);
        $item = $this->getItem($pk);
        if ($this->getPermissionCheck()) {
            if (!$item) {
                return null;
            }
            if (!$this->acl->check(ACLRequest::create($this->getObject(), $pk)->onlyUpdateMode())) {
                return null;
            }
            foreach ($values as $fieldName => $value) {
                $aclRequest = ACLRequest::create($this->getObject(), $pk)->setField([$fieldName => $value])->onlyUpdateMode();
                if (!$this->acl->check($aclRequest)) {
                    throw new AccessDeniedException(sprintf('Not allowed to change `%s`', $fieldName));
                }
            }
        }
        if (($condition = $this->getCondition()) && $condition->hasRules()) {
            if (!$this->conditionOperator->satisfy($condition, $item, $this->getObject())) {
                return null;
            }
        }
        $incomingFields = $requestOrData instanceof Request ? array_keys($requestOrData->request->all()) : array_keys($requestOrData);
        if (!$incomingFields) {
            return false;
        }
        $changedData = $this->mapData($values, $incomingFields, $item);
        if ($this->getWithNewsFeed()) {
            $this->utils->newNewsFeed($this->objects, $this->getObject(), array_merge($values, $pk), 'updated');
        }
        $result = $storageController->patch($pk, $changedData);
        $args['result'] = $result;
        $event = new GenericEvent($this->getObject(), $args);
        $this->eventDispatcher->dispatch('core/object/modify', $event);
        $this->eventDispatcher->dispatch('core/object/patch', $event);
        return $result;
    }
ObjectCrud