Invalid Condition Handled

Created on 12 April 2024, 8 months ago
Updated 7 June 2024, 6 months ago

Problem/Motivation

Invalid Condition Handled in validateLanguageFrontPageElement and updateLanguageFrontPageElement functions

$languages = $this->languageManager->getLanguages();
    $site_config = $this->configFactory->getEditable('system.site');
    foreach ($languages as $language) {
      if (!$language->isDefault()) {
        $language_id = str_replace('-', '', $language->getId());
        $site_config->set('page.front_' . $language_id, $formState->getValue('site_frontpage_' . $language_id));
      }
    }

and

$languages = $this->languageManager->getLanguages();
    foreach ($languages as $language) {
      if (!$language->isDefault()) {
        $language_id = str_replace('-', '', $language->getId());
        // Get the normal path of the front page.
        $formState->setValueForElement($form['front_page']['site_frontpage_' . $language_id], $this->aliasManager->getPathByAlias($formState->getValue('site_frontpage_' . $language_id)));
        // Validate front page path.
        if (($value = $formState->getValue('site_frontpage_' . $language_id)) && $value[0] !== '/') {
          $formState->setErrorByName('site_frontpage_' . $language_id, $this->t("The path '%path' has to start with a slash.", ['%path' => $formState->getValue('site_frontpage_' . $language_id)]));
        }
        if (!$this->pathValidator->isValid($formState->getValue('site_frontpage_' . $language_id))) {
          $formState->setErrorByName('site_frontpage_' . $language_id, $this->t("Either the path '%path' is invalid or you do not have access to it.", ['%path' => $formState->getValue('site_frontpage_' . $language_id)]));
        }
      }
    }

in this code if $languages is null the for loop will give error in both code

Steps to reproduce

should handle empty array condition like addLanguageFrontPageElement() function

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇮🇳India govind_giri_goswami

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024