2

I created an entity in a module, using code. I generated skeletons with drupal console generate:entity:content (without bundles), and then added a datetime field to my TestFieldEntityItem.php, in baseFieldDefinitions().

$fields['test_date_incode'] = BaseFieldDefinition::create('datetime')
  ->setLabel(t('Test date'))
  ->setDescription(t('Test.'))
  ->setRevisionable(TRUE)
  ->setSettings([
    'datetime_type' => 'date'
  ])
  ->setDefaultValue('')
  ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'datetime_default',
    'settings' => [
      'format_type' => 'medium',
    ],
    'weight' => 14,
  ])
  ->setDisplayOptions('form', [
    'type' => 'datetime',
    'weight' => 14,
  ])
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);

I can add data to my entity, without problem, but if I want to add another field (a simple text field) through the UI, I get this error:

Un problème est survenu à la création du champ test_text : The "datetime" plugin does not exist.

(In English, the error message is A problem occurred creating field test_text: The "datetime" plugin does not exist.)

The field is created, but I don't like this error. It seems my code to create the datetime field is not the right one. I use the Calendar module, if this could have any incidence.

3

Hard to tell which plugin is missing. A guess would be it is a missing field widget plugin which causes the error when you try to add a new field to the default form mode. Then change the plugin name to something like this:

  ->setDisplayOptions('form', [
    'type' => 'datetime_default',

If this is not the error, then provide a full error message with a backtrace.

  • YOU. ARE. AMAZING. I didn't understand what "Plugin" mean here, and I had no other error. Thanks ! – Grubshka Aug 18 '17 at 20:19

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.