Edit and Update Entity schema on drupal 8 | Drupal 8

Edit and Update Entity schema on drupal 8

Submitted by editor on Fri, 09/30/2016 - 15:40
Question

How to update schema (field definition) of an Entity of a drupal 8 custom entity ?

Add a new field:

Example 1 Automatic update:

1. Update baseFieldDefinitions() of the Entity.
2. Apply update from a mymodule_update_N(). Ex:

function mymodule_update_8001() {
  //Update Entitys from baseFieldDefinitions();
  \Drupal::entityDefinitionUpdateManager()->applyUpdates();
}

 

Examples from : https://www.drupal.org/node/2554097

API : https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityDefinitionUpdateManager.php/class/EntityDefinitionUpdateManager/8.2.x

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.