Skip to content

Commit

Permalink
Improved the custom-custom field implementation, to allow duplicate f…
Browse files Browse the repository at this point in the history
…ields to be use in sub-forms and in same form/view with the correct expected behavior of incremental naming, only if in same sub-form or form/view. gh-341
  • Loading branch information
Llewellynvdm committed Oct 1, 2018
1 parent 0436868 commit d7665fe
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -125,7 +125,7 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015
+ *Last Build*: 29th September, 2018
+ *Last Build*: 1st October, 2018
+ *Version*: 2.9.6
+ *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
Expand Down
2 changes: 1 addition & 1 deletion admin/README.txt
Expand Up @@ -125,7 +125,7 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015
+ *Last Build*: 29th September, 2018
+ *Last Build*: 1st October, 2018
+ *Version*: 2.9.6
+ *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
Expand Down
103 changes: 64 additions & 39 deletions admin/helpers/compiler/a_Get.php
Expand Up @@ -1177,22 +1177,14 @@ public function getComponentData()
$component->addconfig = (isset($component->addconfig) && ComponentbuilderHelper::checkJson($component->addconfig)) ? json_decode($component->addconfig, true) : null;
if (ComponentbuilderHelper::checkArray($component->addconfig))
{
$component->config = array_map(function($field)
{
// set hash
static $hash = 1;
// load hash
$field['hash'] = md5($field['field'] . $hash);
// increment hash
$hash++;
$component->config = array_map(function($field) {
// make sure the alias and title is 0
$field['alias'] = 0;
$field['title'] = 0;
// load the settings
$field['settings'] = $this->getFieldData($field['field']);
// set real field name
$field['base_name'] = $this->getFieldName($field);
// set unigue name keeper
$this->setUniqueNameCounter($this->getFieldName($field), 'configs');
// set the field details
$this->setFieldDetails($field);
// set unique name counter
$this->setUniqueNameCounter($field['base_name'], 'configs');
// return field
return $field;
}, array_values($component->addconfig));
Expand Down Expand Up @@ -1669,23 +1661,8 @@ public function getAdminViewData($id)
// load the field data
$view->fields = array_map(function($field) use($name_single, $name_list, &$ignoreFields)
{
// set hash
static $hash = 123467890; // (TODO) I found this making duplicates
// load hash
$field['hash'] = md5($field['field'] . $hash);
// increment hash
$hash++;
// set the settings
$field['settings'] = $this->getFieldData($field['field'], $name_single, $name_list);
// set real field name
$field['base_name'] = $this->getFieldName($field);
// set code name for field type
$field['type_name'] = $this->getFieldType($field);
// check if value is array
if (isset($field['permission']) && !ComponentbuilderHelper::checkArray($field['permission']) && is_numeric($field['permission']) && $field['permission'] > 0)
{
$field['permission'] = array($field['permission']);
}
// set the field details
$this->setFieldDetails($field, $name_single, $name_list);
// check if this field is a default field OR
// check if this is none database related field
if (in_array($field['base_name'], $this->defaultFields) ||
Expand All @@ -1694,8 +1671,6 @@ public function getAdminViewData($id)
{
$ignoreFields[$field['field']] = $field['field'];
}
// set unigue name keeper
$this->setUniqueNameCounter($field['base_name'], $name_list);
// return field
return $field;
}, array_values($view->addfields));
Expand Down Expand Up @@ -2673,6 +2648,55 @@ public function getFieldData($id, $name_single = null, $name_list = null)
return false;
}

/**
* set Field details
*
* @param object $field The field object
* @param string $singleViewName The single view name
* @param string $listViewName The list view name
* @param string $amicably The peaceful resolve
*
* @return void
*
*/
public function setFieldDetails(&$field, $singleViewName = null, $listViewName = null, $amicably = '')
{
// set hash
static $hash = 123467890;
// load hash if not found
if (!isset($field['hash']))
{
$field['hash'] = md5($field['field'] . $hash);
// increment hash
$hash++;
}
// set the settings
if (!isset($field['settings']))
{
$field['settings'] = $this->getFieldData($field['field'], $singleViewName, $listViewName);
}
// set real field name
if (!isset($field['base_name']))
{
$field['base_name'] = $this->getFieldName($field);
}
// set code name for field type
if (!isset($field['type_name']))
{
$field['type_name'] = $this->getFieldType($field);
}
// check if value is array
if (isset($field['permission']) && !ComponentbuilderHelper::checkArray($field['permission']) && is_numeric($field['permission']) && $field['permission'] > 0)
{
$field['permission'] = array($field['permission']);
}
// set unigue name keeper
if ($listViewName)
{
$this->setUniqueNameCounter($field['base_name'], $listViewName . $amicably);
}
}

/**
* Get the field's actual type
*
Expand All @@ -2695,7 +2719,7 @@ public function getFieldType(&$field)
if (strpos($field['settings']->type_name, '@') !== false)
{
// set own custom field
$field['own_custom'] = $field['settings']->type_name;
$field['settings']->own_custom = $field['settings']->type_name;
$field['settings']->type_name = 'Custom';
}
// set the type name
Expand Down Expand Up @@ -2748,16 +2772,17 @@ public function getFieldType(&$field)
*
* @param object $field The field object
* @param string $listViewName The list view name
* @param string $amicably The peaceful resolve
*
* @return string Success returns field name
*
*/
public function getFieldName(&$field, $listViewName = null)
public function getFieldName(&$field, $listViewName = null, $amicably = '')
{
// return the unique name if already set
if (ComponentbuilderHelper::checkString($listViewName) && isset($field['hash']) && isset($this->uniqueFieldNames[$listViewName . $field['hash']]))
if (ComponentbuilderHelper::checkString($listViewName) && isset($field['hash']) && isset($this->uniqueFieldNames[$listViewName . $amicably . $field['hash']]))
{
return $this->uniqueFieldNames[$listViewName . $field['hash']];
return $this->uniqueFieldNames[$listViewName . $amicably . $field['hash']];
}
// always make sure we have a field name and type
if (!isset($field['settings']) || !isset($field['settings']->type_name) || !isset($field['settings']->name))
Expand Down Expand Up @@ -2834,9 +2859,9 @@ public function getFieldName(&$field, $listViewName = null)
// return the value unique
if (ComponentbuilderHelper::checkString($listViewName) && isset($field['hash']))
{
$this->uniqueFieldNames[$listViewName . $field['hash']] = $this->uniqueName($name, $listViewName);
$this->uniqueFieldNames[$listViewName . $amicably . $field['hash']] = $this->uniqueName($name, $listViewName . $amicably);
// now return the unique name
return $this->uniqueFieldNames[$listViewName . $field['hash']];
return $this->uniqueFieldNames[$listViewName . $amicably . $field['hash']];
}
// fall back to global
return $name;
Expand Down
86 changes: 66 additions & 20 deletions admin/helpers/compiler/c_Fields.php
Expand Up @@ -1353,13 +1353,25 @@ protected function stringSetField($setType, &$fieldAttributes, &$name, &$typeNam
// only continue if we have a field set
if (ComponentbuilderHelper::checkArray($fieldsSets))
{
foreach ($fieldsSets as $fieldId)
// set the resolver
$_resolverKey = $fieldAttributes['name'];
// load the field data
$fieldsSets = array_map(function($id) use($view_name_single, $view_name_list, $_resolverKey) {
// start field
$field = array();
$field['field'] = $id;
// set the field details
$this->setFieldDetails($field, $view_name_single, $view_name_list, $_resolverKey);
// return field
return $field;
}, array_values($fieldsSets));
// start the build
foreach ($fieldsSets as $fieldData)
{
// get the field data
$fieldData['settings'] = $this->getFieldData($fieldId, $view_name_single);
// if we have settings continue
if (ComponentbuilderHelper::checkObject($fieldData['settings']))
{
$r_name = $this->getFieldName($fieldData);
$r_name = $this->getFieldName($fieldData, $view_name_list, $_resolverKey);
$r_typeName = $this->getFieldType($fieldData);
$r_multiple = false;
$r_langLabel = '';
Expand Down Expand Up @@ -1440,13 +1452,25 @@ protected function stringSetField($setType, &$fieldAttributes, &$name, &$typeNam
// only continue if we have a field set
if (ComponentbuilderHelper::checkArray($fieldsSets))
{
foreach ($fieldsSets as $fieldId)
// set the resolver
$_resolverKey = $fieldAttributes['name'];
// load the field data
$fieldsSets = array_map(function($id) use($view_name_single, $view_name_list, $_resolverKey) {
// start field
$field = array();
$field['field'] = $id;
// set the field details
$this->setFieldDetails($field, $view_name_single, $view_name_list, $_resolverKey);
// return field
return $field;
}, array_values($fieldsSets));
// start the build
foreach ($fieldsSets as $fieldData)
{
// get the field data
$fieldData['settings'] = $this->getFieldData($fieldId, $view_name_single);
// if we have settings continue
if (ComponentbuilderHelper::checkObject($fieldData['settings']))
{
$r_name = $this->getFieldName($fieldData);
$r_name = $this->getFieldName($fieldData, $view_name_list, $_resolverKey);
$r_typeName = $this->getFieldType($fieldData);
$r_multiple = false;
$r_langLabel = '';
Expand Down Expand Up @@ -1691,14 +1715,25 @@ protected function simpleXMLSetField($setType, &$fieldAttributes, &$name, &$type
// only continue if we have a field set
if (ComponentbuilderHelper::checkArray($fieldsSets))
{
foreach ($fieldsSets as $fieldId)
// set the resolver
$_resolverKey = $fieldAttributes['name'];
// load the field data
$fieldsSets = array_map(function($id) use($view_name_single, $view_name_list, $_resolverKey) {
// start field
$field = array();
$field['field'] = $id;
// set the field details
$this->setFieldDetails($field, $view_name_single, $view_name_list, $_resolverKey);
// return field
return $field;
}, array_values($fieldsSets));
// start the build
foreach ($fieldsSets as $fieldData)
{
// get the field data
$fieldData = array();
$fieldData['settings'] = $this->getFieldData($fieldId, $view_name_single);
// if we have settings continue
if (ComponentbuilderHelper::checkObject($fieldData['settings']))
{
$r_name = $this->getFieldName($fieldData);
$r_name = $this->getFieldName($fieldData, $view_name_list, $_resolverKey);
$r_typeName = $this->getFieldType($fieldData);
$r_multiple = false;
$r_langLabel = '';
Expand Down Expand Up @@ -1788,14 +1823,25 @@ protected function simpleXMLSetField($setType, &$fieldAttributes, &$name, &$type
// only continue if we have a field set
if (ComponentbuilderHelper::checkArray($fieldsSets))
{
foreach ($fieldsSets as $fieldId)
// set the resolver
$_resolverKey = $fieldAttributes['name'];
// load the field data
$fieldsSets = array_map(function($id) use($view_name_single, $view_name_list, $_resolverKey) {
// start field
$field = array();
$field['field'] = $id;
// set the field details
$this->setFieldDetails($field, $view_name_single, $view_name_list, $_resolverKey);
// return field
return $field;
}, array_values($fieldsSets));
// start the build
foreach ($fieldsSets as $fieldData)
{
// get the field data
$fieldData = array();
$fieldData['settings'] = $this->getFieldData($fieldId, $view_name_single);
// if we have settings continue
if (ComponentbuilderHelper::checkObject($fieldData['settings']))
{
$r_name = $this->getFieldName($fieldData);
$r_name = $this->getFieldName($fieldData, $view_name_list, $_resolverKey);
$r_typeName = $this->getFieldType($fieldData);
$r_multiple = false;
$r_langLabel = '';
Expand Down Expand Up @@ -2052,9 +2098,9 @@ private function setFieldAttributes(&$field, &$viewType, &$name, &$typeName, &$m
{
$fieldAttributes['custom'] = array();
// is this an own custom field
if (isset($field['own_custom']))
if (isset($field['settings']->own_custom))
{
$fieldAttributes['custom']['own_custom'] = $field['own_custom'];
$fieldAttributes['custom']['own_custom'] = $field['settings']->own_custom;
}
$setCustom = true;
}
Expand Down
2 changes: 1 addition & 1 deletion componentbuilder.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name>
<creationDate>29th September, 2018</creationDate>
<creationDate>1st October, 2018</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>
Expand Down

0 comments on commit d7665fe

Please sign in to comment.