Stable release of v5.0.0-alpha1
First alpha release of Component Builder towards Joomla 5 (very unstable...).
This commit is contained in:
@@ -13,17 +13,16 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Field;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface as History;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Customcode as FieldCustomcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Validation;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Rule;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,95 +41,93 @@ class Data
|
||||
protected array $fields;
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Compiler Event
|
||||
* The EventInterface Class.
|
||||
*
|
||||
* @var EventInterface
|
||||
* @var Event
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected EventInterface $event;
|
||||
protected Event $event;
|
||||
|
||||
/**
|
||||
* Compiler History
|
||||
* The HistoryInterface Class.
|
||||
*
|
||||
* @var HistoryInterface
|
||||
* @var History
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected HistoryInterface $history;
|
||||
protected History $history;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Customcode
|
||||
* The Customcode Class.
|
||||
*
|
||||
* @var Customcode
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* Compiler Field Customcode
|
||||
* The Customcode Class.
|
||||
*
|
||||
* @var FieldCustomcode
|
||||
* @var FieldCustomcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected FieldCustomcode $fieldCustomcode;
|
||||
protected FieldCustomcode $fieldcustomcode;
|
||||
|
||||
/**
|
||||
* Compiler Field Validation
|
||||
* The Rule Class.
|
||||
*
|
||||
* @var Validation
|
||||
* @var Rule
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Validation $validation;
|
||||
protected Rule $rule;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @var \JDatabaseDriver
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected \JDatabaseDriver $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param EventInterface|null $event The compiler event api object.
|
||||
* @param HistoryInterface|null $history The compiler history object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Customcode|null $customcode The compiler customcode object.
|
||||
* @param FieldCustomcode|null $fieldCustomcode The field customcode object.
|
||||
* @param Validation|null $validation The field validation rule object.
|
||||
* @param \JDatabaseDriver|null $db The database object.
|
||||
* The database class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?EventInterface $event = null, ?HistoryInterface $history = null,
|
||||
?Placeholder $placeholder = null, ?Customcode $customcode = null, ?FieldCustomcode $fieldCustomcode = null,
|
||||
?Validation $validation = null, ?\JDatabaseDriver $db = null)
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param Event $event The EventInterface Class.
|
||||
* @param History $history The HistoryInterface Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Customcode $customcode The Customcode Class.
|
||||
* @param FieldCustomcode $fieldcustomcode The Customcode Class.
|
||||
* @param Rule $rule The Rule Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, Event $event, History $history,
|
||||
Placeholder $placeholder, Customcode $customcode,
|
||||
FieldCustomcode $fieldcustomcode, Rule $rule)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->event = $event ?: Compiler::_('Event');
|
||||
$this->history = $history ?: Compiler::_('History');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->customcode = $customcode ?: Compiler::_('Customcode');
|
||||
$this->fieldCustomcode = $fieldCustomcode ?: Compiler::_('Field.Customcode');
|
||||
$this->validation = $validation ?: Compiler::_('Field.Validation');
|
||||
$this->db = $db ?: Factory::getDbo();
|
||||
$this->config = $config;
|
||||
$this->event = $event;
|
||||
$this->history = $history;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->customcode = $customcode;
|
||||
$this->fieldcustomcode = $fieldcustomcode;
|
||||
$this->rule = $rule;
|
||||
$this->db = Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,13 +166,9 @@ class Data
|
||||
$this->db->quoteName('a.id') . ' = ' . $this->db->quote($id)
|
||||
);
|
||||
|
||||
// TODO we need to update the event signatures
|
||||
$context = $this->config->component_context;
|
||||
|
||||
// Trigger Event: jcb_ce_onBeforeQueryFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeQueryFieldData',
|
||||
array(&$context, &$id, &$query, &$this->db)
|
||||
'jcb_ce_onBeforeQueryFieldData', [&$id, &$query, &$this->db]
|
||||
);
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
@@ -188,8 +181,7 @@ class Data
|
||||
|
||||
// Trigger Event: jcb_ce_onBeforeModelFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeModelFieldData',
|
||||
array(&$context, &$field)
|
||||
'jcb_ce_onBeforeModelFieldData', [&$field]
|
||||
);
|
||||
|
||||
// adding a fix for the changed name of type to fieldtype
|
||||
@@ -199,7 +191,7 @@ class Data
|
||||
$field->xml = $this->customcode->update(json_decode((string) $field->xml));
|
||||
|
||||
// check if we have validate (validation rule and set it if found)
|
||||
$this->validation->set($id, $field->xml);
|
||||
$this->rule->set($id, $field->xml);
|
||||
|
||||
// load the type values form type params
|
||||
$field->properties = (isset($field->properties)
|
||||
@@ -301,8 +293,7 @@ class Data
|
||||
|
||||
// Trigger Event: jcb_ce_onAfterModelFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onAfterModelFieldData',
|
||||
array(&$context, &$field)
|
||||
'jcb_ce_onAfterModelFieldData', [&$field]
|
||||
);
|
||||
|
||||
$this->fields[$id] = $field;
|
||||
@@ -316,14 +307,13 @@ class Data
|
||||
if ($id > 0 && isset($this->fields[$id]))
|
||||
{
|
||||
// update the customcode of the field
|
||||
$this->fieldCustomcode->update($id, $this->fields[$id], $singleViewName, $listViewName);
|
||||
$this->fieldcustomcode->update($id, $this->fields[$id], $singleViewName, $listViewName);
|
||||
|
||||
// return the field
|
||||
return $this->fields[$id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -71,21 +71,18 @@ final class Groups
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @var \JDatabaseDriver
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected \JDatabaseDriver $db;
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \JDatabaseDriver|null $db The Database Driver object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?\JDatabaseDriver $db = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = $db ?: Factory::getDbo();
|
||||
$this->db = Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaFive;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreFieldInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Fields
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreField implements CoreFieldInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Fields
|
||||
*
|
||||
* @var array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $fields = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Fields Path
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation fields
|
||||
$this->paths[] = JPATH_LIBRARIES . '/src/Form/Field';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Field Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set fields lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->fields === [])
|
||||
{
|
||||
// check if the path exist
|
||||
foreach ($this->paths as $path)
|
||||
{
|
||||
$this->set($path);
|
||||
}
|
||||
}
|
||||
|
||||
// return fields if found
|
||||
if ($this->fields !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->fields
|
||||
);
|
||||
}
|
||||
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fields found in a path
|
||||
*
|
||||
* @param string $path The path to load fields from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$fields = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract field names
|
||||
$processedFields = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Field.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -9) === 'Field.php')
|
||||
{
|
||||
return str_replace('Field.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $fields);
|
||||
|
||||
// Merge with existing fields and remove duplicates
|
||||
$this->fields = array_unique(array_merge($processedFields, $this->fields));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaFive;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreRule implements CoreRuleInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Rules
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $rules = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Rules Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation rules
|
||||
$this->path = JPATH_LIBRARIES . '/src/Form/Rule';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set rules lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->rules === [])
|
||||
{
|
||||
$this->set($this->path);
|
||||
}
|
||||
|
||||
// return rules if found
|
||||
if ($this->rules !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rules found in a path
|
||||
*
|
||||
* @param string $path The path to load rules from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$rules = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract rule names
|
||||
$processedRules = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Rule.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -8) === 'Rule.php')
|
||||
{
|
||||
return str_replace('Rule.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $rules);
|
||||
|
||||
// Merge with existing rules and remove duplicates
|
||||
$this->rules = array_unique(array_merge($processedRules, $this->rules));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaFive;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Creator\Permission;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\InputButtonInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Input Button
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class InputButton implements InputButtonInterface
|
||||
{
|
||||
/**
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The Permission Class.
|
||||
*
|
||||
* @var Permission
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Permission $permission;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Permission $permission The Permission Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Permission $permission)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Button To List Field Input (getInput tweak)
|
||||
*
|
||||
* @param array $fieldData The field custom data
|
||||
*
|
||||
* @return string of getInput class on success empty string otherwise
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array $fieldData): string
|
||||
{
|
||||
// make sure hte view values are set
|
||||
if (isset($fieldData['add_button'])
|
||||
&& ($fieldData['add_button'] === 'true'
|
||||
|| 1 == $fieldData['add_button'])
|
||||
&& isset($fieldData['view'])
|
||||
&& isset($fieldData['views'])
|
||||
&& StringHelper::check($fieldData['view'])
|
||||
&& StringHelper::check($fieldData['views']))
|
||||
{
|
||||
// set local component
|
||||
$local_component = "com_" . $this->config->component_code_name;
|
||||
// check that the component value is set
|
||||
if (!isset($fieldData['component'])
|
||||
|| !StringHelper::check(
|
||||
$fieldData['component']
|
||||
))
|
||||
{
|
||||
$fieldData['component'] = $local_component;
|
||||
}
|
||||
// check that the component has the com_ value in it
|
||||
if (strpos((string) $fieldData['component'], 'com_') === false
|
||||
|| strpos((string) $fieldData['component'], '=') !== false)
|
||||
{
|
||||
$fieldData['component'] = "com_" . $fieldData['component'];
|
||||
}
|
||||
// make sure the component is update if # # # or [ [ [ component placeholder is used
|
||||
if (strpos((string) $fieldData['component'], (string) Placefix::h()) !== false
|
||||
|| strpos((string) $fieldData['component'], (string) Placefix::b()) !== false) // should not be needed... but
|
||||
{
|
||||
$fieldData['component'] = $this->placeholder->update_(
|
||||
$fieldData['component']
|
||||
);
|
||||
}
|
||||
// get core permissions
|
||||
$coreLoad = false;
|
||||
// add ref tags
|
||||
$refLoad = true;
|
||||
// fall back on the field component
|
||||
$component = $fieldData['component'];
|
||||
// check if we should add ref tags (since it only works well on local views)
|
||||
if ($local_component !== $component)
|
||||
{
|
||||
// do not add ref tags
|
||||
$refLoad = false;
|
||||
}
|
||||
// start building the add buttons/s
|
||||
$addButton = array();
|
||||
$addButton[] = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
|
||||
$addButton[] = Indent::_(1) . " * Override to add new button";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1)
|
||||
. " * @return string The field input markup.";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1) . " * @since 3.2";
|
||||
$addButton[] = Indent::_(1) . " */";
|
||||
$addButton[] = Indent::_(1) . "protected function getInput()";
|
||||
$addButton[] = Indent::_(1) . "{";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " see if we should add buttons";
|
||||
$addButton[] = Indent::_(2)
|
||||
. "\$set_button = \$this->getAttribute('button');";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get html";
|
||||
$addButton[] = Indent::_(2) . "\$html = parent::getInput();";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " if true set button";
|
||||
$addButton[] = Indent::_(2) . "if (\$set_button === 'true')";
|
||||
$addButton[] = Indent::_(2) . "{";
|
||||
$addButton[] = Indent::_(3) . "\$button = array();";
|
||||
$addButton[] = Indent::_(3) . "\$script = array();";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_code_name = \$this->getAttribute('name');";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the input from url";
|
||||
$addButton[] = Indent::_(3) . "\$app = Factory::getApplication();";
|
||||
$addButton[] = Indent::_(3) . "\$jinput = \$app->input;";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the view name & id";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$values = \$jinput->getArray(array(";
|
||||
$addButton[] = Indent::_(4) . "'id' => 'int',";
|
||||
$addButton[] = Indent::_(4) . "'view' => 'word'";
|
||||
$addButton[] = Indent::_(3) . "));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if new item";
|
||||
$addButton[] = Indent::_(3) . "\$ref = '';";
|
||||
$addButton[] = Indent::_(3) . "\$refJ = '';";
|
||||
if ($refLoad)
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load referral if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load field details if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get button label";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = trim(\$button_code_name);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/_+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/\s+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace(\"/[^A-Za-z ]/\", '', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = ucfirst(strtolower(\$button_label));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get user object";
|
||||
$addButton[] = Indent::_(3) . "\$user = Factory::getApplication()->getIdentity();";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to create " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.create')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build Create button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Create\" class=\"btn btn-small btn-success hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_CREATE_NEW_S', \$button_label).'\" style=\"border-radius: 0px 4px 4px 0px;\"";
|
||||
$addButton[] = Indent::_(5) . "href=\"index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['view']
|
||||
. "&layout=edit'.\$ref.'\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-new icon-white\"></span></a>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to edit " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.edit')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build edit button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Edit\" class=\"btn btn-small hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_EDIT_S', \$button_label).'\" style=\"display: none; border-radius: 0px 4px 4px 0px;\" href=\"#\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-edit\"></span></a>';";
|
||||
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build script";
|
||||
$addButton[] = Indent::_(4) . "\$script[] = \"";
|
||||
$addButton[] = Indent::_(5) . "document.addEventListener('DOMContentLoaded', function() {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "document.getElementById('jform_\".\$button_code_name.\"').addEventListener('change', function(e) {";
|
||||
$addButton[] = Indent::_(7) . "e.preventDefault();";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "let \".\$button_code_name.\"Value = this.value;";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(6) . "});";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "let \".\$button_code_name.\"Value = document.getElementById('jform_\".\$button_code_name.\"').value;";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(5) . "});";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "function \".\$button_code_name.\"Button(value) {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var createButton = document.getElementById('\".\$button_code_name.\"Create');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var editButton = document.getElementById('\".\$button_code_name.\"Edit');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "if (value > 0) {"; // TODO not ideal since value may not be an (int)
|
||||
$addButton[] = Indent::_(7) . "// hide the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(7) . "// show edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "let url = 'index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['views']
|
||||
. "&task=" . $fieldData['view']
|
||||
. ".edit&id='+value+'\".\$refJ.\"';"; // TODO this value may not be the ID
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.setAttribute('href', url);";
|
||||
$addButton[] = Indent::_(6) . "} else {";
|
||||
$addButton[] = Indent::_(7) . "// show the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "// hide edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(6) . "}";
|
||||
$addButton[] = Indent::_(5) . "}\";";
|
||||
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if button was created for " . $fieldData['view']
|
||||
. " field.";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (is_array(\$button) && count(\$button) > 0)";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " Load the needed script.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document = Factory::getApplication()->getDocument();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document->addScriptDeclaration(implode(' ',\$script));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " return the button attached to input field.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "return '<div class=\"input-group\">' .\$html . implode('',\$button).'</div>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(2) . "}";
|
||||
$addButton[] = Indent::_(2) . "return \$html;";
|
||||
$addButton[] = Indent::_(1) . "}";
|
||||
|
||||
return implode(PHP_EOL, $addButton);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaFour;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreFieldInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Fields
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreField implements CoreFieldInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Fields
|
||||
*
|
||||
* @var array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $fields = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Fields Path
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation fields
|
||||
$this->paths[] = JPATH_LIBRARIES . '/src/Form/Field';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Field Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set fields lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->fields === [])
|
||||
{
|
||||
// check if the path exist
|
||||
foreach ($this->paths as $path)
|
||||
{
|
||||
$this->set($path);
|
||||
}
|
||||
}
|
||||
|
||||
// return fields if found
|
||||
if ($this->fields !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->fields
|
||||
);
|
||||
}
|
||||
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fields found in a path
|
||||
*
|
||||
* @param string $path The path to load fields from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$fields = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract field names
|
||||
$processedFields = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Field.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -9) === 'Field.php')
|
||||
{
|
||||
return str_replace('Field.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $fields);
|
||||
|
||||
// Merge with existing fields and remove duplicates
|
||||
$this->fields = array_unique(array_merge($processedFields, $this->fields));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaFour;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreRule implements CoreRuleInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Rules
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $rules = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Rules Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation rules
|
||||
$this->path = JPATH_LIBRARIES . '/src/Form/Rule';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set rules lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->rules === [])
|
||||
{
|
||||
$this->set($this->path);
|
||||
}
|
||||
|
||||
// return rules if found
|
||||
if ($this->rules !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rules found in a path
|
||||
*
|
||||
* @param string $path The path to load rules from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$rules = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract rule names
|
||||
$processedRules = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Rule.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -8) === 'Rule.php')
|
||||
{
|
||||
return str_replace('Rule.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $rules);
|
||||
|
||||
// Merge with existing rules and remove duplicates
|
||||
$this->rules = array_unique(array_merge($processedRules, $this->rules));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaFour;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Creator\Permission;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\InputButtonInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Input Button
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class InputButton implements InputButtonInterface
|
||||
{
|
||||
/**
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The Permission Class.
|
||||
*
|
||||
* @var Permission
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Permission $permission;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Permission $permission The Permission Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Permission $permission)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Button To List Field Input (getInput tweak)
|
||||
*
|
||||
* @param array $fieldData The field custom data
|
||||
*
|
||||
* @return string of getInput class on success empty string otherwise
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array $fieldData): string
|
||||
{
|
||||
// make sure hte view values are set
|
||||
if (isset($fieldData['add_button'])
|
||||
&& ($fieldData['add_button'] === 'true'
|
||||
|| 1 == $fieldData['add_button'])
|
||||
&& isset($fieldData['view'])
|
||||
&& isset($fieldData['views'])
|
||||
&& StringHelper::check($fieldData['view'])
|
||||
&& StringHelper::check($fieldData['views']))
|
||||
{
|
||||
// set local component
|
||||
$local_component = "com_" . $this->config->component_code_name;
|
||||
// check that the component value is set
|
||||
if (!isset($fieldData['component'])
|
||||
|| !StringHelper::check(
|
||||
$fieldData['component']
|
||||
))
|
||||
{
|
||||
$fieldData['component'] = $local_component;
|
||||
}
|
||||
// check that the component has the com_ value in it
|
||||
if (strpos((string) $fieldData['component'], 'com_') === false
|
||||
|| strpos((string) $fieldData['component'], '=') !== false)
|
||||
{
|
||||
$fieldData['component'] = "com_" . $fieldData['component'];
|
||||
}
|
||||
// make sure the component is update if # # # or [ [ [ component placeholder is used
|
||||
if (strpos((string) $fieldData['component'], (string) Placefix::h()) !== false
|
||||
|| strpos((string) $fieldData['component'], (string) Placefix::b()) !== false) // should not be needed... but
|
||||
{
|
||||
$fieldData['component'] = $this->placeholder->update_(
|
||||
$fieldData['component']
|
||||
);
|
||||
}
|
||||
// get core permissions
|
||||
$coreLoad = false;
|
||||
// add ref tags
|
||||
$refLoad = true;
|
||||
// fall back on the field component
|
||||
$component = $fieldData['component'];
|
||||
// check if we should add ref tags (since it only works well on local views)
|
||||
if ($local_component !== $component)
|
||||
{
|
||||
// do not add ref tags
|
||||
$refLoad = false;
|
||||
}
|
||||
// start building the add buttons/s
|
||||
$addButton = array();
|
||||
$addButton[] = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
|
||||
$addButton[] = Indent::_(1) . " * Override to add new button";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1)
|
||||
. " * @return string The field input markup.";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1) . " * @since 3.2";
|
||||
$addButton[] = Indent::_(1) . " */";
|
||||
$addButton[] = Indent::_(1) . "protected function getInput()";
|
||||
$addButton[] = Indent::_(1) . "{";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " see if we should add buttons";
|
||||
$addButton[] = Indent::_(2)
|
||||
. "\$set_button = \$this->getAttribute('button');";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get html";
|
||||
$addButton[] = Indent::_(2) . "\$html = parent::getInput();";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " if true set button";
|
||||
$addButton[] = Indent::_(2) . "if (\$set_button === 'true')";
|
||||
$addButton[] = Indent::_(2) . "{";
|
||||
$addButton[] = Indent::_(3) . "\$button = array();";
|
||||
$addButton[] = Indent::_(3) . "\$script = array();";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_code_name = \$this->getAttribute('name');";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the input from url";
|
||||
$addButton[] = Indent::_(3) . "\$app = Factory::getApplication();";
|
||||
$addButton[] = Indent::_(3) . "\$jinput = \$app->input;";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the view name & id";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$values = \$jinput->getArray(array(";
|
||||
$addButton[] = Indent::_(4) . "'id' => 'int',";
|
||||
$addButton[] = Indent::_(4) . "'view' => 'word'";
|
||||
$addButton[] = Indent::_(3) . "));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if new item";
|
||||
$addButton[] = Indent::_(3) . "\$ref = '';";
|
||||
$addButton[] = Indent::_(3) . "\$refJ = '';";
|
||||
if ($refLoad)
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load referral if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load field details if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get button label";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = trim(\$button_code_name);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/_+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/\s+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace(\"/[^A-Za-z ]/\", '', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = ucfirst(strtolower(\$button_label));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get user object";
|
||||
$addButton[] = Indent::_(3) . "\$user = Factory::getApplication()->getIdentity();";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to create " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.create')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build Create button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Create\" class=\"btn btn-small btn-success hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_CREATE_NEW_S', \$button_label).'\" style=\"border-radius: 0px 4px 4px 0px;\"";
|
||||
$addButton[] = Indent::_(5) . "href=\"index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['view']
|
||||
. "&layout=edit'.\$ref.'\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-new icon-white\"></span></a>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to edit " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.edit')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build edit button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Edit\" class=\"btn btn-small hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_EDIT_S', \$button_label).'\" style=\"display: none; border-radius: 0px 4px 4px 0px;\" href=\"#\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-edit\"></span></a>';";
|
||||
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build script";
|
||||
$addButton[] = Indent::_(4) . "\$script[] = \"";
|
||||
$addButton[] = Indent::_(5) . "document.addEventListener('DOMContentLoaded', function() {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "document.getElementById('jform_\".\$button_code_name.\"').addEventListener('change', function(e) {";
|
||||
$addButton[] = Indent::_(7) . "e.preventDefault();";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "let \".\$button_code_name.\"Value = this.value;";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(6) . "});";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "let \".\$button_code_name.\"Value = document.getElementById('jform_\".\$button_code_name.\"').value;";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(5) . "});";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "function \".\$button_code_name.\"Button(value) {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var createButton = document.getElementById('\".\$button_code_name.\"Create');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var editButton = document.getElementById('\".\$button_code_name.\"Edit');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "if (value > 0) {"; // TODO not ideal since value may not be an (int)
|
||||
$addButton[] = Indent::_(7) . "// hide the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(7) . "// show edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "let url = 'index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['views']
|
||||
. "&task=" . $fieldData['view']
|
||||
. ".edit&id='+value+'\".\$refJ.\"';"; // TODO this value may not be the ID
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.setAttribute('href', url);";
|
||||
$addButton[] = Indent::_(6) . "} else {";
|
||||
$addButton[] = Indent::_(7) . "// show the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "// hide edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(6) . "}";
|
||||
$addButton[] = Indent::_(5) . "}\";";
|
||||
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if button was created for " . $fieldData['view']
|
||||
. " field.";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (is_array(\$button) && count(\$button) > 0)";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " Load the needed script.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document = Factory::getApplication()->getDocument();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document->addScriptDeclaration(implode(' ',\$script));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " return the button attached to input field.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "return '<div class=\"input-group\">' .\$html . implode('',\$button).'</div>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(2) . "}";
|
||||
$addButton[] = Indent::_(2) . "return \$html;";
|
||||
$addButton[] = Indent::_(1) . "}";
|
||||
|
||||
return implode(PHP_EOL, $addButton);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaThree;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreFieldInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Fields
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreField implements CoreFieldInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Fields
|
||||
*
|
||||
* @var array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $fields = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Fields Path
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation fields
|
||||
$this->paths[] = JPATH_LIBRARIES . '/src/Form/Field';
|
||||
$this->paths[] = JPATH_LIBRARIES . '/joomla/form/fields';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Field Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set fields lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->fields === [])
|
||||
{
|
||||
// check if the path exist
|
||||
foreach ($this->paths as $path)
|
||||
{
|
||||
$this->set($path);
|
||||
}
|
||||
}
|
||||
|
||||
// return fields if found
|
||||
if ($this->fields !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->fields
|
||||
);
|
||||
}
|
||||
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fields found in a path
|
||||
*
|
||||
* @param string $path The path to load fields from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$fields = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract field names
|
||||
$processedFields = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Field.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -9) === 'Field.php')
|
||||
{
|
||||
return str_replace('Field.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $fields);
|
||||
|
||||
// Merge with existing fields and remove duplicates
|
||||
$this->fields = array_unique(array_merge($processedFields, $this->fields));
|
||||
}
|
||||
}
|
||||
|
@@ -14,23 +14,23 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaThree;
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreValidationInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Field Validation Rules
|
||||
* Core Joomla Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class CoreValidation implements CoreValidationInterface
|
||||
final class CoreRule implements CoreRuleInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Rules
|
||||
*
|
||||
* @var array|null
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected ?array $rules = null;
|
||||
protected array $rules = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Rules Path
|
||||
@@ -61,41 +61,13 @@ class CoreValidation implements CoreValidationInterface
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if (!$this->rules)
|
||||
if ($this->rules === [])
|
||||
{
|
||||
// check if the path exist
|
||||
if (!Folder::exists($this->path))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// we must first store the current working directory
|
||||
$joomla = getcwd();
|
||||
|
||||
// go to that folder
|
||||
chdir($this->path);
|
||||
|
||||
// load all the files in this path
|
||||
$rules = Folder::files('.', '\.php', true, true);
|
||||
|
||||
// change back to Joomla working directory
|
||||
chdir($joomla);
|
||||
|
||||
// make sure we have an array
|
||||
if (!ArrayHelper::check($rules))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove the Rule.php from the name
|
||||
$this->rules = array_map(
|
||||
fn($name): string => str_replace(array('./','Rule.php'), '', (string) $name),
|
||||
$rules
|
||||
);
|
||||
$this->set($this->path);
|
||||
}
|
||||
|
||||
// return rules if found
|
||||
if (is_array($this->rules))
|
||||
if ($this->rules !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
@@ -105,12 +77,49 @@ class CoreValidation implements CoreValidationInterface
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the rules found in a path
|
||||
*
|
||||
* @param string $path The path to load rules from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$rules = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract rule names
|
||||
$processedRules = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Rule.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -8) === 'Rule.php')
|
||||
{
|
||||
return str_replace('Rule.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $rules);
|
||||
|
||||
// Merge with existing rules and remove duplicates
|
||||
$this->rules = array_unique(array_merge($processedRules, $this->rules));
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field;
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaThree;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
@@ -19,6 +19,7 @@ use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\InputButtonInterface;
|
||||
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class InputButton
|
||||
final class InputButton implements InputButtonInterface
|
||||
{
|
||||
/**
|
||||
* The Config Class.
|
||||
@@ -153,7 +154,7 @@ final class InputButton
|
||||
. "\$button_code_name = \$this->getAttribute('name');";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the input from url";
|
||||
$addButton[] = Indent::_(3) . "\$app = JFactory::getApplication();";
|
||||
$addButton[] = Indent::_(3) . "\$app = Factory::getApplication();";
|
||||
$addButton[] = Indent::_(3) . "\$jinput = \$app->input;";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the view name & id";
|
||||
@@ -180,7 +181,7 @@ final class InputButton
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) JUri::getInstance();";
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
@@ -205,7 +206,7 @@ final class InputButton
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) JUri::getInstance();";
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
@@ -230,18 +231,18 @@ final class InputButton
|
||||
. "\$button_label = ucfirst(strtolower(\$button_label));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get user object";
|
||||
$addButton[] = Indent::_(3) . "\$user = JFactory::getUser();";
|
||||
$addButton[] = Indent::_(3) . "\$user = Factory::getUser();";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to create " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.create')
|
||||
. "', '" . $component . "') && \$app->isAdmin()) // TODO for now only in admin area.";
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build Create button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Create\" class=\"btn btn-small btn-success hasTooltip\" title=\"'.JText:"
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Create\" class=\"btn btn-small btn-success hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_CREATE_NEW_S', \$button_label).'\" style=\"border-radius: 0px 4px 4px 0px; padding: 4px 4px 4px 7px;\"";
|
||||
$addButton[] = Indent::_(5) . "href=\"index.php?option="
|
||||
@@ -255,12 +256,12 @@ final class InputButton
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.edit')
|
||||
. "', '" . $component . "') && \$app->isAdmin()) // TODO for now only in admin area.";
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build edit button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Edit\" class=\"btn btn-small hasTooltip\" title=\"'.JText:"
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Edit\" class=\"btn btn-small hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_EDIT_S', \$button_label).'\" style=\"display: none; padding: 4px 4px 4px 7px;\" href=\"#\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
@@ -317,7 +318,7 @@ final class InputButton
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " Load the needed script.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document = JFactory::getDocument();";
|
||||
. "\$document = Factory::getDocument();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document->addScriptDeclaration(implode(' ',\$script));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
@@ -12,82 +12,81 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreValidationInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface as CoreRule;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Validation Rules
|
||||
* Compiler Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Validation
|
||||
class Rule
|
||||
{
|
||||
/**
|
||||
* Compiler registry
|
||||
* The Registry Class.
|
||||
*
|
||||
* @var Registry
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Compiler Gui
|
||||
* The Customcode Class.
|
||||
*
|
||||
* @var Gui
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Gui $gui;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Customcode
|
||||
*
|
||||
* @var Customcode
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* Compiler Field Core Validation
|
||||
* The Gui Class.
|
||||
*
|
||||
* @var CoreValidationInterface
|
||||
* @var Gui
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected CoreValidationInterface $validation;
|
||||
protected Gui $gui;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
* @param Gui|null $gui The compiler customcode gui object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Customcode|null $customcode The compiler customcode object.
|
||||
* @param CoreValidationInterface|null $validation The core validation rule object.
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The CoreRuleInterface Class.
|
||||
*
|
||||
* @var CoreRule
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected CoreRule $corerule;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Registry $registry The Registry Class.
|
||||
* @param Customcode $customcode The Customcode Class.
|
||||
* @param Gui $gui The Gui Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param CoreRule $corerule The CoreRuleInterface Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Registry $registry = null, ?Gui $gui = null, ?Placeholder $placeholder = null,
|
||||
?Customcode $customcode = null, ?CoreValidationInterface $validation = null)
|
||||
public function __construct(Registry $registry, Customcode $customcode, Gui $gui,
|
||||
Placeholder $placeholder, CoreRule $corerule)
|
||||
{
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
$this->gui = $gui ?: Compiler::_('Customcode.Gui');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->customcode = $customcode ?: Compiler::_('Customcode');
|
||||
$this->validation = $validation ?: Compiler::_('Field.Core.Validation');
|
||||
$this->registry = $registry;
|
||||
$this->customcode = $customcode;
|
||||
$this->gui = $gui;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->corerule = $corerule;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +119,7 @@ class Validation
|
||||
if ($this->registry->get("validation.rules.${validation_rule}") === null)
|
||||
{
|
||||
// get joomla core validation names and make sure this rule is not a core validation rule
|
||||
if (!in_array($validation_rule, (array) $this->validation->get(true)))
|
||||
if (!in_array($validation_rule, (array) $this->corerule->get(true)))
|
||||
{
|
||||
// get the class methods for this rule if it exists
|
||||
if (($php_code = GetHelper::var(
|
||||
@@ -162,7 +161,6 @@ class Validation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user