2

I have created a D8 module for creating a custom field. I have done it following the given links.

https://www.drupal.org/node/2052601
https://www.drupal.org/node/2620968
https://www.drupal.org/node/2620966

I have created an module.info.yml file . Then created a three folders inside

/src/Plugin/Field , namely,

  1. FieldFormatter

  2. FieldType

  3. FieldWidget

I have coded in each of the folders as per the links. I could see my custom field in the field list. But my problem is that it is categorized under disabled. Please help me to figure out the problem.

  • 1
    Add a screenshot, it might also be useful to share your code. I'm not sure what you mean exactly. – Berdir Aug 8 '16 at 13:48
  • 1
    I have exactly the same problem. I've created a custom field type and when I create a field in the UI I can't place it anywhere under "Manage form display". The field is always in the 'disabled' section. The widget selection drop down says 'hidden' and doesn't have any other options. – tanc Jan 4 '17 at 15:54
  • There are so many tiny things that can make a custom field not work. I don't like it. – RaisinBranCrunch Mar 7 '17 at 19:15
0

After both your field and your field instance are created, you need to enable it in the related form:

entity_get_form_display('node', $bundle, 'default')
  ->setComponent('field_custom', array(
    'type' => 'string'
  ))
  ->save();
0

I had the same problem and the issue in my case was that I was using default_widget = "options_select" in my FieldType plugin but the options_select widget does not allow my custom field type.

The solution was to create a custom FieldWidget plugin which extends the OptionsSelectWidget and in the field_types declare my custom field type.

This allowed my field to be placed in the form correctly and the options widget to be used.

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.