You are here

public function DrupalFavicon::__construct in Favicon 7.2

File

src/DrupalFavicon.php, line 10

Class

DrupalFavicon

Code

public function __construct($theme) {
  $this->theme = $theme;

  // @todo Separate this to individual methods
  // @todo Should this check validation for each one before proceeding to the next?
  if (is_file(conf_path() . '/favicon.ico')) {

    // Allow the favicon to be set in sites/mysite.com/favicon.ico.
    $uri = conf_path() . '/favicon.ico';
  }
  elseif ($favicon = theme_get_setting('favicon', $this->theme)) {

    // Otherwise use the theme's default favicon.
    // This needs to be converted to a path relative to the Drupal root since
    // it gets saved as an absolute link.
    $uri = str_replace($GLOBALS['base_url'] . '/', '', $favicon);
  }
  elseif ($favicon_path = theme_get_setting('favicon_path', $this->theme)) {

    // Otherwise use the custom path for the theme's favicon.
    $uri = $favicon_path;
  }
  else {

    // Fallback to the default Drupal favicon file.
    $uri = static::DEFAULT_URI;
  }

  // Convert the URI to a file object.
  $this->file = static::getFileFromUri($uri);
}