Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions administrator/components/com_fields/forms/field.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@
<option value="0">COM_FIELDS_FIELD_DISPLAY_NO_DISPLAY</option>
</field>

<field
name="prefix"
type="text"
label="COM_FIELDS_FIELD_PREFIX_LABEL"
size="40"
/>

<field
name="suffix"
type="text"
label="COM_FIELDS_FIELD_SUFFIX_LABEL"
size="40"
/>

<field
name="layout"
type="fieldLayout"
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.com_fields.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ COM_FIELDS_FIELD_LABEL_FORM_CLASS_LABEL="Label Class (Form)"
COM_FIELDS_FIELD_LABEL_LABEL="Label"
COM_FIELDS_FIELD_LABEL_RENDER_CLASS_LABEL="Label Class (Output)"
COM_FIELDS_FIELD_NOTE_LABEL="Note"
COM_FIELDS_FIELD_PREFIX_LABEL="Prefix"
COM_FIELDS_FIELD_RENDER_CLASS_DESC="The class attributes of the field when the field is rendered. If multiple classes are needed, list them with spaces."
COM_FIELDS_FIELD_RENDER_CLASS_LABEL="Render Class"
COM_FIELDS_FIELD_REQUIRED_LABEL="Required"
COM_FIELDS_FIELD_SHOW_ON_ADMIN="Administrator"
COM_FIELDS_FIELD_SHOW_ON_BOTH="Both"
COM_FIELDS_FIELD_SHOW_ON_LABEL="Show On"
COM_FIELDS_FIELD_SHOW_ON_SITE="Site"
COM_FIELDS_FIELD_SUFFIX_LABEL="Suffix"
COM_FIELDS_FIELD_TYPE_LABEL="Type"
COM_FIELDS_FIELD_USE_GLOBAL="Use settings from Plugin"
COM_FIELDS_MUSTCONTAIN_A_TITLE_FIELD="Field must have a title."
Expand Down
8 changes: 8 additions & 0 deletions components/com_fields/layouts/field/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
$label = Text::_($field->label);
$value = $field->value;
$showLabel = $field->params->get('showlabel');
$prefix = Text::plural($field->params->get('prefix'), $value);
$suffix = Text::plural($field->params->get('suffix'), $value);
$labelClass = $field->params->get('label_render_class');

if ($value == '')
Expand All @@ -30,4 +32,10 @@
<?php if ($showLabel == 1) : ?>
<span class="field-label <?php echo $labelClass; ?>"><?php echo htmlentities($label, ENT_QUOTES | ENT_IGNORE, 'UTF-8'); ?>: </span>
<?php endif; ?>
<?php if ($prefix) : ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just from a code review perspective. I think this needs to be <?php if (!empty($prefix)) : ?> otherwise you're going to get the span with an empty string. But if you test and tell me this works then I'm happy with that too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would work without empty but would raise a warning if $prefix is not defined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But would not work if $prefix is "0" (zero)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field params is a registry object, so it will default to an empty string if existing fields haven't been saved yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and you do not get a span with empty string
Also tested what happens if you have a prefix and then delete the prefix - no span then either

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a point in what Harald wrote. It doesn't work if you have a prefix (eg "0") which evaluates to false. I'm not sure if you ever get such a prefix or suffix. If you want to avoid that, one could do a check if ($prefix !== '')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if prefix is 0 then you dont get a prefix (including the spans) not sure that would ever happen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I mean. I don't think "0" is a valid prefix or suffix. But I learned people do expect crazy things and maybe someone expects "0" to appear.
Personally, I don't mind 😄

<span class="field-prefix"><?php echo htmlentities($prefix, ENT_QUOTES | ENT_IGNORE, 'UTF-8'); ?></span>
<?php endif; ?>
<span class="field-value"><?php echo $value; ?></span>
<?php if ($suffix) : ?>
<span class="field-suffix"><?php echo htmlentities($suffix, ENT_QUOTES | ENT_IGNORE, 'UTF-8'); ?></span>
<?php endif; ?>