0

I have a custom content entity created with
public static function baseFieldDefinitions(EntityTypeInterface $entity_type).
I just added a field to that entity with
- adding a new $fields['courriel'] = BaseFieldDefinition::create('email')
- creating hook.install file with

function association_update_8101()
{
  \Drupal::entityDefinitionUpdateManager()->applyUpdates();
}

Running update.php has indeed added the field to the corresponding database table and I can access it with my code (for example, I store in that field a copy of user->mail.
But when I use CRUD forms for my Entity (i.e. canonical, add-form, edit-form or collection), I don't see the new field.
What did I miss?

[Edit] my hook.install is now:

function association_update_8101()
{
  $storage_definition = BaseFieldDefinition::create('email')
    ->setLabel(t('Courriel'))
    ->setDescription(t('The email address of the Personne entity.'))
    ->setDefaultValue('')
    ->setReadOnly(TRUE);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('courriel', 'association_personne', 'association_personne', $storage_definition);
}  

I managed to run again update.php with success (at least with no errors): the table has now the new column (Courriel) but I still don't have my CRUD forms showing 'Courriel'.
Is there anything else I need to add to hook_update_8101 to have that done?

3
  • I think the problem is not in the update function itself, but it's more likely that you have a missing line. I think you can inspect what drush is doing, "drush entity updates" Commented Mar 20, 2017 at 16:21
  • You can check also this link, with the change records. drupal.org/node/2554097 Commented Mar 20, 2017 at 16:24
  • I updated hook_update_8101 (see Edit in my post) but still not having CRUD forms showing 'Courriel' :-(
    – gbmapo
    Commented Mar 21, 2017 at 8:03

1 Answer 1

0

It seems I was looking at the wrong place.
Once hook_update_8101 executed, I should have updated myEntityListBuilder.php to be consistent.
The other forms (canonical, add-form, edit-form) were effectively updated.

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.