Improved the plugin form builder, to allow multi form field relationships.

This commit is contained in:
2019-08-22 03:54:47 +02:00
parent c13c752abb
commit d2f94d84fa
65 changed files with 1225 additions and 431 deletions

View File

@ -363,6 +363,8 @@ class ComponentbuilderModelAdmin_custom_tabs extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.admin_custom_tabs', $data);
}
return $data;

View File

@ -384,6 +384,8 @@ class ComponentbuilderModelAdmin_fields extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.admin_fields', $data);
}
return $data;

View File

@ -384,6 +384,8 @@ class ComponentbuilderModelAdmin_fields_conditions extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.admin_fields_conditions', $data);
}
return $data;

View File

@ -395,6 +395,8 @@ class ComponentbuilderModelAdmin_fields_relations extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.admin_fields_relations', $data);
}
return $data;

View File

@ -893,6 +893,8 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.admin_view', $data);
}
return $data;

View File

@ -426,6 +426,8 @@ class ComponentbuilderModelClass_extends extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.class_extends', $data);
}
return $data;

View File

@ -435,6 +435,8 @@ class ComponentbuilderModelClass_method extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.class_method', $data);
}
return $data;

View File

@ -426,6 +426,8 @@ class ComponentbuilderModelClass_property extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.class_property', $data);
}
return $data;

View File

@ -395,6 +395,8 @@ class ComponentbuilderModelComponent_admin_views extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_admin_views', $data);
}
return $data;

View File

@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_config extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_config', $data);
}
return $data;

View File

@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_custom_admin_menus extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_custom_admin_menus', $data);
}
return $data;

View File

@ -395,6 +395,8 @@ class ComponentbuilderModelComponent_custom_admin_views extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_custom_admin_views', $data);
}
return $data;

View File

@ -432,6 +432,8 @@ class ComponentbuilderModelComponent_dashboard extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_dashboard', $data);
}
return $data;

View File

@ -431,6 +431,8 @@ class ComponentbuilderModelComponent_files_folders extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_files_folders', $data);
}
return $data;

View File

@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_mysql_tweaks extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_mysql_tweaks', $data);
}
return $data;

View File

@ -363,6 +363,8 @@ class ComponentbuilderModelComponent_placeholders extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_placeholders', $data);
}
return $data;

View File

@ -364,6 +364,8 @@ class ComponentbuilderModelComponent_plugins extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_plugins', $data);
}
return $data;

View File

@ -395,6 +395,8 @@ class ComponentbuilderModelComponent_site_views extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_site_views', $data);
}
return $data;

View File

@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_updates extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.component_updates', $data);
}
return $data;

View File

@ -599,6 +599,8 @@ class ComponentbuilderModelCustom_admin_view extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.custom_admin_view', $data);
}
return $data;

View File

@ -435,6 +435,8 @@ class ComponentbuilderModelCustom_code extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.custom_code', $data);
}
return $data;

View File

@ -613,6 +613,8 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.dynamic_get', $data);
}
return $data;

View File

@ -483,6 +483,8 @@ class ComponentbuilderModelField extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.field', $data);
}
return $data;

View File

