Skip to content

Commit 6d37b9b

Browse files
committed
feat: add custom fields filtering to opengraph field
1 parent fea4185 commit 6d37b9b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

plugins/system/opengraph/src/Field/OpengraphField.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Form Field class for the Joomla Platform.
2626
* Supports a generic list of options.
2727
*
28-
* @since 1.7.0
28+
* @since __DEPLOY_VERSION__
2929
*/
3030

3131
class OpengraphField extends GroupedlistField
@@ -34,7 +34,7 @@ class OpengraphField extends GroupedlistField
3434
* The form field type.
3535
*
3636
* @var string
37-
* @since 1.7.0
37+
* @since __DEPLOY_VERSION__
3838
*/
3939
protected $type = 'Opengraph';
4040

@@ -44,7 +44,7 @@ class OpengraphField extends GroupedlistField
4444
*
4545
* @return object[] The field option objects.
4646
*
47-
* @since 3.7.0
47+
* @since __DEPLOY_VERSION__
4848
*/
4949
protected function getGroups()
5050
{
@@ -81,19 +81,27 @@ protected function getGroups()
8181
return $groups;
8282
}
8383

84-
$customOptions = [];
84+
// Allowed field types for each OpenGraph group
85+
$allowedFieldTypes = [
86+
'text-fields' => ['text', 'textarea'],
87+
'image-fields' => ['media', 'imagelist'],
88+
'image-alt-fields' => ['text'],
89+
];
8590

91+
$allowedTypes = $allowedFieldTypes[$fieldType] ?? [];
8692

8793
$customFields = FieldsHelper::getFields('com_content.article', null);
94+
$customOptions = [];
8895

8996
foreach ($customFields as $field) {
90-
// todo : will be filtered by type or group in the future
97+
if (!in_array($field->type, $allowedTypes, true)) {
98+
continue;
99+
}
91100

92101
$label = $field->title . ' (' . $field->name . ')';
93-
$customOptions[] = HTMLHelper::_('select.option', $field->name, $label);
102+
$customOptions[] = HTMLHelper::_('select.option', 'field.' . $field->name, $label);
94103
}
95104

96-
97105
if (!empty($customOptions)) {
98106
$groups['Custom Fields'] = $customOptions;
99107
}

0 commit comments

Comments
 (0)