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
24 changes: 23 additions & 1 deletion administrator/components/com_fields/src/Model/FieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,30 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null)
*/
public function save($data)
{
$field = null;
$field = null;
$hasDuplicateSubformFields = false;

if (isset($data['id']) && $data['id']) {
$field = $this->getItem($data['id']);
}

$fieldType = $data['type'] ?? ($field->type ?? null);

if ($fieldType === 'subform' && isset($data['fieldparams']['options']) && \is_array($data['fieldparams']['options'])) {
$seenCustomFields = [];

foreach ($data['fieldparams']['options'] as $option) {
$customField = (string) ($option['customfield'] ?? '');

if (isset($seenCustomFields[$customField])) {
$hasDuplicateSubformFields = true;
break;
}

$seenCustomFields[$customField] = true;
}
}

if (isset($data['params']['searchindex'])) {
if (\is_null($field)) {
if ($data['params']['searchindex'] > 0) {
Expand Down Expand Up @@ -172,6 +190,10 @@ public function save($data)
return false;
}

if ($hasDuplicateSubformFields) {
Factory::getApplication()->enqueueMessage(Text::_('COM_FIELDS_FIELD_SUBFORM_DUPLICATE_FIELDS_REMOVED'), 'warning');
}

// Save the assigned categories into #__fields_categories
$db = $this->getDatabase();
$id = (int) $this->getState('field.id');
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/com_fields.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ COM_FIELDS_FIELD_SHOWLABEL_LABEL="Label"
COM_FIELDS_FIELD_SHOWON_DESC="Conditionally show or hide the field depending on the value of other fields."
COM_FIELDS_FIELD_SHOWON_LABEL="Showon Attribute"
COM_FIELDS_FIELD_SMARTSEARCHOPTIONS_HEADING="Smart Search"
COM_FIELDS_FIELD_SUBFORM_DUPLICATE_FIELDS_REMOVED="Duplicate subform fields were removed. Each field can only be used once."
COM_FIELDS_FIELD_SUFFIX_LABEL="Suffix"
COM_FIELDS_FIELD_TYPE_LABEL="Type"
COM_FIELDS_FIELD_USE_GLOBAL="Use settings from Plugin"
Expand Down
Loading