Improved the custom-custom field implementation, to allow duplicate fields 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

This commit is contained in:
Llewellyn van der Merwe 2018-10-01 04:16:24 +02:00
parent 043686814c
commit d7665fe88d
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
5 changed files with 133 additions and 62 deletions

View File

@ -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

View File

@ -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

View File

@ -1177,22 +1177,14 @@ class Get
$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));
@ -1669,23 +1661,8 @@ class Get
// 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) ||
@ -1694,8 +1671,6 @@ class Get
{
$ignoreFields[$field['field']] = $field['field'];
}
// set unigue name keeper
$this->setUniqueNameCounter($field['base_name'], $name_list);
// return field
return $field;
}, array_values($view->addfields));
@ -2673,6 +2648,55 @@ class Get
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
*
@ -2695,7 +2719,7 @@ class Get
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
@ -2748,16 +2772,17 @@ class Get
*
* @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))
@ -2834,9 +2859,9 @@ class Get
// 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;

View File

@ -1353,13 +1353,25 @@ class Fields extends Structure
// 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 = '';
@ -1440,13 +1452,25 @@ class Fields extends Structure
// 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 = '';
@ -1691,14 +1715,25 @@ class Fields extends Structure
// 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 = '';
@ -1788,14 +1823,25 @@ class Fields extends Structure
// 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 = '';
@ -2052,9 +2098,9 @@ class Fields extends Structure
{
$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;
}

View File

@ -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>