function merci_staff_field_widget_form_alter in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2
Same name and namespace in other branches
- 7.2 modules/merci_staff/merci_staff.module \merci_staff_field_widget_form_alter()
File
- modules/
merci_staff/ merci_staff.module, line 282 - merci_staff functions
Code
function merci_staff_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) {
return;
if ($context['instance']['bundle'] == 'merci_reservation' and $context['instance']['field_name'] == 'group_audience') {
$form = $context['form'];
$field = $context['field'];
$instance = $context['instance'];
$langcode = $context['langcode'];
$items = $context['items'];
$delta = $context['delta'];
if (!user_access('manage reservations')) {
return;
}
if (isset($form_state['values'])) {
$node = (array) $form_state['values'] + (array) $form['#node'];
}
else {
$node = $form['#node'];
}
$node = (object) $node;
drupal_static_reset('og_field_audience_options');
unset($element['#input']);
unset($element['#type']);
unset($element['#options']);
unset($element['#default_value']);
unset($element['#attributes']);
unset($element['#disabled']);
// Re-use options widget element validation, to correctly transform
// submitted values from field => delta to delta => field.
// @see options_field_widget().
unset($element['#value_key']);
unset($element['#element_validate']);
unset($element['#properties']);
// Add OG specific context.
unset($element['#opt_group']);
unset($element['#audience']);
unset($element['#hidden_selected_gids']);
$base = $element;
// Recreate the groups and choices based on the submitted name.
merci_staff_load_user((array) $node);
global $user;
$return = og_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $base);
merci_staff_load_user();
$element = $return;
}
}