|
@@ -49,6 +49,7 @@ class ObjectFormManager extends FormManager
|
|
|
const ENUM_MODE_VIEW = 'view';
|
|
|
const ENUM_MODE_EDIT = 'edit';
|
|
|
const ENUM_MODE_CREATE = 'create';
|
|
|
+ const ENUM_MODE_APPLY_STIMULUS = 'apply_stimulus';
|
|
|
|
|
|
protected $oApp;
|
|
|
protected $oObject;
|
|
@@ -482,6 +483,18 @@ class ObjectFormManager extends FormManager
|
|
|
{
|
|
|
$oField->SetReadOnly(true);
|
|
|
}
|
|
|
+ // - Else if it's must change, we force it as not readonly and not hidden
|
|
|
+ elseif (($iFieldFlags & OPT_ATT_MUSTCHANGE) === OPT_ATT_MUSTCHANGE)
|
|
|
+ {
|
|
|
+ $oField->SetReadOnly(false);
|
|
|
+ $oField->SetHidden(false);
|
|
|
+ }
|
|
|
+ // - Else if it's must prompt, we force it as not readonly and not hidden
|
|
|
+ elseif (($iFieldFlags & OPT_ATT_MUSTPROMPT) === OPT_ATT_MUSTPROMPT)
|
|
|
+ {
|
|
|
+ $oField->SetReadOnly(false);
|
|
|
+ $oField->SetHidden(false);
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
// Normal field
|
|
@@ -658,6 +671,87 @@ class ObjectFormManager extends FormManager
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Merging $this->aFormProperties with $aFormPropertiesToMerge. Merge only layout for now
|
|
|
+ *
|
|
|
+ * @param array $aFormPropertiesToMerge
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public function MergeFormProperties($aFormPropertiesToMerge)
|
|
|
+ {
|
|
|
+ if ($aFormPropertiesToMerge['layout'] !== null)
|
|
|
+ {
|
|
|
+ // Checking if we need to render the template from twig to html in order to parse the fields
|
|
|
+ if ($aFormPropertiesToMerge['layout']['type'] === 'twig')
|
|
|
+ {
|
|
|
+ // Creating sandbox twig env. to load and test the custom form template
|
|
|
+ $oTwig = new \Twig_Environment(new \Twig_Loader_String());
|
|
|
+ $sRendered = $oTwig->render($aFormPropertiesToMerge['layout']['content'], array('oRenderer' => $this->oRenderer, 'oObject' => $this->oObject));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $sRendered = $aFormPropertiesToMerge['layout']['content'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Parsing rendered template to find the fields
|
|
|
+ $oHtmlDocument = new \DOMDocument();
|
|
|
+ $oHtmlDocument->loadHTML('<root>' . $sRendered . '</root>');
|
|
|
+
|
|
|
+ // Adding fields to the list
|
|
|
+ $oXPath = new \DOMXPath($oHtmlDocument);
|
|
|
+ foreach ($oXPath->query('//div[@class="form_field"][@data-field-id]') as $oFieldNode)
|
|
|
+ {
|
|
|
+ $sFieldId = $oFieldNode->getAttribute('data-field-id');
|
|
|
+ $sFieldFlags = $oFieldNode->getAttribute('data-field-flags');
|
|
|
+// $iFieldFlags = OPT_ATT_NORMAL;
|
|
|
+
|
|
|
+// // Checking if field has form_path, if not, we add it
|
|
|
+// if (!$oFieldNode->hasAttribute('data-form-path'))
|
|
|
+// {
|
|
|
+// $oFieldNode->setAttribute('data-form-path', $oForm->GetId());
|
|
|
+// }
|
|
|
+ // Merging only fields that are already in the form
|
|
|
+ if (array_key_exists($sFieldId, $this->aFormProperties['fields']))
|
|
|
+ {
|
|
|
+ // Settings field flags from the data-field-flags attribute
|
|
|
+ foreach (explode(' ', $sFieldFlags) as $sFieldFlag)
|
|
|
+ {
|
|
|
+ if ($sFieldFlag !== '')
|
|
|
+ {
|
|
|
+ $sConst = 'OPT_ATT_' . strtoupper(str_replace('_', '', $sFieldFlag));
|
|
|
+ if (defined($sConst))
|
|
|
+ {
|
|
|
+ switch ($sConst)
|
|
|
+ {
|
|
|
+ case 'OPT_ATT_SLAVE':
|
|
|
+ case 'OPT_ATT_HIDDEN':
|
|
|
+ if (!array_key_exists($sFieldId, $this->aFormProperties['fields']))
|
|
|
+ {
|
|
|
+ $this->aFormProperties['fields'][$sFieldId] = array();
|
|
|
+ }
|
|
|
+ $this->aFormProperties['fields'][$sFieldId]['hidden'] = true;
|
|
|
+ break;
|
|
|
+ case 'OPT_ATT_READONLY':
|
|
|
+ if (!array_key_exists($sFieldId, $this->aFormProperties['fields']))
|
|
|
+ {
|
|
|
+ $this->aFormProperties['fields'][$sFieldId] = array();
|
|
|
+ }
|
|
|
+ $this->aFormProperties['fields'][$sFieldId]['read_only'] = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ IssueLog::Error(__METHOD__ . ' at line ' . __LINE__ . ' : Flag "' . $sFieldFlag . '" is not valid for field [@data-field-id="' . $sFieldId . '"] in form[@id="' . $aFormPropertiesToMerge['id'] . '"]');
|
|
|
+ throw new Exception('Flag "' . $sFieldFlag . '" is not valid for field [@data-field-id="' . $sFieldId . '"] in form[@id="' . $aFormPropertiesToMerge['id'] . '"]');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Calls all form fields OnCancel method in order to delegate them the cleanup;
|
|
|
*
|
|
|
* @param array $aArgs
|