function thunder_media_field_widget_image_focal_point_form_alter in Thunder 8.4
Same name and namespace in other branches
- 8.5 modules/thunder_media/thunder_media.module \thunder_media_field_widget_image_focal_point_form_alter()
- 8.2 modules/thunder_media/thunder_media.module \thunder_media_field_widget_image_focal_point_form_alter()
- 8.3 modules/thunder_media/thunder_media.module \thunder_media_field_widget_image_focal_point_form_alter()
- 6.2.x modules/thunder_media/thunder_media.module \thunder_media_field_widget_image_focal_point_form_alter()
- 6.0.x modules/thunder_media/thunder_media.module \thunder_media_field_widget_image_focal_point_form_alter()
- 6.1.x modules/thunder_media/thunder_media.module \thunder_media_field_widget_image_focal_point_form_alter()
Implements hook_field_widget_WIDGET_ID_form_alter().
Add process function to hide 'remove' button of image field widget on inline entity forms.
File
- modules/
thunder_media/ thunder_media.module, line 92 - Contains media related functions.
Code
function thunder_media_field_widget_image_focal_point_form_alter(&$element, FormStateInterface $form_state, $context) {
$config = \Drupal::config('thunder_media.settings');
if (!$config
->get('enable_filefield_remove_button')) {
$type = NULL;
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
if (!empty($form_state
->getStorage()['form_display']) && ($form_display = $form_state
->getStorage()['form_display']) && $form_display
->getTargetEntityTypeId() == 'media') {
$type = $form_display
->getTargetBundle();
}
elseif (isset($context['form']['#type']) && $context['form']['#type'] == 'inline_entity_form' && $context['form']['#entity_type'] == 'media') {
$type = $context['form']['#bundle'];
}
if ($type) {
/** @var \Drupal\media\MediaTypeInterface $type */
$type = \Drupal::entityTypeManager()
->getStorage('media_type')
->load($type);
if ($type
->get('source_configuration')['source_field'] == $element['#field_name']) {
$element['#process'][] = 'thunder_media_inline_entity_form_image_widget_process';
}
}
}
}