@@ -68,13 +68,32 @@ protected function getOptions()
6868 {
6969 $ options = parent ::getOptions ();
7070
71+ // Get the ID of the field currently being edited
72+ $ currentFieldId = (int ) $ this ->form ->getValue ('id ' );
73+
74+ // If current field ID is zero
75+ if ($ currentFieldId === 0 ) {
76+ $ currentFieldId = (int ) Factory::getApplication ()->getInput ()->getInt ('id ' );
77+ }
78+
7179 // Check whether we have a result for this context yet
7280 if (!isset (static ::$ customFieldsCache [$ this ->context ])) {
73- static ::$ customFieldsCache [$ this ->context ] = FieldsHelper::getFields ($ this ->context , null , false , null , true );
81+ static ::$ customFieldsCache [$ this ->context ] = FieldsHelper::getFields (
82+ $ this ->context ,
83+ null ,
84+ false ,
85+ null ,
86+ true
87+ );
7488 }
7589
7690 // Iterate over the custom fields for this context
7791 foreach (static ::$ customFieldsCache [$ this ->context ] as $ customField ) {
92+ // Skip the current field itself so it cannot be selected as a subfield
93+ if ($ currentFieldId && (int ) $ customField ->id === $ currentFieldId ) {
94+ continue ;
95+ }
96+
7897 $ options [] = HTMLHelper::_ (
7998 'select.option ' ,
8099 $ customField ->id ,
@@ -90,8 +109,11 @@ function ($a, $b) {
90109 }
91110 );
92111
93- if (\count ($ options ) == 0 ) {
94- Factory::getApplication ()->enqueueMessage (Text::_ ('COM_FIELDS_NO_FIELDS_TO_CREATE_SUBFORM_FIELD_WARNING ' ), 'warning ' );
112+ if (\count ($ options ) === 0 ) {
113+ Factory::getApplication ()->enqueueMessage (
114+ Text::_ ('COM_FIELDS_NO_FIELDS_TO_CREATE_SUBFORM_FIELD_WARNING ' ),
115+ 'warning '
116+ );
95117 }
96118
97119 return $ options ;
0 commit comments