I've created a custom entity in a custom module and one of the fields on this entity is an entity reference field to a Paragraphs typed entity. The field is created just fine and i can even 'add' a new instance of the custom entity, however when i try to edit the entity the paragraph reference field fails, giving me an error. I get a different error depending on the widget that is selected for the paragraph entity reference field.
If i use an inline entity form based widget I get a Drupal message that This entity (paragraph:37) cannot be reference. in a Drupal message.
If I use a paragraph stable or legacy widget type, I get the error directly in the edit field area without needing to save first that says, You are not allowed to add any of the Paragraphs types.
I am the site admin user and have verified full rights to everything in the permissions tab.
System Versions:
- Drupal 10.3.6
- Paragraphs 8.x-1.18
To Recreate the Error
Create a Paragraph Type to reference
- Make sure Paragraphs module is installed, I'm using
- Create new Paragraph Type called
test_plain - Add a basic plain text field to the
test_plainparagraph type
Create Custom Entity and Module
I used the devel module's drush generate entity:content to make a base scaffolding for a new content entity.
- From command line use
drush generate entity:content - answer questions being sure to adding translatable and revisionable
- Module machine name: cont_ent_test
- Module name [Cont ent test]:
- Entity type label [Cont ent test]:
- Entity type ID [cont_ent_test]:
- Entity class [ContEntTest]:
- Entity base path [/cont-ent-test]:
- Make the entity type fieldable? [Yes]:
- Make the entity type revisionable? [No]: Yes
- Make the entity type translatable? [No]: Yes
- The entity type has bundle? [No]:
- Create canonical page? [Yes]:
- Create entity template? [Yes]:
- Create CRUD permissions? [No]:
- Add "label" base field? [Yes]:
- Add "status" base field? [Yes]:
- Add "created" base field? [Yes]:
- Add "changed" base field? [Yes]:
- Add "author" base field? [Yes]:
- Add "description" base field? [Yes]: No
- Create REST configuration for the entity? [No]:
Update the cont_ent_test Entity With Paragraph Entity Reference Field
Finally we add the paragraph entity reference field to the new custom entity.
// We get the available paragraph entities and make sure we have a `test_plain` entity $paragraph_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('paragraph'); foreach ($paragraph_types as $id => $type_info) { $field_id = 'test_plain'; if ($id == $field_id) { $fields['test_plains'] = BaseFieldDefinition::create('entity_reference_revisions') ->setLabel(t('Test Plain')) ->setRequired(FALSE) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) ->setSetting('target_type', 'paragraph') ->setSetting('handler', 'default:paragraph') ->setSetting('handler_settings', [ 'target_bundles' => [$field_id], ]) ->setDisplayOptions('form', [ 'type' => 'inline_entity_form_complex', // 'settings' => [ // 'form_mode' => 'default', // Use default form mode for paragraphs // 'label_singular' => t(ucwords(str_replace('_', ' ', $field_id))), // 'label_plural' => t(ucwords(str_replace('_', ' ', $field_id)).'s'), // 'override_labels' => TRUE, // ], 'weight' => 30, ]) // ->setDisplayOptions('view', [ // 'type' => 'entity_reference_revisions', // 'label' => 'above', // 'weight' => 30, // ]) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE) ; } } // END - foreach(paragraph type entity) Add/Edit Instance of New Cont Ent Test Entity
Install the new module which will be in the '@to do Add Package' section of the Extend page. Go to Content -> Cont Ent Test the click Add button to create a new instance. Add a Test Plain paragraph in the nested field, and save the instance. 
After saving we can go back and try to edit form.
Without changing anything if we try to save from the edit form we get an error.
If I use a Paragraph type widget then I get this error directly in the paragraph field
The user is the full site admin to everything. For completeness, here is the ContEntTestInterface, which is what is created by the drush generate.
\\ src\ContEntTestInterface.php declare(strict_types=1); namespace Drupal\cont_ent_test; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\user\EntityOwnerInterface; /** * Provides an interface defining a cont ent test entity type. */ interface ContEntTestInterface extends ContentEntityInterface, EntityOwnerInterface, EntityChangedInterface { } Content Type Entity Works
To verify the issue is not with the paragraph entity type, i also created a new Node type (ie content type) via the Drupal Admin interface and added the test_plain paragraph entity ref field to it via the admin UI Manage fields and it works fine. So there is something that enables the paragraphs and node entities to work together that my custom entity is missing, but I can't figure out what it is. The revisioning, translatable, and access seem to be the same from what I can tell.



idand therevision_id.RevisionableContentEntityBase. For the field type to try for paragraph entity ref i got from this stack answer, drupal.stackexchange.com/a/275551/104691, but that could be wrong. They mention something about the rev on edit, but it's not clear to me what they mean. That could be the same thing I'm seeing. What field class should I try that might be more compatible with a paragraph type?entity_reference_revisionsas the field type. Are you saying that the issue is that I'm doing this as part of abaseFieldDefnition()with aBaseFieldDefinition::create('entity_refrence_revisions')and that base fields can't handle this field type?