I’m trying to create a plugin that adds a file type field with support for dropzone and other functions to user fields. Plugin structure:
/plugins/fields/upload/
/fields
upload.php
/params
upload.xml
/services
provider.php
/src
/Extension
Upload.php
/tmpl
upload.php
upload.xml
The problem is that the function getInput() is not executed in /fields/upload.php I added the echo output to the end of the file for the test - it works. File contents /fields/upload.php:
<?php
namespace Joomla\Plugin\Fields\Upload\Fields;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
defined('_JEXEC') or die;
class UploadField extends FormField
{
protected $type = 'Upload';
protected function getInput()
{
return '<input type="file" name="' . htmlspecialchars($this->name) . '" />';
}
}
echo '1111';
File contents /src/Extension/Upload.php:
namespace Joomla\Plugin\Fields\Upload\Extension;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Form\Form;
use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
final class Upload extends FieldsPlugin implements SubscriberInterface
{
public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form)
{
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form);
if ($field->type !== 'upload') {
return;
}
if (!$fieldNode) {
return $fieldNode;
}
//$form->addFieldPath(JPATH_PLUGINS . '/fields/upload/fields');
$doc = Factory::getDocument();
$doc->addStyleSheet(Uri::root() . 'media/plg_fields_upload/css/dropzone.min.css');
$doc->addScript(Uri::root() . 'media/plg_fields_upload/js/dropzone.min.js');
$fieldNode->setAttribute('field_id', $field->id);
$fieldNode->setAttribute('type', 'upload');
//$fieldNode->setAttribute('layout', $field->params->get('form_layout', 'upload'));
return $fieldNode;
}
}
I have not found any documentation on creating custom types. What could be the problem?