@ -26,7 +26,111 @@ class JFormFieldJoomlaplugins extends JFormFieldList
*
* @var string
*/
public $type = 'joomlaplugins';
public $type = 'joomlaplugins';
/**
* Override to add new button
*
* @return string The field input markup.
*
* @since 3.2
*/
protected function getInput()
{
// see if we should add buttons
$set_button = $this->getAttribute('button');
// get html
$html = parent::getInput();
// if true set button
if ($set_button === 'true')
{
$button = array();
$script = array();
$button_code_name = $this->getAttribute('name');
// get the input from url
$app = JFactory::getApplication();
$jinput = $app->input;
// get the view name & id
$values = $jinput->getArray(array(
'id' => 'int',
'view' => 'word'
));
// check if new item
$ref = '';
$refJ = '';
if (!is_null($values['id']) && strlen($values['view']))
{
// only load referral if not new item.
$ref = '&ref=' . $values['view'] . '&refid=' . $values['id'];
$refJ = '&ref=' . $values['view'] . '&refid=' . $values['id'];
// get the return value.
$_uri = (string) JUri::getInstance();
$_return = urlencode(base64_encode($_uri));
// load return value.
$ref .= '&return=' . $_return;
$refJ .= '&return=' . $_return;
}
// get button label
$button_label = trim($button_code_name);
$button_label = preg_replace('/_+/', ' ', $button_label);
$button_label = preg_replace('/\s+/', ' ', $button_label);
$button_label = preg_replace("/[^A-Za-z ]/", '', $button_label);
$button_label = ucfirst(strtolower($button_label));
// get user object
$user = JFactory::getUser();
// only add if user allowed to create joomla_plugin
if ($user->authorise('joomla_plugin.create', 'com_componentbuilder') && $app->isAdmin()) // TODO for now only in admin area.
{
// build Create button
$button[] = '<a id="'.$button_code_name.'Create" class="btn btn-small btn-success hasTooltip" title="'.JText::sprintf('PLG_CONTENT_COMPONENTBUILDERPRIVACYTABS_CREATE_NEW_S', $button_label).'" style="border-radius: 0px 4px 4px 0px; padding: 4px 4px 4px 7px;"
href="index.php?option=com_componentbuilder&amp;view=joomla_plugin&amp;layout=edit'.$ref.'" >
<span class="icon-new icon-white"></span></a>';
}
// only add if user allowed to edit joomla_plugin
if ($user->authorise('joomla_plugin.edit', 'com_componentbuilder') && $app->isAdmin()) // TODO for now only in admin area.
{
// build edit button
$button[] = '<a id="'.$button_code_name.'Edit" class="btn btn-small hasTooltip" title="'.JText::sprintf('PLG_CONTENT_COMPONENTBUILDERPRIVACYTABS_EDIT_S', $button_label).'" style="display: none; padding: 4px 4px 4px 7px;" href="#" >
<span class="icon-edit"></span></a>';
// build script
$script[] = "
jQuery(document).ready(function() {
jQuery('#adminForm').on('change', '#jform_".$button_code_name."',function (e) {
e.preventDefault();
var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val();
".$button_code_name."Button(".$button_code_name."Value);
});
var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val();
".$button_code_name."Button(".$button_code_name."Value);
});
function ".$button_code_name."Button(value) {
if (value > 0) {
// hide the create button
jQuery('#".$button_code_name."Create').hide();
// show edit button
jQuery('#".$button_code_name."Edit').show();
var url = 'index.php?option=com_componentbuilder&view=joomla_plugins&task=joomla_plugin.edit&id='+value+'".$refJ."';
jQuery('#".$button_code_name."Edit').attr('href', url);
} else {
// show the create button
jQuery('#".$button_code_name."Create').show();
// hide edit button
jQuery('#".$button_code_name."Edit').hide();
}
}";
}
// check if button was created for joomla_plugin field.
if (is_array($button) && count($button) > 0)
{
// Load the needed script.
$document = JFactory::getDocument();
$document->addScriptDeclaration(implode(' ',$script));
// return the button attached to input field.
return '<div class="input-append">' .$html . implode('',$button).'</div>';
}
}
return $html;
}
/**
* Method to get a list of options for a list input.

View File

@ -41,19 +41,26 @@ class JFormFieldTargetfields extends JFormFieldList
$jinput = JFactory::getApplication()->input;
// get the id
$ID = $jinput->getInt('id', 0);
// get the view name
$VIEW = $jinput->get('view', null, 'WORD');
// rest the fields ids
$fieldIds = array();
if (is_numeric($ID) && $ID >= 1)
// if this is an actual admin view then we are done
if ('admin_view' === $VIEW && is_numeric($ID) && $ID >= 1)
{
$adminView = $ID;
}
elseif (is_numeric($ID) && $ID >= 1)
{
// get the admin view ID
$adminView = ComponentbuilderHelper::getVar('admin_fields_conditions', (int) $ID, 'id', 'admin_view');
}
else
elseif ('admin_view' !== $VIEW)
{
// get the admin view ID
$adminView = $jinput->getInt('refid', 0);
}
if (is_numeric($adminView) && $adminView >= 1)
if (isset($adminView) && is_numeric($adminView) && $adminView >= 1)
{
// get all the fields linked to the admin view
if ($addFields = ComponentbuilderHelper::getVar('admin_fields', (int) $adminView, 'admin_view', 'addfields'))

View File

@ -630,6 +630,8 @@ class ComponentbuilderModelFieldtype extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.fieldtype', $data);
}
return $data;

View File

@ -409,38 +409,134 @@
type="subform"
name="fields"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_LABEL"
layout="joomla.form.field.subform.repeatable-table"
layout="joomla.form.field.subform.repeatable"
multiple="true"
buttons="add,remove,move"
icon="list"
max="50">
max="10">
<form hidden="true" name="list_fields_modal" repeat="true">
<!-- Field Field. Type: Fields. (custom) -->
<!-- Plugin Field. Type: Checkbox. (joomla) -->
<field
type="fields"
name="field"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_LABEL"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_DESCRIPTION"
class="list_class fieldFull"
multiple="false"
default=""
required="true"
button="false"
type="checkbox"
name="plugin"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN_LABEL"
value="1"
default="1"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN_DESCRIPTION"
class="inputbox"
/>
<!-- Custom_value Field. Type: Textarea. (joomla) -->
<!-- File Field. Type: Text. (joomla) -->
<field
type="textarea"
name="custom_value"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CUSTOM_VALUE_LABEL"
rows="2"
cols="4"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CUSTOM_VALUE_DESCRIPTION"
type="text"
name="file"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILE_LABEL"
size="10"
maxlength="50"
default="config"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILE_DESCRIPTION"
class="text_area"
hint="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CUSTOM_VALUE_HINT"
required="false"
readonly="false"
disabled="false"
filter="WORD"
hint="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILE_HINT"
autocomplete="on"
/>
<!-- Fields_name Field. Type: Text. (joomla) -->
<field
type="text"
name="fields_name"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_NAME_LABEL"
size="10"
maxlength="50"
default="params"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_NAME_DESCRIPTION"
class="text_area"
filter="WORD"
hint="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_NAME_HINT"
autocomplete="on"
/>
<!-- Fieldset Field. Type: Text. (joomla) -->
<field
type="text"
name="fieldset"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDSET_LABEL"
size="10"
maxlength="50"
default="basic"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDSET_DESCRIPTION"
class="text_area"
filter="WORD"
hint="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDSET_HINT"
autocomplete="on"
/>
<!-- Label Field. Type: Text. (joomla) -->
<field
type="text"
name="label"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_LABEL"
size="10"
maxlength="50"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_DESCRIPTION"
class="text_area"
filter="String"
hint="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_HINT"
autocomplete="on"
/>
<!-- Fields_rules_paths Field. Type: List. (joomla) -->
<field
type="list"
name="fields_rules_paths"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_RULES_PATHS_LABEL"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_RULES_PATHS_DESCRIPTION"
class="list_class"
multiple="false"
validate="number"
default="1">
<!-- Option Set. -->
<option value="1">
COM_COMPONENTBUILDER_JOOMLA_PLUGIN_COMPONENT</option>
<option value="2">
COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN</option>
</field>
<!-- Fields Field. Type: Subform. (joomla) -->
<field
type="subform"
name="fields"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_LABEL"
layout="joomla.form.field.subform.repeatable-table"
multiple="true"
buttons="add,remove,move"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_DESCRIPTION"
icon="list"
max="50"
nested_depth="1">
<form hidden="true" name="list_fields_modal" repeat="true">
<!-- Field Field. Type: Fields. (custom) -->
<field
type="fields"
name="field"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_LABEL"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_DESCRIPTION"
class="list_class fieldFull"
multiple="false"
default=""
required="true"
button="false"
/>
<!-- Custom_value Field. Type: Textarea. (joomla) -->
<field
type="textarea"
name="custom_value"
label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CUSTOM_VALUE_LABEL"
rows="2"
cols="4"
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CUSTOM_VALUE_DESCRIPTION"
class="text_area"
hint="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CUSTOM_VALUE_HINT"
required="false"
readonly="false"
disabled="false"
/>
</form>
</field>
</form>
</field>
<!-- Add_php_method_uninstall Field. Type: Radio. (joomla) -->

View File

@ -375,6 +375,8 @@ class ComponentbuilderModelHelp_document extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.help_document', $data);
}
return $data;

View File

@ -767,6 +767,8 @@ class ComponentbuilderModelJoomla_component extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.joomla_component', $data);
}
return $data;

View File

@ -94,7 +94,7 @@ class ComponentbuilderModelJoomla_plugin extends JModelAdmin
'readme'
)
),
'configparams' => array(
'forms_fields' => array(
'fullwidth' => array(
'fields'
)
@ -572,6 +572,8 @@ class ComponentbuilderModelJoomla_plugin extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.joomla_plugin', $data);
}
return $data;

View File

@ -409,6 +409,8 @@ class ComponentbuilderModelJoomla_plugin_files_folders_urls extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.joomla_plugin_files_folders_urls', $data);
}
return $data;

View File

@ -352,6 +352,8 @@ class ComponentbuilderModelJoomla_plugin_group extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.joomla_plugin_group', $data);
}
return $data;

View File

@ -363,6 +363,8 @@ class ComponentbuilderModelJoomla_plugin_updates extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.joomla_plugin_updates', $data);
}
return $data;

View File

@ -353,6 +353,8 @@ class ComponentbuilderModelLanguage extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.language', $data);
}
return $data;

View File

@ -397,6 +397,8 @@ class ComponentbuilderModelLanguage_translation extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.language_translation', $data);
}
return $data;

View File

@ -451,6 +451,8 @@ class ComponentbuilderModelLayout extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.layout', $data);
}
return $data;

View File

@ -449,6 +449,8 @@ class ComponentbuilderModelLibrary extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.library', $data);
}
return $data;

View File

@ -363,6 +363,8 @@ class ComponentbuilderModelLibrary_config extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.library_config', $data);
}
return $data;

View File

@ -409,6 +409,8 @@ class ComponentbuilderModelLibrary_files_folders_urls extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.library_files_folders_urls', $data);
}
return $data;

View File

@ -400,6 +400,8 @@ class ComponentbuilderModelPlaceholder extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.placeholder', $data);
}
return $data;

View File

@ -511,6 +511,8 @@ class ComponentbuilderModelServer extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.server', $data);
}
return $data;

View File

@ -620,6 +620,8 @@ class ComponentbuilderModelSite_view extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.site_view', $data);
}
return $data;

View File

@ -380,6 +380,8 @@ class ComponentbuilderModelSnippet extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.snippet', $data);
}
return $data;

View File

@ -353,6 +353,8 @@ class ComponentbuilderModelSnippet_type extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.snippet_type', $data);
}
return $data;

View File

@ -451,6 +451,8 @@ class ComponentbuilderModelTemplate extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.template', $data);
}
return $data;

View File

@ -403,6 +403,8 @@ class ComponentbuilderModelValidation_rule extends JModelAdmin
if (empty($data))
{
$data = $this->getItem();
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.validation_rule', $data);
}
return $data;