You are here

function social_content_report_mandatory_reason_validate in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()
  2. 8.5 modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()
  3. 8.6 modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()
  4. 8.7 modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()
  5. 8.8 modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()
  6. 10.0.x modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()
  7. 10.1.x modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()
  8. 10.2.x modules/social_features/social_content_report/social_content_report.module \social_content_report_mandatory_reason_validate()

Validation so the reason description field has content when it is mandatory.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: Form State with the submitted values.

1 string reference to 'social_content_report_mandatory_reason_validate'
social_content_report_form_alter in modules/social_features/social_content_report/social_content_report.module
Implements hook_form_alter().

File

modules/social_features/social_content_report/social_content_report.module, line 75
The Social Content Report module file.

Code

function social_content_report_mandatory_reason_validate(array $form, FormStateInterface $form_state) {
  $terms = \Drupal::config('social_content_report.settings')
    ->get('reasons_with_text');
  if (in_array($form_state
    ->getValue('field_reason')[0]['target_id'], $terms) && empty($form_state
    ->getValue('field_other_reason')[0]['value'])) {
    $form_state
      ->setErrorByName('field_other_reason', t('A description of your report is mandatory.'));
  }
}