Very confused.
when creating a field to be used in an article there is an option in the rendering options to select a layout. I might be completely misunderstanding the purpose of this field but.
joomla-cms/administrator/components/com_fields/src/Field/FieldLayoutField.php
Lines 108 to 112 in 3371598
But that can't be correct because that will only look in site templates and a field can be in both the site and the admin.
Also of the paths it is looking in the third one will never exist. It should be html/layouts/form/field
Labels |
Added:
No Code Attached Yet
|
doh
I didnt read properly and didnt notice that the layout is only for the rendering of the field output. I was thinking I could have a layout for the display of the form input
I also find it very confusing.
I assumed that you can create and select an override here for the output of this particular field.
For example, I wanted to create an override of plg_fields_subform. By default this is output as a list, which I want to change. When I give a custom name (mysubform.php) to this override, I can't select this anywhere. It must remain the name subform.php, so that my override is accepted.
However, if I want to use different subforms, then I can't assign my override specifically. It applies to all subforms and causes errors with subforms that do not match my override.
[EDIT]
I finished it with the override of "com_fields/field/render.php" after all.
In my case I made it easier then. I copied the file "subform.php" with my changes into the directory "templates/cassiopeia/html/layouts/com_fields/field/" and renamed it.
Before the foreach loop starts, I had to adjust the variables and add FieldsHelper.
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
if (!array_key_exists('field', $displayData))
{
return;
}
$result = '';
$buttons = '';
$context = '';
$field = $displayData['field'];
if (empty($field->subform_rows))
{
return;
}
foreach ($field->subform_rows as $subform_row){
...
}
?>
<?php if (trim($result) != '') : ?>
<p><?php echo $buttons; ?></p>
<?php echo $result; ?>
<?php endif; ?>
HI @LukasHH
Have a look at https://magazine.joomla.org/all-issues/october-2021/custom-fields-episode-7-part-1-one-custom-field-to-rule-them-all and in particular at this screenshot :
https://magazine.joomla.org/images/2021/october/cf-ep7/cf-ep7-7-alternate-layout.png
It is directly in the interface of any given Custom Field that you can select the Alternate Layout that you created.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-02-01 23:02:06 |
Closed_By | ⇒ | brianteeman |
Oh waow, I was not even aware that multiple places were possible for those CF Alternate Layouts :)
In "Step 5 - create an Alternate Layout for the Custom Field" of https://magazine.joomla.org/all-issues/october-2021/custom-fields-episode-7-part-1-one-custom-field-to-rule-them-all I explain the 2 methods that I knew about, namely using the front-end template.
BTW, I had never thought of using CF in the backend. Where / how is it available?
1. the "manual" way
Create the following file
/templates/[my_template]/html/layouts/com_fields/field/my-own-layout.php
(note: underscores are not allowed in the name of that file)
where you paste the content of the following file
/components/com_fields/layouts/field/render.php
which is actually the default layout used to render Custom Fields
2. via Joomla's interface