Unable to add entity reference fields on Bookable calendar entities

Created on 29 August 2023, about 1 year ago

Problem/Motivation

Adding an (entity reference) field to bookable calendar entities leads to an error message:

Error message
There was a problem creating field Product variation ref: The "integer" plugin does not exist. Valid plugin IDs for Drupal\Core\Field\WidgetPluginManager are: address_default, address_country_default, ..., commerce_product_variation_attributes, commerce_product_variation_title,...

I'm trying to add a commerce product variation reference (reference "Other") to the bookable calendar opening instance, but it doesn't work. In fact I receive the same error while adding any other field type, whether reference fields or not. Ultimately an entity reference field is created, but only content entities are available for selection.

Steps to reproduce

What I am aiming to do is this: Whenever a slot is booked, a corresponding commerce product variation (referenced by the entity ref field that I'm now unable to create) is added the basket. I'm trying to achieve commerce integration with the help of additional modules (ECA in particular). But I get stuck at the very start of my journey... Thanks for any helpful idea.

💬 Support request
Status

Fixed

Version

2.2

Component

Documentation

Created by

🇮🇪Ireland marksmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @marksmith
  • 🇺🇸United States josh.fabean Florida

    Can confirm I get the same exact error. That is strange, checking around integer is a valid base field definition that is used in Drupal Core.

    Here is an example from core core/lib/Drupal/Core/Entity/ContentEntityBase.php

    $fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer')
            ->setLabel(new TranslatableMarkup('ID'))
            ->setReadOnly(TRUE)
            ->setSetting('unsigned', TRUE);
    

    Here is how this module does it.

    $fields['slots'] = BaseFieldDefinition::create('integer')
          ->setLabel(t('Slots'))
          ->setDescription(t("The number of available slots for this instance. If empty (NB not zero), will use calendar's defaults."))
          ->setCardinality(1)
          ->setDisplayOptions('form', [
            'type' => 'integer',
            'weight' => 10,
          ])
          ->setSetting('min', 0)
          ->setDisplayConfigurable('form', TRUE)
          ->setDisplayConfigurable('view', TRUE);
    

    I see other drupal core issues that address having the same issue not sure I see a solution yet though. I'll look and see if I can find anything.

  • 🇮🇪Ireland marksmith

    Ok, now I see it. The problem is with this line of code:

          ->setDisplayOptions('form', [
            'type' => 'integer',
            'weight' => 10,
          ])

    which should be:

          ->setDisplayOptions('form', [
            'widget_type' => 'integer',
            'weight' => 10,
          ])

    This code change solves the problem in my case.

    • josh.fabean committed 214d8f3f on 2.2.x
      Issue #3384065 by marksmith, josh.fabean: Unable to add entity reference...
  • Status changed to Fixed about 1 year ago
  • 🇺🇸United States josh.fabean Florida

    Good find, got that fixed and pushed to new version 2.2.9.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024