function simplify_field_widget_comment_default_form_alter in Simplify 8
Implements hook_field_widget_WIDGET_TYPE_form_alter().
Because of [#2937730] we want to visually-hidden the fields. The comment field in form display actually add the 'comment_default' widget which needs to be preprocessed to hide.
File
- ./
simplify.module, line 327 - Hooks implemented by the simplify module.
Code
function simplify_field_widget_comment_default_form_alter(&$element, FormStateInterface $form_state, $context) {
$entity = $form_state
->getFormObject()
->getEntity();
$entity_type = $entity
->getEntityTypeId();
$entity_bundle_type = NULL;
if ($entity instanceof \Drupal\Core\Entity\ContentEntityBase) {
$type = $entity->type;
$entity_bundle_type = $type ? $type->entity : NULL;
}
// Get array of fields to hide.
$global_fields = _simplify_get_config_value("simplify_{$entity_type}s_global");
$type_fields = $entity_bundle_type ? _simplify_get_config_value('simplify_nodes', [], 'simplify.content_type.' . $entity_bundle_type
->get('type')) : [];
$fields = array_merge($global_fields, $type_fields);
if (isset($fields['comment']) && $fields['comment']) {
$element['#attributes']['class'][] = 'visually-hidden';
$element['status']['#attributes']['class'][] = 'visually-hidden';
}
}