Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Updater/Theme.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Updater; | |
4 | |
5 use Drupal\Core\Url; | |
6 | |
7 /** | |
8 * Defines a class for updating themes using | |
9 * Drupal\Core\FileTransfer\FileTransfer classes via authorize.php. | |
10 */ | |
11 class Theme extends Updater implements UpdaterInterface { | |
12 | |
13 /** | |
14 * Returns the directory where a theme should be installed. | |
15 * | |
16 * If the theme is already installed, drupal_get_path() will return a valid | |
17 * path and we should install it there. If we're installing a new theme, we | |
18 * always want it to go into /themes, since that's where all the | |
19 * documentation recommends users install their themes, and there's no way | |
20 * that can conflict on a multi-site installation, since the Update manager | |
21 * won't let you install a new theme if it's already found on your system, | |
22 * and if there was a copy in the top-level we'd see it. | |
23 * | |
24 * @return string | |
25 * The absolute path of the directory. | |
26 */ | |
27 public function getInstallDirectory() { | |
28 if ($this->isInstalled() && ($relative_path = drupal_get_path('theme', $this->name))) { | |
29 // The return value of drupal_get_path() is always relative to the site, | |
30 // so prepend DRUPAL_ROOT. | |
31 return DRUPAL_ROOT . '/' . dirname($relative_path); | |
32 } | |
33 else { | |
34 // When installing a new theme, prepend the requested root directory. | |
35 return $this->root . '/' . $this->getRootDirectoryRelativePath(); | |
36 } | |
37 } | |
38 | |
39 /** | |
40 * {@inheritdoc} | |
41 */ | |
42 public static function getRootDirectoryRelativePath() { | |
43 return 'themes'; | |
44 } | |
45 | |
46 /** | |
47 * {@inheritdoc} | |
48 */ | |
49 public function isInstalled() { | |
50 // Check if the theme exists in the file system, regardless of whether it | |
51 // is enabled or not. | |
52 $themes = \Drupal::state()->get('system.theme.files', []); | |
53 return isset($themes[$this->name]); | |
54 } | |
55 | |
56 /** | |
57 * {@inheritdoc} | |
58 */ | |
59 public static function canUpdateDirectory($directory) { | |
60 $info = static::getExtensionInfo($directory); | |
61 | |
62 return (isset($info['type']) && $info['type'] == 'theme'); | |
63 } | |
64 | |
65 /** | |
66 * Determines whether this class can update the specified project. | |
67 * | |
68 * @param string $project_name | |
69 * The project to check. | |
70 * | |
71 * @return bool | |
72 */ | |
73 public static function canUpdate($project_name) { | |
74 return (bool) drupal_get_path('theme', $project_name); | |
75 } | |
76 | |
77 /** | |
78 * {@inheritdoc} | |
79 */ | |
80 public function postInstall() { | |
81 // Update the theme info. | |
82 clearstatcache(); | |
83 \Drupal::service('theme_handler')->rebuildThemeData(); | |
84 } | |
85 | |
86 /** | |
87 * {@inheritdoc} | |
88 */ | |
89 public function postInstallTasks() { | |
90 // Since this is being called outsite of the primary front controller, | |
91 // the base_url needs to be set explicitly to ensure that links are | |
92 // relative to the site root. | |
93 // @todo Simplify with https://www.drupal.org/node/2548095 | |
94 $default_options = [ | |
95 '#type' => 'link', | |
96 '#options' => [ | |
97 'absolute' => TRUE, | |
98 'base_url' => $GLOBALS['base_url'], | |
99 ], | |
100 ]; | |
101 return [ | |
102 $default_options + [ | |
103 '#url' => Url::fromRoute('system.themes_page'), | |
104 '#title' => t('Install newly added themes'), | |
105 ], | |
106 $default_options + [ | |
107 '#url' => Url::fromRoute('system.admin'), | |
108 '#title' => t('Administration pages'), | |
109 ], | |
110 ]; | |
111 } | |
112 | |
113 } |