From 87ba078dc8c1d66b60815a0535426b8c851770dd Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 4 Dec 2017 16:56:18 +0200 Subject: [PATCH] fixed unintended formating. tweaked functions. resolved gh-189 --- admin/helpers/compiler/c_Fields.php | 308 ++++++++++++++-------------- 1 file changed, 156 insertions(+), 152 deletions(-) diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index 875da7395..bdfefb1cf 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -1,5 +1,4 @@ debugLinenr) { - return ' [Fields '.$nr.']'; + return ' [Fields '.$nr.']'; } return ''; } /** * set the Field set of a view - * + * * @param array $view The view data * @param string $component The component name * * @return string The fields set in xml - * + * */ public function setFieldSet($view, $component) { @@ -868,45 +868,45 @@ class Fields extends Structure /** * set a field * - * @param string $setType The set of fields type - * @param array $fieldAttributes The field values - * @param string $name The field name - * @param string $typeName The field type - * @param string $langView The language string of the view - * @param string $viewName The singel view name - * @param string $listViewName The list view name - * @param array $placeholders The place holder and replace values - * @param string $optionArray The option bucket array used to set the field options if needed. - * @param arra $custom Used when field is from config + * @param string $setType The set of fields type + * @param array $fieldAttributes The field values + * @param string $name The field name + * @param string $typeName The field type + * @param string $langView The language string of the view + * @param string $viewName The single view name + * @param string $listViewName The list view name + * @param array $placeholders The place holder and replace values + * @param string $optionArray The option bucket array used to set the field options if needed. + * @param array $custom Used when field is from config * * @return SimpleXMLElement The field in xml * */ private function setField($setType, &$fieldAttributes, &$name, &$typeName, &$langView, &$viewName, &$listViewName, $placeholders, &$optionArray, $custom = null) { - $r = new stdClass(); + $field = new stdClass(); if ($setType === 'option') { // now add to the field set - $r->fieldXML = new SimpleXMLElement(''); - $r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; + $field->fieldXML = new SimpleXMLElement(''); + $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; foreach ($fieldAttributes as $property => $value) { if ($property != 'option') { - $r->fieldXML->addAttribute($property, $value); + $field->fieldXML->addAttribute($property, $value); } elseif ($property === 'option') { - $this->xmlComment($r->fieldXML, $this->setLine(__LINE__) . " Option Set."); + $this->xmlComment($field->fieldXML, $this->setLine(__LINE__) . " Option Set."); if (strpos($value, ',') !== false) { // mulitpal options $options = explode(',', $value); foreach ($options as $option) { - $optionXML = $r->fieldXML->addChild('option'); + $optionXML = $field->fieldXML->addChild('option'); if (strpos($option, '|') !== false) { // has other value then text @@ -934,7 +934,7 @@ class Fields extends Structure else { // one option - $optionXML = $r->fieldXML->addChild('option'); + $optionXML = $field->fieldXML->addChild('option'); if (strpos($value, '|') !== false) { // has other value then text @@ -960,36 +960,36 @@ class Fields extends Structure } } } - if (!$r->fieldXML->count()) + if (!$field->fieldXML->count()) { - $this->xmlComment($r->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings."); + $this->xmlComment($field->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings."); } } elseif ($setType === 'plain') { // now add to the field set - $r->fieldXML = new SimpleXMLElement(''); - $r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; + $field->fieldXML = new SimpleXMLElement(''); + $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; foreach ($fieldAttributes as $property => $value) { if ($property != 'option') { - $r->fieldXML->addAttribute($property, $value); + $field->fieldXML->addAttribute($property, $value); } } } elseif ($setType === 'spacer') { // now add to the field set - $r->fieldXML = new SimpleXMLElement(''); - $r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". A None Database Field. (joomla)"; + $field->fieldXML = new SimpleXMLElement(''); + $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". A None Database Field. (joomla)"; foreach ($fieldAttributes as $property => $value) { if ($property != 'option') { - $r->fieldXML->addAttribute($property, $value); + $field->fieldXML->addAttribute($property, $value); } } } @@ -999,17 +999,17 @@ class Fields extends Structure if ($typeName === 'repeatable') { // now add to the field set - $r->fieldXML = new SimpleXMLElement(''); - $r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; + $field->fieldXML = new SimpleXMLElement(''); + $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (depreciated)"; foreach ($fieldAttributes as $property => $value) { if ($property != 'fields') { - $r->fieldXML->addAttribute($property, $value); + $field->fieldXML->addAttribute($property, $value); } } - $fieldsXML = $r->fieldXML->addChild('fields'); + $fieldsXML = $field->fieldXML->addChild('fields'); $fieldsXML->addAttribute('name', $fieldAttributes['name'] . '_fields'); $fieldsXML->addAttribute('label', ''); $fieldSetXML = $fieldsXML->addChild('fieldset'); @@ -1088,20 +1088,25 @@ class Fields extends Structure elseif ($typeName === 'subform') { // now add to the field set - $r->fieldXML = new SimpleXMLElement(''); - $r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; - + $field->fieldXML = new SimpleXMLElement(''); + $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; + // add all properties foreach ($fieldAttributes as $property => $value) { - if ($property != 'fields') + if ($property != 'fields' && $property != 'formsource') { - $r->fieldXML->addAttribute($property, $value); + $field->fieldXML->addAttribute($property, $value); } } - // if we do not detect formsource we add the form - if (!isset($fieldAttributes['formsource'])) + // if we detect formsource we do not add the form + if (isset($fieldAttributes['formsource']) && ComponentbuilderHelper::checkString($fieldAttributes['formsource'])) { - $form = $r->fieldXML->addChild('form'); + $field->fieldXML->addAttribute('formsource', $fieldAttributes['formsource']); + } + // add the form + else + { + $form = $field->fieldXML->addChild('form'); $attributes = array( 'hidden' => 'true', 'name' => 'list_' . $fieldAttributes['name'] . '_modal', @@ -1181,13 +1186,13 @@ class Fields extends Structure elseif ($setType === 'custom') { // now add to the field set - $r->fieldXML = new SimpleXMLElement(''); - $r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (custom)"; + $field->fieldXML = new SimpleXMLElement(''); + $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (custom)"; foreach ($fieldAttributes as $property => $value) { if ($property != 'option') { - $r->fieldXML->addAttribute($property, $value); + $field->fieldXML->addAttribute($property, $value); } } // incase the field is in the config and has not been set @@ -1201,16 +1206,16 @@ class Fields extends Structure $this->setCustomFieldTypeFile($data, $listViewName, $viewName); } } - return $r; + return $field; } /** * set the layout builder * * @param string $viewName The single edit view code name - * @param string $tabName The tab code name - * @param string $name The field code name - * @param array $field The field details + * @param string $tabName The tab code name + * @param string $name The field code name + * @param array $field The field details * * @return void * @@ -1295,10 +1300,10 @@ class Fields extends Structure /** * build the site field data needed * - * @param string $view The single edit view code name - * @param string $field The field name - * @param string $set The decoding set this field belongs to - * @param string $type The field type + * @param string $view The single edit view code name + * @param string $field The field name + * @param string $set The decoding set this field belongs to + * @param string $type The field type * * @return void * @@ -1346,7 +1351,7 @@ class Fields extends Structure */ private function setFieldAttributes(&$field, &$viewType, &$name, &$typeName, &$multiple, &$langLabel, $langView, &$spacerCounter, $listViewName, $viewName, $placeholders, $repeatable = false) { - // reset array` + // reset array $fieldAttributes = array(); $setCustom = false; // setup joomla default fields @@ -1469,7 +1474,7 @@ class Fields extends Structure $name = $this->setPlaceholders($xmlValue, $placeholders); } } - elseif ($property['name'] === 'extension' || $property['name'] === 'directory') + elseif ($property['name'] === 'extension' || $property['name'] === 'directory' || $property['name'] === 'formsource') { $xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); // replace the placeholders @@ -1487,7 +1492,7 @@ class Fields extends Structure // set the line number $phpLine = (int) str_replace('type_phpx_', '', $property['name']); // load the php for the custom field file - $fieldAttributes['custom']['php'][$phpLine] = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); + $fieldAttributes['custom']['phpx'][$phpLine] = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); } elseif ($property['name'] === 'extends' && $setCustom) { @@ -1684,7 +1689,6 @@ class Fields extends Structure protected function setUniqueNameKeeper(&$field, &$typeName, &$name, $viewName) { // setup a default field - $xml = new SimpleXMLElement($field['settings']->xml); if (ComponentbuilderHelper::checkArray($field['settings']->properties)) { foreach ($field['settings']->properties as $property)