Added the option to import JCB packages with GUID mapping. Resolved gh-657 to allow for painless fieldtype change in the field area.

This commit is contained in:
2021-08-11 14:15:35 +02:00
parent 576eac1a5a
commit b64e423f51
51 changed files with 345 additions and 155 deletions

View File

@ -604,7 +604,7 @@ class ComponentbuilderModelAjax extends JModelList
'before' => array('table' => 'admin_view', 'tables' => 'admin_views', 'id' => 'id', 'name' => 'system_name', 'text' => 'Admin View')
);
protected function checkRepeatableConversion(&$fieldsData, $fieldsArrayType, $id, $linked_id_name)
protected function checkRepeatableConversion($type, &$fieldsData, $fieldsArrayType, $id, $linked_id_name)
{
if (ComponentbuilderHelper::checkJson($fieldsData) && isset($this->conversionCheck[$fieldsArrayType]))
{
@ -624,7 +624,7 @@ class ComponentbuilderModelAjax extends JModelList
$objectUpdate = new stdClass();
$objectUpdate->{$linked_id_name} = (int) $id;
$objectUpdate->{$fieldsArrayType} = $fieldsData;
JFactory::getDbo()->updateObject('#__componentbuilder_'.$type, $objectUpdate, 'admin_view');
JFactory::getDbo()->updateObject('#__componentbuilder_' . $type, $objectUpdate, 'admin_view');
}
}
}
@ -1733,7 +1733,7 @@ class ComponentbuilderModelAjax extends JModelList
// check repeatable conversion
if (method_exists(__CLASS__, 'checkRepeatableConversion'))
{
$this->checkRepeatableConversion($fieldsData, $fieldName, $id, $idName);
$this->checkRepeatableConversion($type, $fieldsData, $fieldName, $id, $idName);
}
// get the table
$table = $this->getSubformTable($type, $fieldsData);
@ -2180,8 +2180,8 @@ class ComponentbuilderModelAjax extends JModelList
{
// reset the buttons bucket
$buttons = array();
// some helper for some fields
$helper = array('xml' => 'note_select_field_type');
// some helper for some fields (I am sorry)
$helper = array('xml' => 'note_filter_information');
// get input
$jinput = JFactory::getApplication()->input;
$return_here = $jinput->get('return_here', null, 'base64');
@ -2235,10 +2235,14 @@ class ComponentbuilderModelAjax extends JModelList
// check if field has string length
if (ComponentbuilderHelper::checkString($value))
{
$buttons[$key] = array();
// see if the field needs some help :)
$_key = (isset($helper[$key])) ? $helper[$key] : $key;
// build the buttons
$buttons[$_key] = array();
if (($button = $this->getButton('custom_code', 3)) && ComponentbuilderHelper::checkString($button))
{
$buttons[$key]['_create'] = $button;
$buttons[$_key]['_create'] = $button;
}
}
}
@ -2248,15 +2252,16 @@ class ComponentbuilderModelAjax extends JModelList
{
foreach ($bucket as $field => $customcodes)
{
$edit_icon = '<span class="icon-edit" aria-hidden="true"></span> ';
// see if the field needs some help :)
if (isset($helper[$field]))
{
$field = $helper[$field];
}
$field = (isset($helper[$field])) ? $helper[$field] : $field;
// set the edit icon
$edit_icon = '<span class="icon-edit" aria-hidden="true"></span> ';
// load the buttons found
foreach ($customcodes as $customcode)
{
// get the customcode name
$key = (array) explode('+', $customcode);
// see if we can get the button
if (!isset($buttons[$field][$key[0]]) && ($_id = ComponentbuilderHelper::getVar('custom_code', $key[0], 'function_name')) !== false
&& ($button = ComponentbuilderHelper::getEditTextButton($edit_icon . $key[0], $_id, 'custom_code', 'custom_codes', $return_here, 'com_componentbuilder', false, 'btn btn-small button-edit" style="margin: 0 0 5px 0;'))
&& ComponentbuilderHelper::checkString($button))
@ -3225,15 +3230,23 @@ class ComponentbuilderModelAjax extends JModelList
{
// first check field type
$_fieldType = ComponentbuilderHelper::getVar('field', $global['a_id'], 'id', 'fieldtype');
// only continue if field type is the same
if ($fieldtype == $_fieldType)
$xmlDB = ComponentbuilderHelper::getVar('field', $global['a_id'], 'id', 'xml');
// check if it is a string
if (ComponentbuilderHelper::checkString($xmlDB))
{
$xmlDB = ComponentbuilderHelper::getVar('field', $global['a_id'], 'id', 'xml');
// check if it is a string
if (ComponentbuilderHelper::checkString($xmlDB))
{
$xml = json_decode($xmlDB);
}
$xml = json_decode($xmlDB);
}
// remove the field type if not the same
if ($xml && $fieldtype != $_fieldType)
{
// unset some stuff
$pattern = array();
$pattern[] = '/type=".+?"/i'; // to force the new type to be set
$pattern[] = '/class=".+?"/i'; // to remove all classes
$pattern[] = '/type_php.+?".+?"/i'; // to remove any PHP code stuff
// also add a special switch to force adding all properties of the new type
$xml = preg_replace($pattern, '..__FORCE_LOAD_ALL_PROPERTIES__..', $xml);
}
}
return $xml;