function SettingsForm::validateLogoManaged

Validate the Logo Managed image element.

Parameters

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

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

1 call to SettingsForm::validateLogoManaged()
SettingsForm::validateForm in core/modules/navigation/src/Form/SettingsForm.php
Form validation handler.

File

core/modules/navigation/src/Form/SettingsForm.php, line 211

Class

SettingsForm
Configure Navigation settings for this site.

Namespace

Drupal\navigation\Form

Code

protected function validateLogoManaged(array $form, FormStateInterface $form_state) : void {
    $logo_managed = $form_state->getValue('logo_managed');
    $config = $this->config('navigation.settings');
    if (empty($logo_managed)) {
        return;
    }
    $width = $config->get('logo_width');
    $height = $config->get('logo_height');
    // Skip if the fid has not been modified.
    $fid = reset($logo_managed);
    if ($fid == $config->get('logo_managed')) {
        return;
    }
    $file = $this->entityTypeManager
        ->getStorage('file')
        ->load($fid);
    if ($fid && !$this->adjustLogoDimensions($file)) {
        $form_state->setErrorByName('logo_managed', $this->t('Image dimensions are bigger than the expected %widthx%height pixels and cannot be used as the navigation logo.', [
            '%width' => $width,
            '%height' => $height,
        ]));
    }
}

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