Folder structure of Joomla 4 module?? Topic is solved

For Joomla! 4.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
User avatar
rbuelund
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Feb 10, 2007 9:07 pm
Location: Århus
Contact:

Folder structure of Joomla 4 module??

Post by rbuelund » Thu Sep 22, 2022 3:28 pm

I cannot find any documentation about the folder structure in a Joomla 4 module. Where do I place the code for a custom List field that I need in my XML config file for the module ? It is a site module.

I have tried to place it in mod_mymodule\src\Field and then added this to the fieldset tag in the XML file: addfieldprefix="Mycompany\Module\Smssystemsendgroup\Site\Field"

But it does not seem to work.

I have added the namespace <namespace>Mycompany\Module\Smssystemsendgroup</namespace>to the XML file also.
Ronny Buelund
Coordinator of the Danish Joomla Translation Team: http://danskjoomla.dk
Owner of http://ableit.dk

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2330
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Folder structure of Joomla 4 module??

Post by SharkyKZ » Thu Sep 22, 2022 4:34 pm

You placed the classes in src directory but your namespace tag does not define this directory. You can add it using path attribute in <namespace> tag:

Code: Select all

<namespace path="src">Mycompany\Module\Smssystemsendgroup</namespace>
Or, alternatively, move the classes outside of this directory.

Field classes also need to follow specific naming convention, field type followed by "Field", e.g. ExampleField. So the fully qualified name of your class would be:

Code: Select all

Mycompany\Module\Smssystemsendgroup\Site\Field\ExampleField
and the file would be in

Code: Select all

modules/mod_mymodule/src/Field/ExampleField.php

User avatar
rbuelund
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Feb 10, 2007 9:07 pm
Location: Århus
Contact:

Re: Folder structure of Joomla 4 module??

Post by rbuelund » Thu Sep 22, 2022 4:52 pm

Ok - thanks for the input - but still no luck.

I do not know if this is correct - should the type variable also have the postifx "Field" ?

Code: Select all

class SelectsendgrouplistField extends ListField
{
	/**
	 * The form field type.
	 *
	 * @var    string
	 * @since  11.1
	 */
	protected $type = 'SelectsendgrouplistField';
And this is my XML parameter - is that correct ?

Code: Select all

	<fields name="params">
			<fieldset name="basic" addfieldprefix="Mycompany\Module\Smssystemsendgroup\Site\Field\SelectsendgrouplistField">
				<field name="moduleclass_sfx" type="text" default="" label="MOD_SMSSYSTEM_SENDGROUP_CLASS_SUFFIKS_TITLE" description="MOD_SMSSYSTEM_SENDGROUP_CLASS_SUFFIKS_DESC" />
                <field name="@spacer" type="spacer" default="" label="" description="" />
                <field 
					name="selectsendgrouplist" 
					type="SelectsendgrouplistField" 
					multiple="false" 
					label="MOD_SMSSYSTEM_SENDGROUP_SELECT_TITEL" 
					description="MOD_SMSSYSTEM_SENDGROUP_SELECT_DESC" 
					size="10"
					/>
Ronny Buelund
Coordinator of the Danish Joomla Translation Team: http://danskjoomla.dk
Owner of http://ableit.dk

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2330
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Folder structure of Joomla 4 module??

Post by SharkyKZ » Thu Sep 22, 2022 5:24 pm

Does your field file has a namespace declaration? addfieldprefix should not have the field class, i.e. "addfieldprefix="Mycompany\Module\Smssystemsendgroup\Site\Field" was correct.

User avatar
rbuelund
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Feb 10, 2007 9:07 pm
Location: Århus
Contact:

Re: Folder structure of Joomla 4 module??

Post by rbuelund » Thu Sep 22, 2022 6:03 pm

This is my field file for testing (I will later add some sql):

Code: Select all

<?php

namespace Mycompany\Module\Smssystemsendgroup\Site\Field;

defined('JPATH_PLATFORM') or die;

use \Joomla\CMS\Form\Field\ListField;



/**
 * Form Field class for the Joomla Platform.
 * Supports an HTML select list of categories
 *
 * @package     Joomla.Platform
 * @subpackage  Form
 * @since       11.1
 */
class SelectsendgrouplistField extends ListField
{
	/**
	 * The form field type.
	 *
	 * @var    string
	 * @since  11.1
	 */
	protected $type = 'Selectsendgrouplist';
	/**
	 * Method to get the field options for category
	 * Use the extension attribute in a form to specify the.specific extension for
	 * which categories should be displayed.
	 * Use the show_root attribute to specify whether to show the global category root in the list.
	 *
	 * @return  array    The field option objects.
	 *
	 * @since   11.1
	 */
	protected function getOptions()
	{
		// Initialise variables.
		$options = array();
		$options[] = JHtml::_('select.option', 'Rotur');
		$options[] = JHtml::_('select.option', 'Arbejdsdag');
		$options[] = JHtml::_('select.option', 'Ikke betalt kontingent');
		$options[] = JHtml::_('select.option', 'Test');
		//$options = array_merge(parent::getOptions(), $options);
		return $options;
	}
}
Ronny Buelund
Coordinator of the Danish Joomla Translation Team: http://danskjoomla.dk
Owner of http://ableit.dk

User avatar
rbuelund
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Feb 10, 2007 9:07 pm
Location: Århus
Contact:

Re: Folder structure of Joomla 4 module??

Post by rbuelund » Thu Sep 22, 2022 6:26 pm

Ahh I got the options to show now - so far so good. My next problem is - all options are shown in a field - can I show them as a dropdown instead ? Which class should I use in the XML file ?

Also when I mark a value in the list, and press save, the marking disappears again and is not saved.
Ronny Buelund
Coordinator of the Danish Joomla Translation Team: http://danskjoomla.dk
Owner of http://ableit.dk

User avatar
rbuelund
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Feb 10, 2007 9:07 pm
Location: Århus
Contact:

Re: Folder structure of Joomla 4 module??

Post by rbuelund » Thu Sep 22, 2022 7:03 pm

It seems that the 'type' parameter is missing in the tag when the html is generated - should this not be type="list" ? In the XML file, the type is the name of the customfield.
Ronny Buelund
Coordinator of the Danish Joomla Translation Team: http://danskjoomla.dk
Owner of http://ableit.dk

MarkRS
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 134
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Folder structure of Joomla 4 module??

Post by MarkRS » Thu Sep 22, 2022 7:13 pm

Just about any class that starts with "J" is likely to not be the correct J4 class.

For example you're using JHtml and you might find it works better with HTMLHelper, suitably adjusted.

My custom lists that use HTMLHelper work correctly as dropdowns. I haven't tried (in J4) the option marking that you mentioned, though.
It's a community, the more we all contribute, the better it will be.

User avatar
rbuelund
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Feb 10, 2007 9:07 pm
Location: Århus
Contact:

Re: Folder structure of Joomla 4 module??

Post by rbuelund » Thu Sep 22, 2022 7:14 pm

Ahhhh - dough! The problem was because of the parameter size="10", which of course should not be in the field params of the dropdown. Now it works. Thank you very much !
Ronny Buelund
Coordinator of the Danish Joomla Translation Team: http://danskjoomla.dk
Owner of http://ableit.dk


Post Reply

Return to “Joomla! 4.x Coding”