function wsdata_field_form_alter in Web Service Data 8
Same name and namespace in other branches
- 2.0.x modules/wsdata_field/wsdata_field.module \wsdata_field_form_alter()
Implements hook_form_alter().
File
- modules/
wsdata_field/ wsdata_field.module, line 122 - Main module file for wsdata_field.
Code
function wsdata_field_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ('node_delete_multiple_confirm_form' !== $form_id && (preg_match('/^node_(.*)_edit_form/', $form_id) || preg_match('/^node_(.*)_form/', $form_id))) {
$entity = $form_state
->getFormObject()
->getEntity();
if ($entity
->getEntityTypeId() == 'node') {
$fields = $entity
->getFieldDefinitions();
foreach ($fields as $field) {
// Get the fields storage definitions.
$field_storage = $field
->getFieldStorageDefinition();
// Check if it has the custom storage flag set to true.
if ($field_storage
->hasCustomStorage()) {
// Check to make sure the object is of type FieldStorageConfig.
if (is_a($field_storage, 'Drupal\\field\\Entity\\FieldStorageConfig')) {
// Fetch the wsfield config entity.
$wsfield_config = \Drupal::service('entity_type.manager')
->getStorage('wsfield_config')
->load($field_storage
->get('field_name'));
if ($wsfield_config != NULL) {
// Make the field hidden by adding a class.
$form[$field_storage
->get('field_name')]['#attributes']['class'][] = 'hidden';
}
}
}
}
}
}
}