Description of the need
Add hook_field_schema_alter()
, as described in https://www.drupal.org/node/691932, which has been merged into Drupal 7 core as of 7.99. See https://www.drupal.org/node/3406312
For the reasons we have hook_schema_alter() - mainly site-specific tweaks, we should allow the same for field storage.
It would make it easier to implement a contrib module (like date_repeat
) that would alter core fields (like core date fields).
Proposed solution
Apply this patch: https://www.drupal.org/files/issues/2023-03-16/drupal-field_schema_alter... or similar.
Alternatives that have been considered
hook_schema_alter()
can be used too but it requires checking for each table to see if it's of the right field type and also requires also handling field creation and deletion so it's more work than the proposed new hook.
Example implementation
``` /** * Allow modules to alter the schema for a field. * * @param array $schema * The schema definition as returned by hook_field_schema(). * @param array $field * The field definition. * * @see field_retrieve_schema() */ function hook_field_schema_alter(&$schema, $field) { if ($field['type'] == 'image') { // Alter the length of a field. $schema['columns']['alt']['length'] = 2048; // Add an additional column of data. $schema['columns']['additional_column'] = array( 'description' => "Additional column added to image field table.", 'type' => 'varchar', 'length' => 128, 'not null' => FALSE, ); // Add an additional index. $schema['indexes']['fid_additional_column'] = array('fid', 'additional_column'); } } ````
Recent comments
Update. Sorry for the late update, got side-tracked on another project. Decided to do my site updates today and downloaded the 1.30.0 version. I had NO issues (i.e. virus warnings) with the...
Virus warning on 1.29.3 download
Alejandro - Thanks for the additional information. Backdrop is very smart, but I'm not!
Image Library - way to change file name?
@yorkshirepudding Thanks for the explanation - my code writing skills are so poor I could not see anything in the code that pointed me to that answer.
Image Library - way to change file name?