Added validation rules resolve gh-254. Removed empty sql files. Improved the field area.
This commit is contained in:
@ -414,6 +414,13 @@ class Get
|
||||
*/
|
||||
public $sqlTweak = array();
|
||||
|
||||
/**
|
||||
* The validation rules that should be added
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $validationRules = array();
|
||||
|
||||
/**
|
||||
* The admin views data array
|
||||
*
|
||||
@ -2082,6 +2089,37 @@ class Get
|
||||
|
||||
// load the values form params
|
||||
$field->xml = $this->setDynamicValues(json_decode($field->xml));
|
||||
|
||||
// check if we have validate (validation rule set)
|
||||
$validationRule = ComponentbuilderHelper::getBetween($field->xml, 'validate="', '"');
|
||||
if (ComponentbuilderHelper::checkString($validationRule))
|
||||
{
|
||||
// make sure it is lowercase
|
||||
$validationRule = ComponentbuilderHelper::safeString($validationRule);
|
||||
// make sure it is not already set
|
||||
if (!isset($this->validationRules[$validationRule]))
|
||||
{
|
||||
// get joomla core validation names
|
||||
if ($coreValidationRules = ComponentbuilderHelper::getExistingValidationRuleNames(true))
|
||||
{
|
||||
// make sure this rule is not a core validation rule
|
||||
if (!in_array($validationRule, $coreValidationRules))
|
||||
{
|
||||
// get the class methods for this rule if it exists
|
||||
if ($this->validationRules[$validationRule] = ComponentbuilderHelper::getVar('validation_rule', $validationRule, 'name','php'))
|
||||
{
|
||||
// open and set the validation rule
|
||||
$this->validationRules[$validationRule] = $this->setDynamicValues(base64_decode($this->validationRules[$validationRule]));
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the notice that this validation rule is custom and was not found
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load the type values form type params
|
||||
$field->properties = (isset($field->properties) && ComponentbuilderHelper::checkJson($field->properties)) ? json_decode($field->properties, true) : null;
|
||||
|
@ -2083,6 +2083,15 @@ class Fields extends Structure
|
||||
// get the actual field name
|
||||
$xmlValue = $this->setPlaceholders($name, $placeholders);
|
||||
}
|
||||
elseif ($property['name'] === 'validate')
|
||||
{
|
||||
// check if we have validate (validation rule set)
|
||||
$xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, 'validate="', '"');
|
||||
if (ComponentbuilderHelper::checkString($xmlValue))
|
||||
{
|
||||
$xmlValue = ComponentbuilderHelper::safeString($xmlValue);
|
||||
}
|
||||
}
|
||||
elseif ($property['name'] === 'extension' || $property['name'] === 'directory' || $property['name'] === 'formsource')
|
||||
{
|
||||
$xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"');
|
||||
@ -2290,6 +2299,16 @@ class Fields extends Structure
|
||||
{
|
||||
$fieldAttributes['display'] = $display;
|
||||
}
|
||||
// make sure validation is set if found (even it not part of field properties)
|
||||
if (!isset($fieldAttributes['validate']))
|
||||
{
|
||||
// check if we have validate (validation rule set)
|
||||
$validationRule = ComponentbuilderHelper::getBetween($field['settings']->xml, 'validate="', '"');
|
||||
if (ComponentbuilderHelper::checkString($validationRule))
|
||||
{
|
||||
$fieldAttributes['validate'] = ComponentbuilderHelper::safeString($validationRule);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fieldAttributes;
|
||||
|
@ -815,6 +815,21 @@ class Infusion extends Interpretation
|
||||
// set the module
|
||||
$this->fileContentDynamic['ajax']['###AJAX_SITE_MODEL_METHODS###'] = $this->setAjaxModelMethods('site');
|
||||
}
|
||||
|
||||
// build the validation rules
|
||||
if (isset($this->validationRules) && ComponentbuilderHelper::checkArray($this->validationRules))
|
||||
{
|
||||
foreach ($this->validationRules as $rule => $_php)
|
||||
{
|
||||
// setup rule file
|
||||
$target = array('admin' => 'a_rule_zi');
|
||||
$this->buildDynamique($target, 'rule', $rule);
|
||||
// set the JFormRule Name
|
||||
$this->fileContentDynamic['a_rule_zi_'.$rule]['###Name###'] = ucfirst($rule);
|
||||
// set the JFormRule PHP
|
||||
$this->fileContentDynamic['a_rule_zi_'.$rule]['###VALIDATION_RULE_METHODS###'] = PHP_EOL . $_php;
|
||||
}
|
||||
}
|
||||
|
||||
// run the second run if needed
|
||||
if (isset($this->secondRunAdmin) && ComponentbuilderHelper::checkArray($this->secondRunAdmin))
|
||||
|
@ -157,6 +157,60 @@ abstract class ComponentbuilderHelper
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getExistingValidationRuleNames($lowercase = false)
|
||||
{
|
||||
if (!$items = self::get('_existing_validation_rules_VDM', null))
|
||||
{
|
||||
// load the file class
|
||||
jimport('joomla.filesystem.file');
|
||||
jimport('joomla.filesystem.folder');
|
||||
// set the path to the form validation rules
|
||||
$path = JPATH_LIBRARIES . '/src/Form/Rule';
|
||||
// check if the path exist
|
||||
if (!JFolder::exists($path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// we must first store the current working directory
|
||||
$joomla = getcwd();
|
||||
// go to that folder
|
||||
chdir($path);
|
||||
// load all the files in this path
|
||||
$items = JFolder::files('.', '\.php', true, true);
|
||||
// change back to Joomla working directory
|
||||
chdir($joomla);
|
||||
// make sure we have an array
|
||||
if (!self::checkArray($items))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// remove the Rule.php from the name
|
||||
$items = array_map( function ($name) {
|
||||
return str_replace(array('./','Rule.php'), '', $name);
|
||||
}, $items);
|
||||
// store the names for next run
|
||||
self::set('_existing_validation_rules_VDM', json_encode($items));
|
||||
}
|
||||
// make sure it is no longer json
|
||||
if (self::checkJson($items))
|
||||
{
|
||||
$items = json_decode($items, true);
|
||||
}
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
$items = array_map( function($item) {
|
||||
return strtolower($item);
|
||||
}, $items);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function getDynamicScripts($type, $fieldName = false)
|
||||
{
|
||||
@ -1626,10 +1680,13 @@ abstract class ComponentbuilderHelper
|
||||
{
|
||||
$result = $db->loadObject();
|
||||
$properties = json_decode($result->properties,true);
|
||||
$field = array('values' => "<field ", 'values_description' => '<ul>', 'short_description' => $result->short_description, 'description' => $result->description);
|
||||
$field = array('values' => "<field ", 'values_description' => '<table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">', 'short_description' => $result->short_description, 'description' => $result->description);
|
||||
// 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)
|
||||
{
|
||||
$field['values_description'] .= '<li><b>'.$property['name'].'</b> '.$property['description'].'</li>';
|
||||
$example = (isset($property['example']) && self::checkString($property['example'])) ? '<code>'.$property['example'].'</code>' : '';
|
||||
$field['values_description'] .= '<tr><td class="uk-text-right"><code>'.$property['name'].'</code></td><td>'.$example.'</td><td>'.$property['description'].'</td></tr>';
|
||||
if(isset($settings[$property['name']]))
|
||||
{
|
||||
$field['values'] .= "\n\t".$property['name'].'="'.$settings[$property['name']].'" ';
|
||||
@ -1640,7 +1697,7 @@ abstract class ComponentbuilderHelper
|
||||
}
|
||||
}
|
||||
$field['values'] .= "\n/>";
|
||||
$field['values_description'] .= '</ul>';
|
||||
$field['values_description'] .= '</tbody></table>';
|
||||
// return found field options
|
||||
return $field;
|
||||
}
|
||||
@ -2814,6 +2871,10 @@ abstract class ComponentbuilderHelper
|
||||
{
|
||||
JHtmlSidebar::addEntry(JText::_('COM_COMPONENTBUILDER_SUBMENU_GET_SNIPPETS'), 'index.php?option=com_componentbuilder&view=get_snippets', $submenu === 'get_snippets');
|
||||
}
|
||||
if ($user->authorise('validation_rule.access', 'com_componentbuilder') && $user->authorise('validation_rule.submenu', 'com_componentbuilder'))
|
||||
{
|
||||
JHtmlSidebar::addEntry(JText::_('COM_COMPONENTBUILDER_SUBMENU_VALIDATION_RULES'), 'index.php?option=com_componentbuilder&view=validation_rules', $submenu === 'validation_rules');
|
||||
}
|
||||
if ($user->authorise('field.access', 'com_componentbuilder') && $user->authorise('field.submenu', 'com_componentbuilder'))
|
||||
{
|
||||
JHtmlSidebar::addEntry(JText::_('COM_COMPONENTBUILDER_SUBMENU_FIELDS'), 'index.php?option=com_componentbuilder&view=fields', $submenu === 'fields');
|
||||
|
Reference in New Issue
Block a user