CrudKit\Pages\BasicDataPage::handle_set_form_values PHP Метод

handle_set_form_values() публичный Метод

    public function handle_set_form_values()
    {
        if ($this->app->isReadOnly()) {
            throw new Exception("Read Only");
        }
        $form = new FormHelper(array(), $this->dataProvider->getEditFormConfig());
        $url = new UrlHelper();
        $values = json_decode($url->get("values_json", "{}"), true);
        if (empty($values)) {
            return array('type' => 'json', 'data' => array('success' => true));
        }
        //validate
        $failedValues = $this->dataProvider->validateRow($values);
        if (empty($failedValues)) {
            $url = new UrlHelper();
            $rowId = $url->get("item_id", null);
            $summaryKey = $this->dataProvider->getSummaryColumns()[0]['key'];
            $rowData = $this->dataProvider->getRow($rowId);
            $rowName = $rowData[$summaryKey];
            $this->dataProvider->setRow($url->get("item_id", null), $values);
            FlashBag::add("alert", "Item {$rowName} has been updated", "success");
            return array('type' => 'json', 'data' => array('success' => true, 'dataValid' => true));
        } else {
            FlashBag::add("alert", "Could not update certain fields", "error");
            return array('type' => 'json', 'data' => array('success' => true, 'dataValid' => false, 'failedValues' => $failedValues));
            //throw new \Exception("Cannot validate values");
        }
    }