6

I'm new in Drupal, I create my first entity and use baseFieldDefinitions to set fields and in fields I use setDisplayOptions to set form like this:

$fields['piece'] = BaseFieldDefinition::create('integer')
  ->setLabel(t('piece'))
  ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'string',
    'weight' => 2,
  ])
  ->setDisplayOptions('form', [
    'label' => 'inline',
    'type' => 'string',/////// what is supported value list of type key
    'weight' => 2,
  ])
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);

what is supported value list of type key in display option?

I only found options_buttons and string

2 Answers 2

15

What you are looking for are the field widget plugins, these depend on what modules you have installed.

Use Drupal Console to run this command:

drupal debug:plugin field.widget

This is what I have on a local site with some contrib modules:

 -------------------------------------------- --------------------------------------------------------------------------------------- 
  Plugin ID                                    Plugin class                                                                           
 -------------------------------------------- --------------------------------------------------------------------------------------- 
  boolean_checkbox                             Drupal\Core\Field\Plugin\Field\FieldWidget\BooleanCheckboxWidget                       
  datetime_datelist                            Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDatelistWidget                        
  datetime_default                             Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDefaultWidget                         
  datetime_timestamp                           Drupal\Core\Datetime\Plugin\Field\FieldWidget\TimestampDatetimeWidget                  
  email_default                                Drupal\Core\Field\Plugin\Field\FieldWidget\EmailDefaultWidget                          
  entity_reference_autocomplete                Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget           
  entity_reference_autocomplete_tags           Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteTagsWidget       
  field_example_3text                          Drupal\field_example\Plugin\Field\FieldWidget\Text3Widget                              
  field_example_colorpicker                    Drupal\field_example\Plugin\Field\FieldWidget\ColorPickerWidget                        
  field_example_text                           Drupal\field_example\Plugin\Field\FieldWidget\TextWidget                               
  field_permission_example_widget              Drupal\field_permission_example\Plugin\Field\FieldWidget\TextWidget                    
  file_generic                                 Drupal\file\Plugin\Field\FieldWidget\FileWidget                                        
  image_image                                  Drupal\image\Plugin\Field\FieldWidget\ImageWidget                                      
  language_select                              Drupal\Core\Field\Plugin\Field\FieldWidget\LanguageSelectWidget                        
  link_default                                 Drupal\link\Plugin\Field\FieldWidget\LinkWidget                                        
  menu_item_extras_view_mode_selector_select   Drupal\menu_item_extras\Plugin\Field\FieldWidget\MenuItemExtrasViewModeSelectorSelect  
  moderation_state_default                     Drupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget               
  number                                       Drupal\Core\Field\Plugin\Field\FieldWidget\NumberWidget                                
  oembed_textfield                             Drupal\media\Plugin\Field\FieldWidget\OEmbedWidget                                     
  options_buttons                              Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsButtonsWidget                        
  options_select                               Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget                         
  path                                         Drupal\path\Plugin\Field\FieldWidget\PathWidget                                        
  string_textarea                              Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextareaWidget                        
  string_textfield                             Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget                       
  text_textarea                                Drupal\text\Plugin\Field\FieldWidget\TextareaWidget                                    
  text_textarea_with_summary                   Drupal\text\Plugin\Field\FieldWidget\TextareaWithSummaryWidget                         
  text_textfield                               Drupal\text\Plugin\Field\FieldWidget\TextfieldWidget                                   
  uri                                          Drupal\Core\Field\Plugin\Field\FieldWidget\UriWidget                                   
 -------------------------------------------- --------------------------------------------------------------------------------------- 
4
  • I use your command: drupal debug:plugin field.widget [ERROR] Command "debug:plugin", is not a valid command name.
    – sadeghpro
    Commented Oct 21, 2018 at 13:21
  • Do you have the latest stable version? . I have Drupal 8.6, Drupal Console version 1.8.0 and PHP 7.1.20. This is the command documentation hechoendrupal.gitbooks.io/drupal-console/en/commands/… Commented Oct 21, 2018 at 13:26
  • If you don't have time to debug the issue, you could use the Plugin Class Package to know what module a given plugin belongs to. Commented Oct 21, 2018 at 13:29
  • sry my fault. my apache not running.it's work
    – sadeghpro
    Commented Oct 21, 2018 at 13:37
2

Would like to add that if you want to get list of baseFieldDefinitions available on your installation run

drupal debug:plugin field.field_type

and to get huge list of formatters, run this

drupal debug:plugin field.formatter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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