function thunder_media_field_widget_image_focal_point_form_alter in Thunder 8.2
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.3 modules/thunder_media/thunder_media.module \thunder_media_field_widget_image_focal_point_form_alter()
- 8.4 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 111 - 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')) {
$bundle = 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') {
$bundle = $form_display
->getTargetBundle();
}
elseif (isset($context['form']['#type']) && $context['form']['#type'] == 'inline_entity_form' && $context['form']['#entity_type'] == 'media') {
$bundle = $context['form']['#bundle'];
}
if ($bundle) {
/** @var \Drupal\media_entity\MediaBundleInterface $bundle */
$bundle = \Drupal::entityTypeManager()
->getStorage('media_bundle')
->load($bundle);
if ($bundle
->getTypeConfiguration()['source_field'] == $element['#field_name']) {
$element['#process'][] = 'thunder_media_inline_entity_form_image_widget_process';
}
}
}
}