@@ -75,6 +75,80 @@ protected function getGroups()
7575 }
7676
7777
78+ if (!$ component instanceof FieldsServiceInterface) {
79+ return $ groups ;
80+ }
81+
82+ // Allowed field types for each OpenGraph group
83+ $ allowedFieldTypes = [
84+ OpengraphGroup::TEXT ->value => ['text ' , 'textarea ' ],
85+ OpengraphGroup::IMAGE ->value => ['media ' , 'imagelist ' ],
86+ OpengraphGroup::IMAGE_ALT ->value => ['text ' ],
87+ ];
88+
89+ $ nativeTypes = $ allowedFieldTypes [$ fieldType ] ?? [];
90+
91+
92+
93+ $ catId = (int ) $ this ->form ->getValue ('id ' ); // editing existing cat
94+ if (!$ catId ) {
95+ // Creating a new category: use the chosen parent so assignments still work
96+ $ catId = (int ) $ this ->form ->getValue ('parent_id ' );
97+ }
98+
99+ // Dummy item with catid so FieldsService filters by assignment
100+ $ scopeItem = $ catId ? (object ) ['catid ' => $ catId ] : null ;
101+
102+ $ customFields = FieldsHelper::getFields ('com_content.article ' , $ scopeItem );
103+ $ customOptions = [];
104+
105+ foreach ($ customFields as $ field ) {
106+ $ accept = \in_array ($ field ->type , $ nativeTypes , true );
107+
108+
109+ // If not native-allowed, see if the field’s plugin implements our interface
110+ if (!$ accept ) {
111+
112+ // Ensure the specific fields plugin is loaded
113+ PluginHelper::importPlugin ('fields ' , $ field ->type );
114+
115+ $ ucType = ucfirst ((string ) $ field ->type );
116+
117+ // Candidate class names in priority order (modern first, then legacy)
118+ $ candidates = [
119+ "Joomla \\Plugin \\Fields \\{$ ucType }\\Extension \\{$ ucType }" , // J4/5 namespaced
120+ "Joomla \\Plugin \\Fields \\{$ ucType }\\Field \\{$ ucType }Field " , // some third-party patterns
121+ "PlgFields {$ ucType }" , // legacy non-namespaced
122+ ];
123+
124+ $ implements = false ;
125+
126+ foreach ($ candidates as $ fqcn ) {
127+ if (\class_exists ($ fqcn ) && \is_subclass_of ($ fqcn , MappableFieldInterface::class)) {
128+ $ implements = ($ fqcn ::getOpengraphGroup ()->value === $ fieldType );
129+ if ($ implements ) {
130+ $ accept = true ;
131+ break ;
132+ }
133+ }
134+ }
135+ }
136+
137+
138+ if (!$ accept ) {
139+ continue ;
140+ }
141+
142+
143+
144+ $ label = $ field ->title . ' ( ' . $ field ->name . ') ' ;
145+ $ customOptions [] = HTMLHelper::_ ('select.option ' , 'field. ' . $ field ->name , $ label );
146+ }
147+
148+ if (!empty ($ customOptions )) {
149+ $ groups ['Custom Fields ' ] = $ customOptions ;
150+ }
151+
78152 return $ groups ;
79153 }
80154}
0 commit comments