0

For one of my projects (Custom Module) I would like to have a "com_menus"-styled modal to select an article - unfortunately it looks like this is not a "default form field type".

Based on my investigations of the com_menus item.xml (where such a field got rendered) the effective "article selector" is hidden behind a field type called "menutype" which looks to me like a core-custom dynamic field which renders a field (-template) based on the field above named "menutype".

If Single Article is selected it loads a field of type modal-select (modalSelect) -> but this only renders the effective inputfield with readonly - no buttons no functionality (which is obvious when checking the source code).

In the com_menus file structure there is in layouts an extra-buttons.php which looks like it renders the additional Select Button. But I have no clue how this is implemented and for me it looks a bit like "component-magic" which I cannot adapt in a module.

All in all I'm lost - I know I could simply create a fancy-list item getting all articles and having a search option there but i think on large sites this would not be the best / performant practice.

Did anyone already figured out how to create such a modal article selector field which makes use of the com_content modal article select layout?

Edit: I'm aware of the general concepts described here

Edit 2: Ok it looks like I was only searching for the wrong terms I've found this "by accident":

JoomlaDialog

Which throwed this solution onto my screen:

...
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->useScript('joomla.dialog');
$wa->useScript('joomla.dialog-autocreate');
$html = '<button class="btn btn-primary" type="button" data-joomla-dialog=\'{"popupType": "iframe", "width":"80vw", "height": "80vh", "src":"index.php?option=com_content&view=articles&tmpl=component&layout=modal"}\'>Click</button>';
...

Which can be used in a Custom Form field indeed - now I only need to know how to "transfer back" the selection into my input field (transmitting the article ID back which has been selected).

1 Answer 1

1

If you're looking to add article selector field in your module configuration form, use Joomla\Component\Content\Administrator\Field\Modal\ArticleField field:

<field
    addfieldprefix="Joomla\Component\Content\Administrator\Field"
    name="testfield"
    type="modal_article"
    label="Select Article"
    select="true"
    new="true"
    edit="true"
    clear="true"
/>

Menu item form is composed of the item.xml form merged with the form of a selected view. In case of Single Article view, it's components/com_content/tmpl/article/default.xml. You can see this field being used there.

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.