protected function setParent(InterfaceGeneralModel $objChildEntry, InterfaceGeneralModel $objParentEntry, $strTable) { $arrChildCondition = $this->getDC()->getParentChildCondition($objParentEntry, $objChildEntry->getProviderName()); if (!($arrChildCondition && $arrChildCondition['setOn'])) { throw new Exception("Can not calculate parent.", 1); } foreach ($arrChildCondition['setOn'] as $arrCondition) { if ($arrCondition['from_field']) { $objChildEntry->setProperty($arrCondition['to_field'], $objParentEntry->getProperty($arrCondition['from_field'])); } else { if (!is_null('value', $arrCondition)) { $objChildEntry->setProperty($arrCondition['to_field'], $arrCondition['value']); } else { throw new Exception("Error Processing child condition, neither from_field nor value specified: " . var_export($arrCondition, true), 1); } } } }
/** * Parse|Check|Validate each field and save it. * * @param string $strField Name of current field * @return void */ public function processInput($strField) { if (in_array($strField, $this->arrProcessedNames)) { return $this->arrProcessed[$strField]; } $this->arrProcessedNames[] = $strField; $strInputName = $strField . '_' . $this->mixWidgetID; // Return if no submit, field is not editable or not in input if (!($this->blnSubmitted && isset($this->arrInputs[$strInputName]) && $this->isEditableField($strField) && !(isset($this->arrDCA['fields'][$strField]['eval']['readonly']) && $this->arrDCA['fields'][$strField]['eval']['readonly']))) { return $this->arrProcessed[$strField] = null; } // Build widget $objWidget = $this->getWidget($strField); if (!$objWidget instanceof Widget) { return $this->arrProcessed[$strField] = null; } // Validate $objWidget->validate(); if (Input::getInstance()->post('SUBMIT_TYPE') == 'auto') { // HACK: we would need a Widget::clearErrors() here but something like this does not exist, hence we have a class that does this for us. WidgetAccessor::resetErrors($objWidget); } // Check if ($objWidget->hasErrors()) { $this->blnNoReload = true; return $this->arrProcessed[$strField] = null; } if (!$objWidget->submitInput()) { return $this->arrProcessed[$strField] = $this->objCurrentModel->getProperty($strField); } // Get value and config $varNew = $objWidget->value; $arrConfig = $this->getFieldDefinition($strField); // If array sort if (is_array($varNew)) { ksort($varNew); } else { if ($varNew != '' && isset(self::$arrDates[$arrConfig['eval']['rgxp']])) { // OH: this should be a widget feature $objDate = new Date($varNew, $GLOBALS['TL_CONFIG'][$arrConfig['eval']['rgxp'] . 'Format']); $varNew = $objDate->tstamp; } } $this->import('Input'); //Handle multi-select fields in "override all" mode // OH: this should be a widget feature if (($arrConfig['inputType'] == 'checkbox' || $arrConfig['inputType'] == 'checkboxWizard') && $arrConfig['eval']['multiple'] && $this->Input->get('act') == 'overrideAll') { if ($arrNew == null || !is_array($arrNew)) { $arrNew = array(); } // FIXME: this will NOT work, as it still uses activeRecord - otoh, what is this intended for? wizards? switch ($this->Input->post($objWidget->name . '_update')) { case 'add': $varNew = array_values(array_unique(array_merge(deserialize($this->objActiveRecord->{$strField}, true), $arrNew))); break; case 'remove': $varNew = array_values(array_diff(deserialize($this->objActiveRecord->{$strField}, true), $arrNew)); break; case 'replace': $varNew = $arrNew; break; } if (!$varNew) { $varNew = ''; } } // Call the save callbacks try { $varNew = $this->objCallbackClass->saveCallback($arrConfig, $varNew); } catch (Exception $e) { $this->blnNoReload = true; $objWidget->addError($e->getMessage()); return $this->arrProcessed[$strField] = null; } // Check on value empty if ($varNew == '' && $arrConfig['eval']['doNotSaveEmpty']) { $this->blnNoReload = true; $objWidget->addError($GLOBALS['TL_LANG']['ERR']['mdtryNoLabel']); return $this->arrProcessed[$strField] = null; } if ($varNew != '') { if ($arrConfig['eval']['encrypt']) { $varNew = $this->Encryption->encrypt(is_array($varNew) ? serialize($varNew) : $varNew); } else { if ($arrConfig['eval']['unique'] && !$this->getDataProvider($this->objCurrentModel->getProviderName())->isUniqueValue($strField, $varNew, $this->objCurrentModel->getID())) { $this->blnNoReload = true; $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $objWidget->label)); return $this->arrProcessed[$strField] = null; } else { if ($arrConfig['eval']['fallback']) { $this->getDataProvider($this->objCurrentModel->getProviderName())->resetFallback($strField); } } } } $this->arrProcessed[$strField] = $varNew; return $varNew; }