Chris@0: isInstalled() && ($relative_path = drupal_get_path('theme', $this->name))) { Chris@0: // The return value of drupal_get_path() is always relative to the site, Chris@0: // so prepend DRUPAL_ROOT. Chris@0: return DRUPAL_ROOT . '/' . dirname($relative_path); Chris@0: } Chris@0: else { Chris@0: // When installing a new theme, prepend the requested root directory. Chris@0: return $this->root . '/' . $this->getRootDirectoryRelativePath(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getRootDirectoryRelativePath() { Chris@0: return 'themes'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function isInstalled() { Chris@0: // Check if the theme exists in the file system, regardless of whether it Chris@0: // is enabled or not. Chris@0: $themes = \Drupal::state()->get('system.theme.files', []); Chris@0: return isset($themes[$this->name]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function canUpdateDirectory($directory) { Chris@0: $info = static::getExtensionInfo($directory); Chris@0: Chris@0: return (isset($info['type']) && $info['type'] == 'theme'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Determines whether this class can update the specified project. Chris@0: * Chris@0: * @param string $project_name Chris@0: * The project to check. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public static function canUpdate($project_name) { Chris@0: return (bool) drupal_get_path('theme', $project_name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function postInstall() { Chris@0: // Update the theme info. Chris@0: clearstatcache(); Chris@0: \Drupal::service('theme_handler')->rebuildThemeData(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function postInstallTasks() { Chris@17: // Since this is being called outside of the primary front controller, Chris@0: // the base_url needs to be set explicitly to ensure that links are Chris@0: // relative to the site root. Chris@0: // @todo Simplify with https://www.drupal.org/node/2548095 Chris@0: $default_options = [ Chris@0: '#type' => 'link', Chris@0: '#options' => [ Chris@0: 'absolute' => TRUE, Chris@0: 'base_url' => $GLOBALS['base_url'], Chris@0: ], Chris@0: ]; Chris@0: return [ Chris@0: $default_options + [ Chris@0: '#url' => Url::fromRoute('system.themes_page'), Chris@0: '#title' => t('Install newly added themes'), Chris@0: ], Chris@0: $default_options + [ Chris@0: '#url' => Url::fromRoute('system.admin'), Chris@0: '#title' => t('Administration pages'), Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: Chris@0: }