Last active
April 12, 2022 13:20
-
-
Save alexandreelise/ffdb75f0259cd77c967a1ffefb8024ef to your computer and use it in GitHub Desktop.
Tiny php script to show all available JFormFields in Joomla! 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package all | |
* @author Alexandre ELISÉ <[email protected]> | |
* @link https://alexandre-elise.fr | |
* @copyright (c) 2020 . Alexandre ELISÉ . Tous droits réservés. | |
* @license GPL-2.0-and-later GNU General Public License v2.0 or later | |
* Created Date : 19/07/2020 | |
* Created Time : 16:04 | |
*/ | |
use Joomla\CMS\Filesystem\File; | |
use Joomla\CMS\Filesystem\Folder; | |
use Joomla\CMS\Form\Form; | |
use Joomla\CMS\Form\FormHelper; | |
defined('_JEXEC') or die; | |
$fields_path = JPATH_LIBRARIES . '/joomla/form/fields'; | |
FormHelper::addFieldPath($fields_path); | |
$exclude = ['predefinedlist.php', 'repeatable.php']; | |
$files = Folder::files($fields_path, '.php', false, false, $exclude); | |
$xml = <<<XML | |
<?xml version="1.0" encoding="UTF-8" ?> | |
<form name="all"> | |
<fieldset name="all"> | |
<fields name="all" /> | |
</fieldset> | |
</form> | |
XML; | |
$form = Form::getInstance('all', $xml); | |
if (empty($files)) { | |
echo 'No fields found<br>'; | |
return; | |
} | |
foreach ($files as $file) | |
{ | |
try | |
{ | |
$type = File::stripExt($file); | |
$field = new SimpleXMLElement('<field name="name-of-'.$type.'" type="'.$type.'" label="Label of '.$type.'" description="Description of '.$type.'" />'); | |
$form->setField($field, 'all', true, 'all'); | |
} | |
catch (Exception $err) | |
{ | |
echo $err->getMessage() . ' ' . $err->getFile() . ' ' . $err->getLine(); | |
continue; | |
} | |
} | |
echo $form->renderFieldset('all'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment