Drupal investigation

field.post_update.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @file
  4. * Post update functions for Field module.
  5. */
  6. use Drupal\Core\Entity\Entity\EntityFormDisplay;
  7. use Drupal\field\Entity\FieldStorageConfig;
  8. use Drupal\field\Entity\FieldConfig;
  9. /**
  10. * Re-save all field storage config objects to add 'custom_storage' property.
  11. */
  12. function field_post_update_save_custom_storage_property() {
  13. foreach (FieldStorageConfig::loadMultiple() as $field_storage_config) {
  14. $field_storage_config->save();
  15. }
  16. return t('All field storage configuration objects re-saved.');
  17. }
  18. /**
  19. * Fixes the 'handler' setting for entity reference fields.
  20. */
  21. function field_post_update_entity_reference_handler_setting() {
  22. foreach (FieldConfig::loadMultiple() as $field_config) {
  23. $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  24. $item_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem';
  25. $class = $field_type_manager->getPluginClass($field_config->getType());
  26. if ($class === $item_class || is_subclass_of($class, $item_class)) {
  27. // field_field_config_presave() will fix the 'handler' setting on save.
  28. $field_config->save();
  29. }
  30. }
  31. return t('Selection handler for entity reference fields have been adjusted.');
  32. }
  33. /**
  34. * Adds the 'size' setting for email widgets.
  35. */
  36. function field_post_update_email_widget_size_setting() {
  37. foreach (EntityFormDisplay::loadMultiple() as $entity_form_display) {
  38. $changed = FALSE;
  39. foreach ($entity_form_display->getComponents() as $name => $options) {
  40. if (isset($options['type']) && $options['type'] === 'email_default') {
  41. $options['settings']['size'] = '60';
  42. $entity_form_display->setComponent($name, $options);
  43. $changed = TRUE;
  44. }
  45. }
  46. if ($changed) {
  47. $entity_form_display->save();
  48. }
  49. }
  50. return t('The new size setting for email widgets has been added.');
  51. }