function field_name_prefix_remove_form_field_ui_field_storage_add_form_alter in Remove field name prefix 8
Implements hook_form_FORM_ID_alter(). For: field_ui_field_storage_add_form
File
- ./
field_name_prefix_remove.module, line 7
Code
function field_name_prefix_remove_form_field_ui_field_storage_add_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
//Remove the unnecessary field_ prefix.
$language = \Drupal::languageManager()
->getCurrentLanguage();
$form['new_storage_wrapper']['field_name']['#field_prefix'] = '<span dir="' . $language
->getDirection() . '">';
// Attach validate function to prevent adding the field_ prefix.
$form['#validate'][] = 'field_name_prefix_remove_form_field_ui_field_overview_form_remove_field_prefix';
// Increase maximum characters to 32 as per database constraint
$form['new_storage_wrapper']['field_name']['#maxlength'] = 32;
}