From d7665fe88ddcf8fd74d6456c3d8c2da80ece0c56 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 1 Oct 2018 04:16:24 +0200 Subject: [PATCH] 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 --- README.md | 2 +- admin/README.txt | 2 +- admin/helpers/compiler/a_Get.php | 103 +++++++++++++++++----------- admin/helpers/compiler/c_Fields.php | 86 +++++++++++++++++------ componentbuilder.xml | 2 +- 5 files changed, 133 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 1e5302dab..f492e76e4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/admin/README.txt b/admin/README.txt index 1e5302dab..f492e76e4 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -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 diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 9b50685d0..9e606c6ca 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -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; diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index 64b106ad9..9a31387ff 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -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; } diff --git a/componentbuilder.xml b/componentbuilder.xml index 2986d9b12..ad74786d5 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 29th September, 2018 + 1st October, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com