At this point it shows how to create a new table in the database (pretty much the same as Joomla 3 anyway) and then the next article goes onto how to create the back end, etc...
However this is where the tutorial stopped. Really annoying as I was starting to fully understand how Joomla MVC components are made (in the past I've always skipped over creating MVC components and pretty much butchered K2 templates to get that to do what I wanted it to do using the custom fields - but I noticed K2 isn't on J4 yet and also I feel kind of cheating to use the custom fields in a template rather than creating a proper MVC component).
I've had a look into the code of some of the components like com_banners and com_phocagallery to see if I can figure out how they create their own back end and tried to create my own custom field but it just doesn't seem to do anything. In fact it just seems to use a text box for my custom field so I guess it's not using my custom field code.
Here is an example of some of the code I was trying...
<?php
defined('JPATH_BASE') or die;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
class JFormFieldMyList extends ListField
{
public $type = 'mylist';
protected function getOptions ()
{
echo '<p>getOptions</p>' ;
return array ( 'Hello', 'Goodbye' ) ;
}
protected function getInput()
{
echo '<p>getInput</p>' ;
return parent::getInput();
}
}
and in site\tmpl\podcast\default.xml
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="COM_PODCASTS_MENU_PODCASTS_TITLE">
<message><![CDATA[COM_PODCASTS_MENU_PODCASTS_DESC]]></message>
</layout>
<fields name="request">
<fieldset name="request" addfieldpath="/administrator/components/com_podcasts/models/fields">
<field name="id"
type="mylist"
label="COM_PODCASTS_MENU_PODCASTS_PARAM_LABEL"
description="COM_PODCASTS_MENU_PODCASTS_PARAM_DESC"
/>
</fieldset>
</fields>
</metadata>
I know I must be missing something here - I thought with this code as getOptions is returning an array of "Hello", "Goodbye" I would end up with a dropdown list when editing the menu item of hello/goodbye but it doesn't even seem to loading the field definition as I added two echo commands so could see if it was running any part of the script - but nothing.
Without the MVC tutorial being finished though it's hard to see where I'm actually going wrong.
Thanks for any help and advice on where I'm going wrong (or even an actual link to a tutorial).