Skip to content

Commit

Permalink
[4.0] Custom fields prefix and suffix (#24232)
Browse files Browse the repository at this point in the history
J4 version of #23499

It is very common to need to display a unit of measurement/value with a field. Currently there is no way to do this without creating custom layouts for every field and every unit when needed.

This PR adds two new param to every custom field "Suffix" and "Prefix" which allows you to add a unit of measurement (or any other text) to be rendered after/before the value of the field.
  • Loading branch information
brianteeman authored and wilsonge committed Apr 23, 2019
1 parent bcfb107 commit 2cfa81c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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) : ?>
<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; ?>

0 comments on commit 2cfa81c

Please sign in to comment.