You are here

function social_event_type_widget_alter in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  2. 8 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  3. 8.2 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  4. 8.3 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  5. 8.4 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  6. 8.5 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  7. 8.7 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  8. 8.8 modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  9. 10.3.x modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  10. 10.0.x modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  11. 10.1.x modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()
  12. 10.2.x modules/social_features/social_event/modules/social_event_type/social_event_type.module \social_event_type_widget_alter()

Function that does some magic to the event type field.

Parameters

array $form: Form array.

2 calls to social_event_type_widget_alter()
social_event_type_form_node_event_edit_form_alter in modules/social_features/social_event/modules/social_event_type/social_event_type.module
Implements hook_form_FORM_ID_alter().
social_event_type_form_node_event_form_alter in modules/social_features/social_event/modules/social_event_type/social_event_type.module
Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_event/modules/social_event_type/social_event_type.module, line 32
The Social event type module.

Code

function social_event_type_widget_alter(array &$form) {

  /** @var \Drupal\Core\Config\ImmutableConfig $config */
  $config = \Drupal::config('social_event_type.settings');

  // Check if the field is set to mandatory.
  if ($config
    ->get('social_event_type_required') == TRUE) {
    $form['field_event_type']['widget']['#required'] = TRUE;
  }

  // Set the event type label for none.
  if (isset($form['field_event_type']['widget']['#options']['_none'])) {

    // If the field was set to mandatory, remove the _none option.
    if ($config
      ->get('social_event_type_required') == TRUE) {
      unset($form['field_event_type']['widget']['#options']['_none']);
    }
  }

  // Change the widget if more than X.
  if (count($form['field_event_type']['widget']['#options']) >= $config
    ->get('social_event_type_select_changer')) {
    $form['field_event_type']['widget']['#type'] = 'select';
  }
}