function TranslateEditForm::validateForm

Same name in other branches
  1. 9 core/modules/locale/src/Form/TranslateEditForm.php \Drupal\locale\Form\TranslateEditForm::validateForm()
  2. 10 core/modules/locale/src/Form/TranslateEditForm.php \Drupal\locale\Form\TranslateEditForm::validateForm()
  3. 11.x core/modules/locale/src/Form/TranslateEditForm.php \Drupal\locale\Form\TranslateEditForm::validateForm()

Overrides FormBase::validateForm

File

core/modules/locale/src/Form/TranslateEditForm.php, line 157

Class

TranslateEditForm
Defines a translation edit form.

Namespace

Drupal\locale\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
    $langcode = $form_state->getValue('langcode');
    foreach ($form_state->getValue('strings') as $lid => $translations) {
        foreach ($translations['translations'] as $key => $value) {
            if (!locale_string_is_safe($value)) {
                $form_state->setErrorByName("strings][{$lid}][translations][{$key}", $this->t('The submitted string contains disallowed HTML: %string', [
                    '%string' => $value,
                ]));
                $form_state->setErrorByName("translations][{$langcode}][{$key}", $this->t('The submitted string contains disallowed HTML: %string', [
                    '%string' => $value,
                ]));
                $this->logger('locale')
                    ->warning('Attempted submission of a translation string with disallowed HTML: %string', [
                    '%string' => $value,
                ]);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.