Commit 0385228c authored by Ben Mullins's avatar Ben Mullins Committed by Chris Wells
Browse files

Issue #3312289 by bnjmnm, narendraR, srishtiiee, rkoller, tim.plunkett,...

Issue #3312289 by bnjmnm, narendraR, srishtiiee, rkoller, tim.plunkett, chrisfromredfin, hotwebmatter, phenaproxima, worldlinemine, simohell, mherchel, benjifisher, mgifford: Svelte UI for install controllers
parent 881be3f7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
enabled_sources:
  - drupalorg_mockapi
allow_ui_install: false
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ svelte:
    - core/drupal
    - core/drupal.debounce
    - core/drupal.dialog
    - core/drupal.announce

tabledrag:
  js:
+21 −12
Original line number Diff line number Diff line
@@ -168,8 +168,15 @@ class InstallerController extends ControllerBase {
    // the PreCreate and PostCreate events. If an exception is caught during
    // PreCreate, there's no stage to destroy and an exception would be raised.
    // So, we check for the presence of a stage before calling destroy().
    if (!$this->installer->isAvailable()) {
      $this->installer->destroy();
    if (!$this->installer->isAvailable() && $this->installer->lockCameFromProjectBrowserInstaller()) {
      // The risks of forcing a destroy with TRUE are understood, which is why
      // we first check if the lock originated from Project Browser. This
      // function is called if an exception is thrown during an install. This
      // can occur during a phase where the stage might not be claimable, so we
      // force-destroy with the TRUE parameter, knowing that the checks above
      // will prevent destroying an Automatic Updates stage or a stage that is
      // in the process of applying.
      $this->installer->destroy(TRUE);
    }
  }

@@ -192,17 +199,16 @@ class InstallerController extends ControllerBase {
  public function inProgress(string $project_id): JsonResponse {
    $requiring = $this->projectBrowserTempStore->get('requiring');
    $core_installing = $this->projectBrowserTempStore->get('installing');
    $status = self::STATUS_IDLE;
    $return = ['status' => self::STATUS_IDLE];

    if (isset($requiring['project_id']) && $requiring['project_id'] === $project_id) {
      $status = self::STATUS_REQUIRING_PROJECT;
      $return['status'] = self::STATUS_REQUIRING_PROJECT;
      $return['phase'] = $requiring['phase'];
    }
    if ($core_installing === $project_id) {
      $status = self::STATUS_INSTALLING_PROJECT;
    }
    $return = ['status' => $status];
    if ($status !== self::STATUS_IDLE) {
      $return['phase'] = $requiring['phase'];
      $return['status'] = self::STATUS_INSTALLING_PROJECT;
    }

    return new JsonResponse($return);
  }

@@ -411,7 +417,7 @@ class InstallerController extends ControllerBase {

    try {
      $stage_id = $this->installer->create();
      $this->setRequiringState($project_id, 'starting install', $stage_id);
      $this->setRequiringState($project_id, 'creating install stage', $stage_id);
    }
    catch (\Exception $e) {
      $this->cancelRequire();
@@ -550,7 +556,10 @@ class InstallerController extends ControllerBase {
      return $this->errorResponse($e, 'project install');
    }
    $this->projectBrowserTempStore->delete('installing');
    return $this->successResponse('project install');
    return new JsonResponse([
      'status' => 0,
      'message' => $this->t('Project @project was installed successfully', ['@project' => $project_id]),
    ]);
  }

}
+28 −3
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\project_browser\Form;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\project_browser\Plugin\ProjectBrowserSourceManager;
@@ -28,6 +29,13 @@ class SettingsForm extends ConfigFormBase {
   */
  protected $cacheBin;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a \Drupal\project_browser\Form\SettingsForm object.
   *
@@ -37,11 +45,14 @@ class SettingsForm extends ConfigFormBase {
   *   The plugin manager.
   * @param \Drupal\Core\Cache\CacheBackendInterface $project_browser_cache
   *   The cache bin.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ProjectBrowserSourceManager $manager, CacheBackendInterface $project_browser_cache) {
  public function __construct(ConfigFactoryInterface $config_factory, ProjectBrowserSourceManager $manager, CacheBackendInterface $project_browser_cache, ModuleHandlerInterface $module_handler) {
    parent::__construct($config_factory);
    $this->manager = $manager;
    $this->cacheBin = $project_browser_cache;
    $this->moduleHandler = $module_handler;
  }

  /**
@@ -51,7 +62,8 @@ class SettingsForm extends ConfigFormBase {
    return new static(
      $container->get('config.factory'),
      $container->get('plugin.manager.project_browser.source'),
      $container->get('cache.project_browser')
      $container->get('cache.project_browser'),
      $container->get('module_handler')
    );
  }

@@ -89,13 +101,26 @@ class SettingsForm extends ConfigFormBase {
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('project_browser.admin_settings');

    // Confirm that package manager is installed and that it provides the
    // CollectIgnoredPathsEvent, added in Package Manager 2.5. The event is
    // required by the UI install feature, so we check for its presence in
    // addition to the module being installed.
    $package_manager_not_ready = !$this->moduleHandler->moduleExists('package_manager') || !class_exists('\Drupal\package_manager\Event\CollectIgnoredPathsEvent');
    $form['allow_ui_install'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Allow installing via UI (experimental)'),
      '#default_value' => $config->get('allow_ui_install'),
      '#description' => $this->t('When enabled (and Package Manager from the Automatic Updates module is installed), modules can be downloaded and enabled via the Project Browser UI.'),
      '#description' => $this->t('When enabled, modules can be downloaded and enabled via the Project Browser UI.'),
      '#disabled' => $package_manager_not_ready,
    ];

    if ($package_manager_not_ready) {
      $form['allow_ui_install_compatiblity'] = [
        '#type' => 'container',
        '#markup' => $this->t('The ability to install modules via the Project Browser UI requires Package Manager version 2.5 or newer. Package Manager is provided as part of the Automatic Updates module.'),
      ];
    }

    $source_plugins = $this->manager->getDefinitions();
    $enabled_sources = $config->get('enabled_sources');
    // Sort the source plugins by the order they're stored in config.
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ class ProjectBrowserRoutes implements ContainerInjectionInterface {
      return [];
    }
    $routes = [];
    $machine_name_regex = '[a-zA-Z_]+';
    $machine_name_regex = '[a-zA-Z0-9_]+';
    $stage_id_regex = '[a-zA-Z0-9_-]+';
    $routes['project_browser.stage.begin'] = new Route(
      '/admin/modules/project_browser/install-begin/{composer_namespace}/{project_id}',
Loading