Body: <p>I'm trying to create a Dropdown field and add it to the User field layout. I've successfully created an empty dropdown field (no options) and added it to the User field layout.</p>
  
  <p>Here is my current code for that:</p>
  
  <pre><code>$subscriptionStatusField = new FieldModel();
  $subscriptionStatusField-&gt;groupId = 1;
  $subscriptionStatusField-&gt;name = "Subscription Status";
  $subscriptionStatusField-&gt;handle = "subscriptionStatus";
  $subscriptionStatusField-&gt;translatable = false;
  $subscriptionStatusField-&gt;type = "Dropdown";
  </code></pre>
  
  <p>What I'm having trouble with is how to add options to the dropdown field. How can I do this programmatically?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-11T03:35:01.673Z
Comments.Text: Your plugin has a FieldType, and in your Field Type class within your getInputHtml method you are rendering the template containing the dropdown code?
Comments.UserDisplayName: a-am
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-15T14:57:33.530Z
Comments.Text: @aran While that may provide the correct options for the front-end, that doesn't provide any server-side enumeration mechanism. Also, I won't be able to change these options in the future without changing my code.
Comments.UserDisplayName: Greg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-15T15:31:07.480Z
Comments.Text: Are you trying to provide settings for the field type so that the user can add options for the drop-down which are output to the field type's front end drop-down?
Comments.UserDisplayName: a-am
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-30T09:56:05.810Z
Comments.Text: This may be off-topic, but did you tried this plugin: https://github.com/lewisjenkins/craft-lj-dynamicfields?
Comments.UserDisplayName: Romain P.
Tags: <plugin-development><users><field><usermodel>
Title: How can I create a dropdown field programmatically with a plugin?
ThreadText: # How can I create a dropdown field programmatically with a plugin?
  
  (Asked by: username_0 on 2016-11-10)
  
  I'm trying to create a Dropdown field and add it to the User field layout. I've successfully created an empty dropdown field (no options) and added it to the User field layout.
  
  Here is my current code for that:
  
  ```
  $subscriptionStatusField = new FieldModel();
  $subscriptionStatusField->groupId = 1;
  $subscriptionStatusField->name = "Subscription Status";
  $subscriptionStatusField->handle = "subscriptionStatus";
  $subscriptionStatusField->translatable = false;
  $subscriptionStatusField->type = "Dropdown";
  
  ```
  
  What I'm having trouble with is how to add options to the dropdown field. How can I do this programmatically?
  
  **Tags:** plugin-development, users, field, usermodel
  
  > **Comments:**
  > **username_1**: Your plugin has a FieldType, and in your Field Type class within your getInputHtml method you are rendering the template containing the dropdown code?  
  > **username_0**: @aran While that may provide the correct options for the front-end, that doesn't provide any server-side enumeration mechanism. Also, I won't be able to change these options in the future without changing my code.  
  > **username_1**: Are you trying to provide settings for the field type so that the user can add options for the drop-down which are output to the field type's front end drop-down?  
  > **username_2**: This may be off-topic, but did you tried this plugin: https://github.com/lewisjenkins/craft-lj-dynamicfields?  
  
  ---
  
  ## 0 answers
  
  