0

For my Project i need to render a custom form field based on the ListField I try to use the "new" conventions for J4 and later using namespacing etc.

this is the relevant part of my xml:

...
<namespace path="src">NXD\Module\FootballManagerPlayers</namespace>
...
<config>
        <fields name="params">
            <fieldset name="basic"
                      addfieldpath="/modules/mod_nxdfm2_players/src/models/fields"
            >
                <field name="team_id"
                        type="TeamSelect"
                        label="MOD_NXDFM2_PLAYERS_TEAM_FILTER_LABEL"
                        description="MOD_NXDFM2_PLAYERS_FILTER_DESC"
                        default=""
                        show_select="true">
                </field>
            </fieldset>
...

I've tried to place the FieldClass PHP on different locations within my module wihtout success. Currently the "TeamSelectField.php" is stored under "modules/mod_nxdfm2_players/src/models/fields" (But I think thats not correct?)

My TeamSelectField.php:

...
namespace NXD\Module\FootballmanagerPlayers\Fields;

defined('_JEXEC') or die;
...
class TeamSelectField extends ListField
{
    protected $type = 'TeamSelect';
...
protected function getInput()
    {
...
}

protected function getOptions()
    {
...
}
...

I'm using Dispatcher.php aswell as the service provider interface... github Link to module code: Link

I've tried different location that's why there are currently multiple "TeamSelectField.php" files in different locations like root/fields, src/Fields, src/models/fields , ....

I've used custom form field types already a few times in Joomla 3 / 4 by using the "old fashioned way" without issues. I'm aware that the conventions are strict but i didn't find any ressource on how to use it "the new way". Any suggestions hints are much appreciated.

Edit Also adding the addFieldPrefix does not change anything:

...
<fieldset name="basic"
                      addfieldpath="/modules/mod_nxdfm2_players/src/models/fields"
                      addfieldprefix="NXD\Module\FootballmanagerPlayers\Field">
...

1 Answer 1

2

File / Folder Structure

src /
- Field /
-- [FieldName]Field.php

Namespacing

In the XML:

<namespace path="src">[COMPANY]\Module\ModuleName</namespace>

Then you need to add the fieldprefix to the field or fieldset:

<fieldset name="basic" addfieldprefix="[COMPANY]\Module\[ModuleName]\Site\Field">

In the [FieldName]Field.php:

namespace [COMPANY]\Module\[ModuleName]\Site\Field;

Then as usual make sure the protected $type = 'FieldName'; is identical to the call in the XML:

...
<field name="team_id"
  type="FieldName"
  label="YOUR_LABEL"
...

In conclusion the ...\Site... part was my mistake - even if the field has to be used in the Backend-Form we need to use "Site" because its a Frontend Module...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.