1 common.inc backdrop_get_favicon()

Gets the file location and mime type for site favicon.

Falls back to the Backdrop favicon if not defined or theme provided.

Return value

(array) $favicon: Information about the favicon to use for the site. Keys include:

  • path: Relative path to the file to be used.
  • type: mime type for the icon being used.

File

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

Code

function backdrop_get_favicon() {
  $favicon = array(
    'path' => file_create_url('core/misc/favicon.ico'),
    'type' => 'image/vnd.microsoft.icon',
  );

  // Load the config and update, if we can.
  try {
    $site_config = config('system.core');

    if ($site_config->get('site_favicon_theme')) {
      global $theme;
      $theme_data = list_themes();
      $theme_object = $theme_data[$theme];
      $theme_favicon = dirname($theme_object->filename) . '/favicon.ico';
      if (file_exists($theme_favicon)) {
        $favicon['path'] = file_create_url($theme_favicon);
      }
    }
    elseif ($site_config->get('site_favicon_path')) {
      $favicon['path'] = file_create_url($site_config->get('site_favicon_path'));
      $favicon['type'] = $site_config->get('site_favicon_mimetype');
    }
  }
  catch (ConfigException $e) {
    // Use the default.
  }

  // Safety check to prevent user-provided javascript: URLs or the like.
  $favicon['path'] = backdrop_strip_dangerous_protocols($favicon['path']);

  return $favicon;
}