3

There are several enum classes containing constants such as the SectionType class which I can use to create sections:

//  …
$section = new SectionModel();
$section->type = SectionType::Single;
//  …

But what about creating fields? Currently I create fields like so:

//  …
$field = new FieldModel();
$field->type = 'PlainText';
//  …

Is there any enum class containing valid identifiers I could use to create a field? Like in the following way?

//  …
$field = new FieldModel();
$field->type = FieldType::PlainText;     // Does something like this exist?
//  …

I can't find such a class or any other listing of existing field types, where do I?

Unfortunately, a list of string identifiers is missing on the guide for plugin development and field types. The list of field types only tells me which field types exist but not what identifiers they have.

| improve this question | | | | |
5

I don't know if any enum exists (couldn't find it in source), but you could have a look at the contents of the craft/app/fieldtypes folder (and ignore BaseFieldtypes, DataModels and interfaces) to find the identifiers:

  • UsersFieldType.php
  • TagsFieldType.php
  • TableFieldType.php
  • RichTextFieldType.php
  • RadioButtonsFieldType.php
  • PositionSelectFieldType.php
  • PlainTextFieldType.php
  • NumberFieldType.php
  • MultiSelectFieldType.php
  • MatrixFieldType.php
  • LightswitchFieldType.php
  • EntriesFieldType.php
  • DropdownFieldType.php
  • DateFieldType.php
  • ColorFieldType.php
  • CheckboxesFieldType.php
  • CategoriesFieldType.php
  • AssetsFieldType.php

String identifiers correspond to the file names (without "FieldType.php", obviously).

| improve this answer | | | | |
  • Ah! Seems obvious, yeah… to me it wasn't. I already knew where the field type implementations are located but I didn't see the relation between file name and string identifier. Yep, pretty shortsighted. ;) Shame on me and thanks to you. :) … But still, I hoped there would have been an enum I could use (because of easiness with auto-complete). Nevertheless, get my upvote. Cheers. – Arvid Jun 3 '16 at 13:47
0

Paul is correct, but probably worth adding if you want the full list of "enums" Craft has available you can look at craft.app.enums in the class reference.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.