Answers.Body: <p>Get all the created fields first and encode them.</p>
  
  <pre><code>protected function settingsHtml(): string
  {
      $fieldsData = [];
      $fields = Craft::$app-&gt;fields-&gt;getAllFields();
      foreach ($fields as $field)
      {
          $fieldsData[$field-&gt;handle] = $field-&gt;name;
      }
  
  }
  </code></pre>
  
  <p>In settings.twig template</p>
  
  <pre><code>{{ forms.multiselectField({
      label: 'Select Fields',
      name: 'fieldSelected',
      id: 'fieldSelected',
      required:     true,
      options: fields,
      values: settings['fieldSelected']
  }) }}
  </code></pre>
  
  <p>Output: </p>
  
  <p><a href="https://i.sstatic.net/HSLEo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HSLEo.png" alt="select fields"></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-13T06:37:07.230Z
Answers.LastActivityDate: 2019-05-14T08:26:57.993Z
Answers.LastEditDate: 2019-05-14T08:26:57.993Z
Answers.UserDisplayName: inrsaurabh
Answers.Body: <p>The fields service <strong>does</strong> include a method getAllFields:</p>
  
  <pre><code>$fields = Craft::$app-&gt;fields-&gt;getAllFields(false);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-10T13:55:02.640Z
Answers.LastActivityDate: 2019-05-10T13:55:02.640Z
Answers.UserDisplayName: Richard
Body: <p>I am trying to get all the <code>fields</code> created by admin in my custom plugin setting page.</p>
  
  <p>As we can get entries , in same way can we have option to get the available fields.</p>
  
  <pre><code> {{ forms.elementSelectField({
      label: 'Entry Select Field',
      id: 'entries',
      name: '',
      elementType: 'craft\\elements\\Entry',
      elements: [craft.entries.one()],
      selectionLabel: 'Select an entry',
  
  }) }}
  </code></pre>
  
  <blockquote>
    <p>I tried to look in core file :/vendor/craftcms/cms/src/services/Fields.php </p>
  </blockquote>
  
  <pre><code>$fields = Craft::$app-&gt;fields-&gt;getAllFields();
  </code></pre>
  
  <p>But there is no such method which return the list of existing fields.</p>
  
  <p>Update:</p>
  
  <p>Now i am able to get the list of all the existing fields.</p>
  
  <pre><code>$fieldsData = [];
  
  $fields = Craft::$app-&gt;fields-&gt;getAllFields();
  
  foreach ($fields as $field)
  {
  
      $fieldsData['name'][] = $field-&gt;name;
      $fieldsData['handle'][] = $field-&gt;handle;
  }
  </code></pre>
  
  <p>In setting the template of plugin I want to give admin an option to select multi fields <code>(handles )</code> 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.  </p>
  
  <blockquote>
    <p>But can we populate multi-select like?</p>
  </blockquote>
  
  <pre><code>{{ forms.multiselectField({
      label: 'Multi Select Field',
      name: '',
      options: {
        fields['handle']: fields['name'],  
      },
      values: '',
  }) }}
  </code></pre>
  
  <blockquote>
    <p>Or if we create our custom multi-select fields how we can save the user ( admin) input? as in micro, it saves by itself.</p>
  </blockquote>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-05-12T11:20:26.223Z
Comments.Text: Can you elaborate on what you're trying to achieve? Maybe the multi-select documentation is helpful: https://docs.craftcms.com/v3/multi-select-fields.html#templating
Comments.UserDisplayName: Richard
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-05-12T15:40:33.063Z
Comments.Text: 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.
Comments.UserDisplayName: inrsaurabh
Tags: <plugin-development><entries-field>
Title: Get all available fields in plugin setting page
ThreadText: # Get all available fields in plugin setting page
  
  (Asked by: username_0 on 2019-05-10)
  
  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.
  
  **Tags:** plugin-development, entries-field
  
  > **Comments:**
  > **username_1**: Can you elaborate on what you're trying to achieve? Maybe the multi-select documentation is helpful: https://docs.craftcms.com/v3/multi-select-fields.html#templating  
  > **username_0**: 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.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2019-05-13. Score: 1 | Accepted answer
  
  Get all the created fields first and encode them.
  
  ```
  protected function settingsHtml(): string
  {
      $fieldsData = [];
      $fields = Craft::$app->fields->getAllFields();
      foreach ($fields as $field)
      {
          $fieldsData[$field->handle] = $field->name;
      }
  
  }
  
  ```
  
  In settings.twig template
  
  ```
  {{ forms.multiselectField({
      label: 'Select Fields',
      name: 'fieldSelected',
      id: 'fieldSelected',
      required:     true,
      options: fields,
      values: settings['fieldSelected']
  }) }}
  
  ```
  
  Output:
  
  [![select fields](https://i.sstatic.net/HSLEo.png)](https://i.sstatic.net/HSLEo.png)
  
  
  ---
  
  ### Answer by username_1 on 2019-05-10. Score: 1
  
  The fields service **does** include a method getAllFields:
  
  ```
  $fields = Craft::$app->fields->getAllFields(false);
  
  ```
  
  
  ---
  
  