You are here

public function AdsenseOldSearchSettings::validateForm in Google AdSense integration 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

oldcode/src/Form/AdsenseOldSearchSettings.php, line 255

Class

AdsenseOldSearchSettings
Form for the older adsense search ads settings.

Namespace

Drupal\adsense_oldcode\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $box_background_color = $form_state
    ->getValue('adsense_search_color_box_background');
  $box_text_color = $form_state
    ->getValue('adsense_search_color_box_background');
  if ($box_background_color == '#000000' && $box_text_color == '#000000') {
    $form_state
      ->setValueForElement($form['searchbox']['adsense_search_color_box_text'], '#FFFFFF');
    $this
      ->messenger()
      ->addMessage($this
      ->t('Changing text color due to conflict with background color.'));
  }
  elseif ($box_background_color == '#FFFFFF' && $box_text_color == '#FFFFFF') {
    $form_state
      ->setValueForElement($form['searchbox']['adsense_search_color_box_text'], '#000000');
    $this
      ->messenger()
      ->addMessage($this
      ->t('Changing text color due to conflict with background color.'));
  }
}