Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Edit and Update Entity schema on drupal 8

By editor , 30 September, 2016
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

Tags

  • Drupal 8
  • Code
  • Entity
  • Add new comment

Comments1

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

José San Martin (not verified)

8 years 10 months ago

Unrecommended?

Hello!
Thanks for the snippet, but it looks like it's not recommended. From https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension%21module.api.php/function/hook_update_N/8.5.x

Never call \Drupal::entityDefinitionUpdateManager()::applyUpdates() in an update function, as it will apply updates for any module not only yours, which will lead to unpredictable results.

  • Reply

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer