Urgent fix to the fields area to address the extra field options, and fields with 0 being removed. Added the option to add a field and not add it to the database, so it will show in the edit view but will not be stored to the database. This is to use javascript/php to use that field value, and then drop it.

This commit is contained in:
2018-04-13 17:24:06 +02:00
parent 51d13b75f0
commit 694612aff9
31 changed files with 515 additions and 300 deletions

View File

@@ -2343,7 +2343,14 @@ class Fields extends Structure
*/
public function setBuilders($langLabel, $langView, $view_name_single, $view_name_list, $name, $view, $field, $typeName, $multiple, $custom = false, $options = false)
{
if ($typeName === 'tag')
// dbSwitch
$dbSwitch = true;
if (isset($field['list']) && $field['list'] == 2)
{
// do not add this field to the database
$dbSwitch = false;
}
elseif ($typeName === 'tag')
{
// set tags for this view but don't load to DB
$this->tagsBuilder[$view_name_single] = $view_name_single;
@@ -2402,12 +2409,12 @@ class Fields extends Structure
$this->historyBuilder[$view_name_single] = $view_name_single;
}
// set Alias (only one title per view)
if (isset($field['alias']) && $field['alias'] && !isset($this->aliasBuilder[$view_name_single]))
if ($dbSwitch && isset($field['alias']) && $field['alias'] && !isset($this->aliasBuilder[$view_name_single]))
{
$this->aliasBuilder[$view_name_single] = $name;
}
// set Titles (only one title per view)
if (isset($field['title']) && $field['title'] && !isset($this->titleBuilder[$view_name_single]))
if ($dbSwitch && isset($field['title']) && $field['title'] && !isset($this->titleBuilder[$view_name_single]))
{
$this->titleBuilder[$view_name_single] = $name;
}
@@ -2467,7 +2474,7 @@ class Fields extends Structure
$this->hiddenFieldsBuilder[$view_name_single] .= ',"' . $name . '"';
}
// set all int fields of this view
if ($field['settings']->datatype === 'INT' || $field['settings']->datatype === 'TINYINT' || $field['settings']->datatype === 'BIGINT')
if ($dbSwitch && ($field['settings']->datatype === 'INT' || $field['settings']->datatype === 'TINYINT' || $field['settings']->datatype === 'BIGINT'))
{
if (!isset($this->intFieldsBuilder[$view_name_single]))
{
@@ -2493,7 +2500,7 @@ class Fields extends Structure
}
// TODO we may need to add a switch instead (since now it uses the first editor field)
// set the main(biggest) text field of this view
if ($typeName === 'editor')
if ($dbSwitch && $typeName === 'editor')
{
if (!isset($this->maintextBuilder[$view_name_single]) || !ComponentbuilderHelper::checkString($this->maintextBuilder[$view_name_single]))
{
@@ -2525,7 +2532,7 @@ class Fields extends Structure
$this->setScriptMediaSwitch[$typeName] = $typeName;
}
// setup gategory for this view
if ($typeName === 'category')
if ($dbSwitch && $typeName === 'category')
{
if (isset($this->catOtherName[$view_name_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$view_name_list]))
{
@@ -2542,12 +2549,12 @@ class Fields extends Structure
$this->catCodeBuilder[$view_name_single] = array('code' => $name, 'views' => $otherViews, 'view' => $otherView);
}
// setup checkbox for this view
if ($typeName === 'checkbox' || (ComponentbuilderHelper::checkArray($custom) && isset($custom['extends']) && $custom['extends'] === 'checkboxes'))
if ($dbSwitch && ($typeName === 'checkbox' || (ComponentbuilderHelper::checkArray($custom) && isset($custom['extends']) && $custom['extends'] === 'checkboxes')))
{
$this->checkboxBuilder[$view_name_single][] = $name;
}
// setup checkboxes and other json items for this view
if (($typeName === 'subform' || $typeName === 'checkboxes' || $multiple || $field['settings']->store != 0) && $typeName != 'tag')
if ($dbSwitch && (($typeName === 'subform' || $typeName === 'checkboxes' || $multiple || $field['settings']->store != 0) && $typeName != 'tag'))
{
switch ($field['settings']->store)
{
@@ -2614,7 +2621,7 @@ class Fields extends Structure
}
}
// build the data for the export & import methods $typeName === 'repeatable' ||
if (($typeName === 'checkboxes' || $multiple || $field['settings']->store != 0) && !ComponentbuilderHelper::checkArray($options))
if ($dbSwitch && (($typeName === 'checkboxes' || $multiple || $field['settings']->store != 0) && !ComponentbuilderHelper::checkArray($options)))
{
$this->getItemsMethodEximportStringFixBuilder[$view_name_single][] = array('name' => $name, 'type' => $typeName, 'translation' => false, 'custom' => $custom, 'method' => $field['settings']->store);
}
@@ -2626,18 +2633,18 @@ class Fields extends Structure
$this->selectionTranslationFixBuilder[$view_name_list][$name] = $options;
}
// build the sort values
if ((isset($field['sort']) && $field['sort'] == 1) && (isset($field['list']) && $field['list'] == 1) && (!$multiple && $typeName != 'checkbox' && $typeName != 'checkboxes' && $typeName != 'repeatable' && $typeName != 'subform'))
if ($dbSwitch && (isset($field['sort']) && $field['sort'] == 1) && (isset($field['list']) && $field['list'] == 1) && (!$multiple && $typeName != 'checkbox' && $typeName != 'checkboxes' && $typeName != 'repeatable' && $typeName != 'subform'))
{
$this->sortBuilder[$view_name_list][] = array('type' => $typeName, 'code' => $name, 'lang' => $listLangName, 'custom' => $custom, 'options' => $options);
}
// build the search values
if (isset($field['search']) && $field['search'] == 1)
if ($dbSwitch && isset($field['search']) && $field['search'] == 1)
{
$_list = (isset($field['list'])) ? $field['list'] : 0;
$this->searchBuilder[$view_name_list][] = array('type' => $typeName, 'code' => $name, 'custom' => $custom, 'list' => $_list);
}
// build the filter values
if ((isset($field['filter']) && $field['filter'] == 1) && (isset($field['list']) && $field['list'] == 1) && (!$multiple && $typeName != 'checkbox' && $typeName != 'checkboxes' && $typeName != 'repeatable' && $typeName != 'subform'))
if ($dbSwitch && (isset($field['filter']) && $field['filter'] == 1) && (isset($field['list']) && $field['list'] == 1) && (!$multiple && $typeName != 'checkbox' && $typeName != 'checkboxes' && $typeName != 'repeatable' && $typeName != 'subform'))
{
$this->filterBuilder[$view_name_list][] = array('type' => $typeName, 'code' => $name, 'lang' => $listLangName, 'database' => $view_name_single, 'function' => ComponentbuilderHelper::safeString($name, 'F'), 'custom' => $custom, 'options' => $options);
}

View File

@@ -1162,8 +1162,7 @@ class Infusion extends Interpretation
}
/**
* Build the lang values and insert to fiel
*
* Build the language values and insert into file
*
* @return boolean on success
*
@@ -1211,6 +1210,8 @@ class Infusion extends Interpretation
$langXML = array();
foreach ($this->languages as $tag => $areas)
{
// trim the tag
$tag = trim($tag);
foreach ($areas as $area => $languageStrings)
{
// only log messages for none en-GB translations
@@ -1264,13 +1265,11 @@ class Infusion extends Interpretation
// count the file created
$this->fileCount++;
// add content to it
$lang = '';
foreach ($languageStrings as $place => $string)
{
$lang .= $place . '="' . $string . '"' . PHP_EOL;
}
$lang = array_map(function ($langstring, $placeholder) {
return $placeholder . '="' . $langstring . '"';
}, $languageStrings, array_keys($languageStrings));
// add to language file
$this->writeFile($path . '/' . $fileName, $lang);
$this->writeFile($path . '/' . $fileName, implode(PHP_EOL, $lang));
// set the line counter
$this->lineCount = $this->lineCount + substr_count($lang, PHP_EOL);
// build xml strings

View File

@@ -1606,6 +1606,8 @@ abstract class ComponentbuilderHelper
'description' => $result->description);
// number pointer
$nr = 0;
// value to check since there are false and null values even 0 in the values returned
$confirmation = '8qvZHoyuFYQqpj0YQbc6F3o5DhBlmS-_-a8pmCZfOVSfANjkmV5LG8pCdAY2JNYu6cB';
// set the headers
$field['values_description'] .= '<thead><tr><th class="uk-text-right">'.JText::_('COM_COMPONENTBUILDER_PROPERTY').'</th><th>'.JText::_('COM_COMPONENTBUILDER_EXAMPLE').'</th><th>'.JText::_('COM_COMPONENTBUILDER_DESCRIPTION').'</th></thead><tbody>';
foreach ($properties as $property)
@@ -1613,7 +1615,7 @@ abstract class ComponentbuilderHelper
$example = (isset($property['example']) && self::checkString($property['example'])) ? self::shorten($property['example'], 30) : '';
$field['values_description'] .= '<tr><td class="uk-text-right"><code>'.$property['name'].'</code></td><td>'.$example.'</td><td>'.$property['description'].'</td></tr>';
// check if we should load the value
$value = self::getValueFromXMLstring($xml, $property['name']);
$value = self::getValueFromXMLstring($xml, $property['name'], $confirmation);
if(self::checkArray($settings) && isset($settings[$property['name']]))
{
// add the xml values
@@ -1623,12 +1625,12 @@ abstract class ComponentbuilderHelper
// add the name List Options as set
$field['nameListOptionsSet'][$property['name']] = $property['name'];
}
elseif (!$xml || $value)
elseif (!$xml || $confirmation !== $value)
{
// add the xml values
$field['values'] .= "\n\t" . $property['name'] . '="'. ($value) ? $value : $property['example'] .'" ';
$field['values'] .= "\n\t" . $property['name'] . '="'. ($confirmation !== $value) ? $value : $property['example'] .'" ';
// add the json values
$field['subform']['properties' . $nr] = array('name' => $property['name'], 'value' => ($value) ? $value : $property['example'], 'desc' => $property['description']);
$field['subform']['properties' . $nr] = array('name' => $property['name'], 'value' => ($confirmation !== $value) ? $value : $property['example'], 'desc' => $property['description']);
}
// add the name List Options
$field['nameListOptions'][$property['name']] = $property['name'];
@@ -1643,17 +1645,13 @@ abstract class ComponentbuilderHelper
return false;
}
public static function getValueFromXMLstring($xml, $get)
public static function getValueFromXMLstring($xml, $get, $confirmation)
{
if (self::checkString($xml))
{
$value = self::getBetween($xml, $get.'="', '"');
if (self::checkString($value))
{
return $value;
}
return self::getBetween($xml, $get.'="', '"', $confirmation);
}
return false;
return $confirmation;
}
@@ -1833,11 +1831,12 @@ abstract class ComponentbuilderHelper
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
* @param string $default The default value if none found
*
* @return string On success / empty string on failure
*
*/
public static function getBetween($content, $start, $end)
public static function getBetween($content, $start, $end, $default = '')
{
$r = explode($start, $content);
if (isset($r[1]))
@@ -1845,7 +1844,7 @@ abstract class ComponentbuilderHelper
$r = explode($end, $r[1]);
return $r[0];
}
return '';
return $default;
}
/**