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

array|null Array containing the logo dimensions properly adjusted. NULL if fails.

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

File

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

Class

SettingsForm
Configure Navigation settings for this site.

Namespace

Drupal\navigation\Form

Code

protected function adjustLogoDimensions(File $file) : ?array {
  $config = $this->config('navigation.settings');
  $image = $this->imageFactory
    ->get($file->getFileUri());
  if (!$image->isValid()) {
    return NULL;
  }
  $width = $config->get('logo.max.width');
  $height = $config->get('logo.max.height');
  if ($image->getWidth() <= $width && $image->getHeight() <= $height) {
    return [
      'width' => $width,
      'height' => $width,
      'resize' => FALSE,
    ];
  }
  if ($image->scale($width, $height) && $image->save()) {
    return [
      'width' => $image->getWidth(),
      'height' => $image->getHeight(),
      'resize' => TRUE,
    ];
  }
  return NULL;
}

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