User tests: Successful: Unsuccessful:
Pull Request for Issue #21867.
to make joomla's admin model aware of subforms so you can actually handle them in seperate tables with their corresponding model
use a subform to add a row
some DB-table has a row added which is handled by default CMS functions
the row gets stashed away in a json field making it unpractical for sorting, searching, ACL, and just about anything
tbd
Instead of extending \Joomla\CMS\MVC\ModelAdminModel ; extend this class to have your form handle subforms with their own respective models and forms
Off course you'll need to provide the model and form you want your subform to use. So in the example below you'd provide:
/**
* Model for a list of History items
*
* @since 0.0.1
*/
class AmberModelHistories extends ListModel
{
// as you would when creating a listview like normal
}
snippet from example form .xml:
<field
name="histories"
type="subform"
formsource="/administrator/components/com_amber/models/forms/histories.xml"
multiple="true"
layout="joomla.form.field.subform.repeatable-table"
/>
content of histories.xml:
note the fieldgroup name which needs to match the name of the subform
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldgroup name="histories">
<field
name="historyID"
type="hidden"
/>
<field
name="resourceID"
type="resource"
label="COM_AMBER_RESOURCE_TITLE_LABEL"
description="COM_AMBER_RESOURCE_TITLE_DESC"
class="inputbox"
/>
<field
name="difQty"
type="number"
label="COM_AMBER_QUANTITY_LABEL"
description="COM_AMBER_QUANTITY_DESC"
class="inputbox"
/>
</fieldgroup>
</form>
the controller for the subform:
/administrator/compontents/com_amber/controllers/histories.php
class AmberControllerHistories extends AdminController
{
public function getModel($name = 'History', $prefix = 'AmberModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Title |
|
Title |
|
Labels |
Added:
?
|
Title |
|
@grillkoning please take a look into the drone / PHPCS reports: http://ci.joomla.org/joomla/joomla-cms/9814/4
Can you extend the description of this pr what you have in mind with it and a code example? It will be then easier to review.
thanks to all of you for your comments and attention. hopefully this will grow to be a useful feature to many.
Labels |
Added:
?
Removed: ? |
Sorry it took so long to respond. As this is a nice addition for the MVC API, it is a new feature which should be adapted Joomla 4. Can you rebase the pr to the 4.2-dev branch? In the meantime I'm closing the pr, when ready please reopen again so we can leave feedback. Thank you very much for your contribution and help making Joomla better.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-03-28 06:27:47 |
Closed_By | ⇒ | laoneo |
@grillkoning i changed your Comment to be more readable and linked to Issue.