function SettingsForm::adjustLogoDimensions

Adjusts the custom logo dimensions according to navigation settings.

Parameters

\Drupal\file\Entity\File $file: The file entity that contains the image.

Return value

bool TRUE if the logo image dimensions are properly adjusted. FALSE otherwise.

1 call to SettingsForm::adjustLogoDimensions()
SettingsForm::validateLogoManaged in core/modules/navigation/src/Form/SettingsForm.php
Validate the Logo Managed image element.

File

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

Class

SettingsForm
Configure Navigation settings for this site.

Namespace

Drupal\navigation\Form

Code

protected function adjustLogoDimensions(File $file) : bool {
    $config = $this->config('navigation.settings');
    $image = $this->imageFactory
        ->get($file->getFileUri());
    if (!$image->isValid()) {
        return FALSE;
    }
    $width = $config->get('logo_width');
    $height = $config->get('logo_height');
    if ($image->getWidth() <= $width && $image->getHeight() <= $height) {
        return TRUE;
    }
    if ($image->scale($width, $height) && $image->save()) {
        $this->messenger()
            ->addStatus($this->t('The image was resized to fit within the navigation logo expected dimensions of %widthx%height pixels. The new dimensions of the resized image are %new_widthx%new_height pixels.', [
            '%width' => $width,
            '%height' => $height,
            '%new_width' => $image->getWidth(),
            '%new_height' => $image->getHeight(),
        ]));
        return TRUE;
    }
    return FALSE;
}

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