I created two custom entities, entity_one and entity_two. entity_one has a entity reference field that allows you to select unlimited instances of entity_twos. The edit form for entity_one seems to work fine. The field exists and properly auto populates with entity_twos. However as soon as I submit and create an entity_one the list page for entity_ones gives me the error.
Error: Call to a member function getValue() on string in DrupalCoreEntityContentEntityBase->__sleep() (line 524 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
If I remove that particular field and just have textfields I do not encounter this behavior. It only occurs when I have the entity reference field. My first instinct was maybe in my EntityOneListBuilder.php it uses a field in the table that isn’t properly formatted but the only fields used are ID and title.
Here is a portion of my EntityOneListBuilder
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('entity_type.manager')->getStorage($entity_type->id()), $container->get('url_generator') ); } public function render() { $build['description'] = [ '#markup' => $this->t('Description Text'), ]; $build['table'] = parent::render(); return $build; } public function buildHeader() { $header['id'] = $this->t('ID'); $header['title'] = $this->t('Title'); return $header + parent::buildHeader(); } public function buildRow(EntityInterface $entity) { $row['id'] = $entity->id(); $row['title'] = $entity->toLink()->toString(); return $row + parent::buildRow($entity); }
And here is how I’m building the entity reference field for entity_one
$fields['entity_twos'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Form Fields')) ->setDescription(t('The fields to add to this form.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'entity_two') ->setTargetEntityTypeId('entity_two') ->setSetting('handler','default') ->setDisplayOptions('view', [ 'label' => 'hidden', 'type' => 'entity_two', 'weight' => 0, ]) ->setDisplayOptions('form', [ 'type' => 'entity_reference_autocomplete', 'weight' => 5, 'settings' => [ 'autocomplete_type' => 'tags', 'size' => '60', 'match_operator' => 'CONTAINS', 'placeholder' => '', ], ]) ->setDisplayConfigurable('form', true) ->setDisplayConfigurable('view', true) ->setRequired(TRUE) ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
Why would that particular field break my collection page?