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