Drupal investigation

profile.install 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the profile module.
  5. */
  6. /**
  7. * Uninstalls the langcode field from the profile entity.
  8. */
  9. function profile_update_8001() {
  10. $definition = \Drupal::entityTypeManager()->getDefinition('profile');
  11. // Allow langcode field to be null.
  12. $schema = \Drupal::database()->schema();
  13. if ($schema->fieldExists($definition->getBaseTable(), 'langcode')) {
  14. $schema->changeField($definition->getBaseTable(), 'langcode', 'langcode', [
  15. 'type' => 'varchar',
  16. 'length' => 12,
  17. 'not null' => FALSE,
  18. ]);
  19. // Set langcode field to null so it can be deleted.
  20. \Drupal::database()
  21. ->update($definition->getBaseTable())
  22. ->fields(['langcode' => NULL])
  23. ->execute();
  24. }
  25. $entity_definition_update = \Drupal::entityDefinitionUpdateManager();
  26. if ($storage_definition = $entity_definition_update->getFieldStorageDefinition('langcode', 'profile')) {
  27. $entity_definition_update->uninstallFieldStorageDefinition($storage_definition);
  28. }
  29. return t('Language code field uninstalled from profile entity.');
  30. }