I am trying to get all the fields
created by admin in my custom plugin setting page.
As we can get entries , in same way can we have option to get the available fields.
{{ forms.elementSelectField({
label: 'Entry Select Field',
id: 'entries',
name: '',
elementType: 'craft\\elements\\Entry',
elements: [craft.entries.one()],
selectionLabel: 'Select an entry',
}) }}
I tried to look in core file :/vendor/craftcms/cms/src/services/Fields.php
$fields = Craft::$app->fields->getAllFields();
But there is no such method which return the list of existing fields.
Update:
Now i am able to get the list of all the existing fields.
$fieldsData = [];
$fields = Craft::$app->fields->getAllFields();
foreach ($fields as $field)
{
$fieldsData['name'][] = $field->name;
$fieldsData['handle'][] = $field->handle;
}
In setting the template of plugin I want to give admin an option to select multi fields (handles )
on the plugin setting page. For this, I am trying to fetch all the created fields first and then pass that array to form micro so that it can populate the multi-select.
But can we populate multi-select like?
{{ forms.multiselectField({
label: 'Multi Select Field',
name: '',
options: {
fields['handle']: fields['name'],
},
values: '',
}) }}
Or if we create our custom multi-select fields how we can save the user ( admin) input? as in micro, it saves by itself.
(handles )
on the plugin setting page. For this i am trying to fetch all the created fields first and then pass that array to form micro so that it can populate the multi-select. – inrsaurabh May 12 '19 at 15:40