No Code Attached Yet
avatar brianteeman
brianteeman
14 Nov 2021

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.

image

  1. Where is this default defined
  2. The code says that it will look in multiple places but the only one I was able to get anything working from was the template overrides.

$template_paths = array(
Path::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/' . $extension . '/field'),
Path::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/com_fields/field'),
Path::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/field'),
);

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

@woluweb

avatar brianteeman brianteeman - open - 14 Nov 2021
avatar joomla-cms-bot joomla-cms-bot - change - 14 Nov 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Nov 2021
avatar woluweb
woluweb - comment - 16 Nov 2021

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

  • go to System > Site Templates > Cassiopeia Details and Files > Create Overrides > Layouts > com_fields
  • click on "field"
  • you get the following confirmation message: "Override created in /templates/cassiopeia/html/layouts/com_fields/field"
  • rename that file
avatar brianteeman
brianteeman - comment - 16 Nov 2021

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

avatar LukasHH
LukasHH - comment - 12 Dec 2021

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; ?>
avatar woluweb
woluweb - comment - 12 Dec 2021

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.

avatar LukasHH
LukasHH - comment - 12 Dec 2021

@woluweb

Yes - I took a closer look at it once and tried it out afterwards. I have described my solution in my comment under [Edit].

avatar brianteeman brianteeman - change - 1 Feb 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-02-01 23:02:06
Closed_By brianteeman
avatar brianteeman brianteeman - close - 1 Feb 2022

Add a Comment

Login with GitHub to post a comment