function imce_field_widget_form_alter in IMCE 8
Same name and namespace in other branches
- 8.2 imce.module \imce_field_widget_form_alter()
Implements hook_field_widget_form_alter().
Alters widget forms that have imce enabled.
File
- ./
imce.module, line 75 - Defines Drupal hooks for imce module.
Code
function imce_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
if ($context['widget']
->getThirdPartySetting('imce', 'enabled')) {
$scheme = $context['items'][$context['delta']]
->getFieldDefinition()
->getSetting('uri_scheme');
if (Imce::access(\Drupal::currentUser(), $scheme)) {
$element['#scheme'] = $scheme;
$class = 'Drupal\\imce\\ImceFileField';
$element['#process'][] = [
$class,
'processWidget',
];
// Make sure default value callbacks are added.
if (empty($element['#file_value_callbacks'])) {
$info = \Drupal::service('element_info')
->getInfo($element['#type']);
if (!empty($info['#file_value_callbacks'])) {
$element['#file_value_callbacks'] = $info['#file_value_callbacks'];
}
}
$element['#file_value_callbacks'][] = [
$class,
'setWidgetValue',
];
}
}
}