33/**
44 * Joomla! Content Management System
55 *
6- * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
6+ * @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
77 * @license GNU General Public License version 2 or later; see LICENSE.txt
88 */
99
1010namespace Joomla \Plugin \System \Opengraph \Field ;
1111
12-
1312use Joomla \CMS \Factory ;
14- use Joomla \CMS \Form \Field \ListField ;
13+ use Joomla \CMS \Fields \FieldsServiceInterface ;
14+ use Joomla \CMS \Form \Field \GroupedlistField ;
1515use Joomla \CMS \HTML \HTMLHelper ;
1616use Joomla \CMS \Opengraph \OpengraphServiceInterface ;
17+ use Joomla \Component \Fields \Administrator \Helper \FieldsHelper ;
18+ use Joomla \CMS \Language \Text ;
1719
1820// phpcs:disable PSR1.Files.SideEffects
1921\defined ('_JEXEC ' ) or die;
2628 * @since 1.7.0
2729 */
2830
29- class OpengraphField extends ListField
31+ class OpengraphField extends GroupedlistField
3032{
3133 /**
3234 * The form field type.
@@ -44,26 +46,58 @@ class OpengraphField extends ListField
4446 *
4547 * @since 3.7.0
4648 */
47- protected function getOptions ()
49+ protected function getGroups ()
4850 {
4951 $ app = Factory::getApplication ();
50- $ options = parent ::getOptions ();
52+ $ groups = [];
53+
54+ $ groups ['' ] = [
55+ HTMLHelper::_ ('select.option ' , '' , Text::_ ('PLG_SYSTEM_OPENGRAPH_NO_FIELD_SELECTED ' ))
56+ ];
5157
5258
59+ $ ogOptions = [];
5360 $ component = $ app ->bootComponent ('com_content ' );
5461
5562 if (!$ component instanceof OpengraphServiceInterface) {
56- return $ options ;
63+ return $ groups ;
5764 }
5865
5966 $ fields = $ component ->getOpengraphFields ();
6067 $ fieldType = $ this ->getAttribute ('field-type ' );
6168
6269 if (isset ($ fields [$ fieldType ])) {
6370 foreach ($ fields [$ fieldType ] as $ value => $ text ) {
64- $ options [] = HTMLHelper::_ ('select.option ' , $ value , $ text );
71+ $ ogOptions [] = HTMLHelper::_ ('select.option ' , $ value , $ text );
6572 }
6673 }
67- return $ options ;
74+
75+ if (!empty ($ ogOptions )) {
76+ $ groups ['Default Fields ' ] = $ ogOptions ;
77+ }
78+
79+
80+ if (!$ component instanceof FieldsServiceInterface) {
81+ return $ groups ;
82+ }
83+
84+ $ customOptions = [];
85+
86+
87+ $ customFields = FieldsHelper::getFields ('com_content.article ' , null );
88+
89+ foreach ($ customFields as $ field ) {
90+ // todo : will be filtered by type or group in the future
91+
92+ $ label = $ field ->title . ' ( ' . $ field ->name . ') ' ;
93+ $ customOptions [] = HTMLHelper::_ ('select.option ' , $ field ->name , $ label );
94+ }
95+
96+
97+ if (!empty ($ customOptions )) {
98+ $ groups ['Custom Fields ' ] = $ customOptions ;
99+ }
100+
101+ return $ groups ;
68102 }
69103}
0 commit comments