fixed unintended formating. tweaked functions. resolved gh-189

This commit is contained in:
Llewellyn van der Merwe 2017-12-04 16:56:18 +02:00
parent cc9a0e9c4c
commit 87ba078dc8
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5

View File

@ -1,5 +1,4 @@
<?php <?php
/**--------------------------------------------------------------------------------------------------------| www.vdm.io |------/ /**--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
__ __ _ _____ _ _ __ __ _ _ _ __ __ _ _____ _ _ __ __ _ _ _
\ \ / / | | | __ \ | | | | | \/ | | | | | | | \ \ / / | | | __ \ | | | | | \/ | | | | | | |
@ -37,6 +36,7 @@ class Fields extends Structure
* *
* @var array * @var array
*/ */
public $metadataBuilder = array(); public $metadataBuilder = array();
/** /**
@ -289,7 +289,7 @@ class Fields extends Structure
* *
* @var array * @var array
*/ */
public $selectionTranslationFixBuilder = array(); public $selectionTranslationFixBuilder = array();
/** /**
* Sort Builder * Sort Builder
@ -868,45 +868,45 @@ class Fields extends Structure
/** /**
* set a field * set a field
* *
* @param string $setType The set of fields type * @param string $setType The set of fields type
* @param array $fieldAttributes The field values * @param array $fieldAttributes The field values
* @param string $name The field name * @param string $name The field name
* @param string $typeName The field type * @param string $typeName The field type
* @param string $langView The language string of the view * @param string $langView The language string of the view
* @param string $viewName The singel view name * @param string $viewName The single view name
* @param string $listViewName The list view name * @param string $listViewName The list view name
* @param array $placeholders The place holder and replace values * @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 string $optionArray The option bucket array used to set the field options if needed.
* @param arra $custom Used when field is from config * @param array $custom Used when field is from config
* *
* @return SimpleXMLElement The field in xml * @return SimpleXMLElement The field in xml
* *
*/ */
private function setField($setType, &$fieldAttributes, &$name, &$typeName, &$langView, &$viewName, &$listViewName, $placeholders, &$optionArray, $custom = null) private function setField($setType, &$fieldAttributes, &$name, &$typeName, &$langView, &$viewName, &$listViewName, $placeholders, &$optionArray, $custom = null)
{ {
$r = new stdClass(); $field = new stdClass();
if ($setType === 'option') if ($setType === 'option')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') if ($property != 'option')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
elseif ($property === 'option') 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) if (strpos($value, ',') !== false)
{ {
// mulitpal options // mulitpal options
$options = explode(',', $value); $options = explode(',', $value);
foreach ($options as $option) foreach ($options as $option)
{ {
$optionXML = $r->fieldXML->addChild('option'); $optionXML = $field->fieldXML->addChild('option');
if (strpos($option, '|') !== false) if (strpos($option, '|') !== false)
{ {
// has other value then text // has other value then text
@ -934,7 +934,7 @@ class Fields extends Structure
else else
{ {
// one option // one option
$optionXML = $r->fieldXML->addChild('option'); $optionXML = $field->fieldXML->addChild('option');
if (strpos($value, '|') !== false) if (strpos($value, '|') !== false)
{ {
// has other value then text // 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') elseif ($setType === 'plain')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') if ($property != 'option')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
} }
} }
elseif ($setType === 'spacer') elseif ($setType === 'spacer')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". A None Database Field. (joomla)"; $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) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') if ($property != 'option')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
} }
} }
@ -999,17 +999,17 @@ class Fields extends Structure
if ($typeName === 'repeatable') if ($typeName === 'repeatable')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (depreciated)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'fields') 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('name', $fieldAttributes['name'] . '_fields');
$fieldsXML->addAttribute('label', ''); $fieldsXML->addAttribute('label', '');
$fieldSetXML = $fieldsXML->addChild('fieldset'); $fieldSetXML = $fieldsXML->addChild('fieldset');
@ -1088,20 +1088,25 @@ class Fields extends Structure
elseif ($typeName === 'subform') elseif ($typeName === 'subform')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)";
// add all properties
foreach ($fieldAttributes as $property => $value) 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 we detect formsource we do not add the form
if (!isset($fieldAttributes['formsource'])) 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( $attributes = array(
'hidden' => 'true', 'hidden' => 'true',
'name' => 'list_' . $fieldAttributes['name'] . '_modal', 'name' => 'list_' . $fieldAttributes['name'] . '_modal',
@ -1181,13 +1186,13 @@ class Fields extends Structure
elseif ($setType === 'custom') elseif ($setType === 'custom')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (custom)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (custom)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') 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 // 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); $this->setCustomFieldTypeFile($data, $listViewName, $viewName);
} }
} }
return $r; return $field;
} }
/** /**
* set the layout builder * set the layout builder
* *
* @param string $viewName The single edit view code name * @param string $viewName The single edit view code name
* @param string $tabName The tab code name * @param string $tabName The tab code name
* @param string $name The field code name * @param string $name The field code name
* @param array $field The field details * @param array $field The field details
* *
* @return void * @return void
* *
@ -1295,10 +1300,10 @@ class Fields extends Structure
/** /**
* build the site field data needed * build the site field data needed
* *
* @param string $view The single edit view code name * @param string $view The single edit view code name
* @param string $field The field name * @param string $field The field name
* @param string $set The decoding set this field belongs to * @param string $set The decoding set this field belongs to
* @param string $type The field type * @param string $type The field type
* *
* @return void * @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) private function setFieldAttributes(&$field, &$viewType, &$name, &$typeName, &$multiple, &$langLabel, $langView, &$spacerCounter, $listViewName, $viewName, $placeholders, $repeatable = false)
{ {
// reset array` // reset array
$fieldAttributes = array(); $fieldAttributes = array();
$setCustom = false; $setCustom = false;
// setup joomla default fields // setup joomla default fields
@ -1469,7 +1474,7 @@ class Fields extends Structure
$name = $this->setPlaceholders($xmlValue, $placeholders); $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'] . '="', '"'); $xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"');
// replace the placeholders // replace the placeholders
@ -1487,7 +1492,7 @@ class Fields extends Structure
// set the line number // set the line number
$phpLine = (int) str_replace('type_phpx_', '', $property['name']); $phpLine = (int) str_replace('type_phpx_', '', $property['name']);
// load the php for the custom field file // 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) elseif ($property['name'] === 'extends' && $setCustom)
{ {
@ -1684,7 +1689,6 @@ class Fields extends Structure
protected function setUniqueNameKeeper(&$field, &$typeName, &$name, $viewName) protected function setUniqueNameKeeper(&$field, &$typeName, &$name, $viewName)
{ {
// setup a default field // setup a default field
$xml = new SimpleXMLElement($field['settings']->xml);
if (ComponentbuilderHelper::checkArray($field['settings']->properties)) if (ComponentbuilderHelper::checkArray($field['settings']->properties))
{ {
foreach ($field['settings']->properties as $property) foreach ($field['settings']->properties as $property)