function ContentTranslationHandler::entityFormValidate

Same name in other branches
  1. 8.9.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::entityFormValidate()
  2. 10 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::entityFormValidate()
  3. 11.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::entityFormValidate()

Form validation handler for ContentTranslationHandler::entityFormAlter().

Validates the submitted content translation metadata.

File

core/modules/content_translation/src/ContentTranslationHandler.php, line 701

Class

ContentTranslationHandler
Base class for content translation handlers.

Namespace

Drupal\content_translation

Code

public function entityFormValidate($form, FormStateInterface $form_state) {
    if (!$form_state->isValueEmpty('content_translation')) {
        $translation = $form_state->getValue('content_translation');
        // Validate the "authored by" field.
        if (!empty($translation['uid']) && !($account = User::load($translation['uid']))) {
            $form_state->setErrorByName('content_translation][uid', t('The translation authoring username %name does not exist.', [
                '%name' => $account->getAccountName(),
            ]));
        }
        // Validate the "authored on" field.
        if (!empty($translation['created']) && strtotime($translation['created']) === FALSE) {
            $form_state->setErrorByName('content_translation][created', t('You have to specify a valid translation authoring date.'));
        }
    }
}

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