Commit 37bd3765 authored by catch's avatar catch
Browse files

Issue #3124762 by Spokje, dww, johnwebdev, paulocs, piyuesh23, Suresh Prabhu...

Issue #3124762 by Spokje, dww, johnwebdev, paulocs, piyuesh23, Suresh Prabhu Parkala, Deepak Goyal, catch, larowlan, rpsu, xjm, andypost, alexpott, daffie, longwave, fgm, Wim Leers, anmolgoyal74: Add 'lifecycle' key to .info.yml files
parent cc5b85ed
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Extension\Exception;

/**
 * Exception thrown when the extension is obsolete on install.
 */
class ObsoleteExtensionException extends \Exception {}
+61 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Extension;

/**
 * Extension lifecycle.
 *
 * The lifecycle of an extension (module/theme etc) can go through the following
 * progression:
 * 1. Starts "experimental".
 * 2. Stabilizes and goes "stable".
 * 3. Eventually (maybe), becomes "deprecated" when being phased out.
 * 4. Finally (maybe), becomes "obsolete" and can't be enabled anymore.
 */
final class ExtensionLifecycle {

  /**
   * The string used to identify the lifecycle in an .info.yml file.
   */
  const LIFECYCLE_IDENTIFIER = 'lifecycle';

  /**
   * Extension is experimental. Warnings will be shown if installed.
   */
  const EXPERIMENTAL = 'experimental';

  /**
   * Extension is stable. This is the default value of any extension.
   */
  const STABLE = 'stable';

  /**
   * Extension is deprecated. Warnings will be shown if still installed.
   */
  const DEPRECATED = 'deprecated';

  /**
   * Extension is obsolete and installation will be prevented.
   */
  const OBSOLETE = 'obsolete';

  /**
   * Determines if a given extension lifecycle string is valid.
   *
   * @param string $lifecycle
   *   The lifecycle to validate.
   *
   * @return bool
   *   TRUE if the lifecycle is valid, otherwise FALSE.
   */
  public static function isValid(string $lifecycle) : bool {
    $valid_values = [
      self::EXPERIMENTAL,
      self::STABLE,
      self::DEPRECATED,
      self::OBSOLETE,
    ];
    return in_array($lifecycle, $valid_values, TRUE);
  }

}
+10 −0
Original line number Diff line number Diff line
@@ -107,6 +107,16 @@ public function parse($filename) {
      if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') {
        $parsed_info['version'] = \Drupal::VERSION;
      }
      $parsed_info += [ExtensionLifecycle::LIFECYCLE_IDENTIFIER => ExtensionLifecycle::STABLE];
      if (!ExtensionLifecycle::isValid($parsed_info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER])) {
        $valid_values = [
          ExtensionLifecycle::EXPERIMENTAL,
          ExtensionLifecycle::STABLE,
          ExtensionLifecycle::DEPRECATED,
          ExtensionLifecycle::OBSOLETE,
        ];
        throw new InfoParserException("'lifecycle: {$parsed_info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]}' is not valid in $filename. Valid values are: '" . implode("', '", $valid_values) . "'.");
      }
    }
    return $parsed_info;
  }
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ interface InfoParserInterface {
   * - name: The real name of the module for display purposes. (Required)
   * - description: A brief description of the module.
   * - type: whether it is for a module or theme. (Required)
   * - lifecycle: [experimental|stable|deprecated|obsolete]. A description of
   *   the current phase in the lifecycle of the module, theme or profile.
   *
   * Information stored in a module .info.yml file:
   * - dependencies: An array of dependency strings. Each is in the form
+4 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\Core\DrupalKernelInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Extension\Exception\ObsoleteExtensionException;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Serialization\Yaml;

@@ -106,6 +107,9 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
      if (!empty($module_data[$module]->info['core_incompatible'])) {
        throw new MissingDependencyException("Unable to install modules: module '$module' is incompatible with this version of Drupal core.");
      }
      if ($module_data[$module]->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] === ExtensionLifecycle::OBSOLETE) {
        throw new ObsoleteExtensionException("Unable to install modules: module '$module' is obsolete.");
      }
    }
    if ($enable_dependencies) {
      $module_list = $module_list ? array_combine($module_list, $module_list) : [];
Loading