- Issue created by @Chi
- πΊπΈUnited States mfb San Francisco
Thanks for reporting, I did not test base fields. Feel free to contribute a patch/MR if you are able, otherwise it's on my list to dig into.
- π·πΊRussia Chi
The simplest fix is just to ignore custom entity types.
- πΊπΈUnited States mfb San Francisco
@Chi if you do that, does status report page warn that the entity schema needs an update?
- πΊπΈUnited States mfb San Francisco
Is there some other method we need to use to work with base fields? Or will EntityDefinitionUpdateManager update base fields?
(The only reason I'm not using EntityDefinitionUpdateManager here already is because of a bug where EntityDefinitionUpdateManager never adds a new index unless there are also other schema changes, but that's not a big deal at all, because we already don't get the index if there is any data in the table; this would change it to "you don't get the index for existing fields, whether or not they have data".)
- Status changed to Needs review
about 1 year ago 10:17pm 8 November 2023 - last update
about 1 year ago 1 pass - πΊπΈUnited States mfb San Francisco
Ok, looks like Drupal\Core\Field\FieldStorageDefinitionInterface doesn't even have a setIndexes() method, fun!
Attached the patch that I have so far, but I didn't yet setup a base field to test it out.
- πΊπΈUnited States mfb San Francisco
Finally created a base field, and #8 doesn't work, as I suspected.
I did find various issues such as π Improve DX of manually applying entity/field storage definition updates Needs work that discuss similar scenarios of needing to set the schema, and e.g. using reflection to access protected methods...
- last update
about 1 year ago 1 pass - πΊπΈUnited States mfb San Francisco
@Chi how about this: I didn't (yet) figure out an API for updating base fields, but we can manually do it.
- π·πΊRussia Chi
I managed to update my entity through this snippet.
$entity_definition_update = \Drupal::service('entity.definition_update_manager'); $current_definition = $entity_definition_update->getFieldStorageDefinition('timezone', 'my_entity'); $new_definition = BaseFieldDefinition::createFromFieldStorageDefinition($current_definition); $entity_definition_update->updateFieldStorageDefinition($new_definition);
- π·πΊRussia Chi
Found some relevant example in Drupal core.
https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/modules/node... - last update
about 1 year ago 1 pass - πΊπΈUnited States mfb San Francisco
New patch with more or less your working code from #11
- π·πΊRussia Chi
That worked for me.
$ drush updb --------- ----------- --------------- --------------------------------------- Module Update ID Type Description --------- ----------- --------------- --------------------------------------- tzfield 8101 hook_update_n 8101 - Add index to time zone fields. --------- ----------- --------------- --------------------------------------- Do you wish to run the specified pending updates? (yes/no) [yes]: > > [notice] Update started: tzfield_update_8101 > [notice] An index has been added to one time zone field. > [notice] Update completed: tzfield_update_8101 [success] Finished performing updates.
- Status changed to Fixed
about 1 year ago 6:26pm 9 November 2023 Automatically closed - issue fixed for 2 weeks with no activity.