Developing an MVC Component
From Joomla! Documentation
Revision as of 03:06, 7 September 2020 by Robbiej (Initial page creation)
These are suggested changes which should be considered for improving this tutorial series in any future rewrite.
When introducing the database (Using the Database) it should use
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
See the note on that tutorial step page for the reasons why. (Also, InnoDB supports row level locking, which MyISAM doesn't).
Helloworld and Helloworlds
The number of times which "helloworld" is used is very confusing. I think it would be an improvement to continue with com_helloworld as the name of the component, but then use "message" and "messages" for the names of the controllers etc, in a similar way as com_content uses "article" and "articles".
This would help for example with the class names of eg the model where currently there is "HelloworldModelHelloworld" and you're not sure which "Helloworld" relates to the name of the component, and which relates to the view/controller within the component.
"Greeting" database column name
In Adding Verifications use some other verification rather than prohibiting digits in the greeting. This becomes too restrictive when you're wanting to use lots of records for testing.
Title and Alias on edit screen
The title ('greeting') and alias should be presented on the edit form above the bootstrap tabs, similar to the way it's done for standard Joomla components.
Joomla Class names
References to Joomla classes should use the namespaced class names.
In Adding Categories there should be a default "Uncategorised" for each of the com_helloworld records. This would avoid the problem with association of categories (in Adding Associations) where the Joomla code in libraries/src/Language/Assocations.php::getAssociations() does an inner join on the tables, which fails to include the com_helloworld record if there's not a category set.
You would need to include in the install script file the creation of the category record though, as the Category table using the Nested Set model, and you (probably) can't just insert a record using a SQL update script.
So I think the step on Adding install/uninstall/update script file should immediately precede the Adding Categories step, and then writing the category record provides a good example of how a script can be used effectively.
Access and ACL
It would make more sense to have these 2 steps next to each other, probably with the Access one first.
Column Ordering in Admin view
In the admin "Helloworlds" view change the column ordering mechanism (which is introduced in Adding Decorations to the backend) to the more modern mechanism (which is introduced in Adding a Front-end Form).
In the step Adding Decorations to the Backend the display of the little penguin could be removed.
In the step Adding Decorations to the Backend fix the filter_helloworlds.xml labels (which refer to com_banners and com_content language strings).
Language Translation Strings
In Adding Language Management consider how best to order the language strings in the file. Joomla orders them alphabetically, but from a tutorial perspective it's maybe better to have them organised based on where they're used in the code, with appropriate comments included regarding where they're used.
In Adding Configuration use the Table $_jsonEncode protected variable to enable the conversion of the fields to json format.
This could also be used by the imageinfo data in Adding and Image
In the step Adding an Image the variables "imageinfo" and "imageInfo" (with a capital I for Info) are both used (for different purposes) in code in this page, and this is confusing. Either make them all just "imageinfo" or call give the variables names which clearly differentiates them.
Created and Created_by database columns
In the step Adding a Front-end form it would be better to write these fields when an administrator creates a record on the back-end. (This would allow us to write an allowEdit() function for use by com_associations in the Adding Associations step, but that's maybe too advanced anyway).
It would be useful to have a step which included describing how Joomla works out where to look for source files for classes – PSR-4 etc.
Naming of Tutorial Steps
Similarly Adding an alias, adding the language filter facility and adding associations are all associated with developing a custom router.
Adding the language filter facility might be better renamed as eg Adding Multilingual capability.