Chris@0: isInstalled() && ($relative_path = drupal_get_path('module', $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 module, 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 'modules'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function isInstalled() { Chris@0: // Check if the module exists in the file system, regardless of whether it Chris@0: // is enabled or not. Chris@17: /** @var \Drupal\Core\Extension\ExtensionList $module_extension_list */ Chris@17: $module_extension_list = \Drupal::service('extension.list.module'); Chris@17: return $module_extension_list->exists($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'] == 'module'); 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('module', $project_name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns available database schema updates once a new version is installed. Chris@0: * Chris@0: * @return array Chris@0: */ Chris@0: public function getSchemaUpdates() { Chris@0: require_once DRUPAL_ROOT . '/core/includes/install.inc'; Chris@0: require_once DRUPAL_ROOT . '/core/includes/update.inc'; Chris@0: Chris@0: if (!self::canUpdate($this->name)) { Chris@0: return []; Chris@0: } Chris@0: module_load_include('install', $this->name); Chris@0: Chris@0: if (!$updates = drupal_get_schema_versions($this->name)) { Chris@0: return []; Chris@0: } Chris@0: $modules_with_updates = update_get_update_list(); Chris@0: if ($updates = $modules_with_updates[$this->name]) { Chris@0: if ($updates['start']) { Chris@0: return $updates['pending']; Chris@0: } Chris@0: } Chris@0: return []; 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('update.module_install'), Chris@0: '#title' => t('Install another module'), Chris@0: ], Chris@0: $default_options + [ Chris@0: '#url' => Url::fromRoute('system.modules_list'), Chris@0: '#title' => t('Enable newly added modules'), 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: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function postUpdateTasks() { Chris@0: // We don't want to check for DB updates here, we do that once for all Chris@0: // updated modules on the landing page. Chris@0: } Chris@0: Chris@0: }