1 common.inc backdrop_get_logo_info()

Gets the path and dimensions of the site wide logo.

Return value

array An array containing "path", "width", and "height".

File

core/includes/common.inc, line 239
Common functions that many Backdrop modules will need to reference.

Code

function backdrop_get_logo_info() {
  $info = array(
    'path' => '',
    'width' => NULL,
    'height' => NULL,
  );

  // The logo may be needed on pages prior to config being ready, e.g. during
  // installer or on maintenance pages. Default to an empty string if unable to
  // load the configuration.
  try {
    $site_config = config('system.core');

    if ($site_config->get('site_logo_theme')) {
      global $theme;
      $theme_data = list_themes();
      $theme_object = $theme_data[$theme];
      $logo = dirname($theme_object->filename) . '/logo.png';
      if (file_exists($logo)) {
        $info['path'] = $logo;
      }
    }
    elseif ($site_config->get('site_logo_path')) {
      $info['path'] = $site_config->get('site_logo_path');
    }

    // Retrieve stored logo dimensions.
    if ($attributes = $site_config->get('site_logo_attributes')) {
      $info = array_merge($info, $attributes);
    }
    // Set the logo dimensions if not set.
    elseif ($info['path'] && $dimensions = @getimagesize($info['path'])) {
      $attributes = array();
      list($attributes['width'], $attributes['height']) = $dimensions;
      $site_config->set('site_logo_attributes', $attributes);
      $info = array_merge($info, $attributes);
    }
  }
  catch (ConfigException $e) {
    // Use the default empty logo.
  }

  return $info;
}