You are here

trait ExtensionListTrait in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Installer/ExtensionListTrait.php \Drupal\Core\Installer\ExtensionListTrait

Provides common functionality for the extension list classes.

Hierarchy

File

core/lib/Drupal/Core/Installer/ExtensionListTrait.php, line 8

Namespace

Drupal\Core\Installer
View source
trait ExtensionListTrait {

  /**
   * Static version of the added file names during the installer.
   *
   * @var string[]
   *
   * @internal
   */
  protected static $staticAddedPathNames;

  /**
   * @see \Drupal\Core\Extension\ExtensionList::setPathname()
   */
  public function setPathname($extension_name, $pathname) {
    parent::setPathname($extension_name, $pathname);

    // In the early installer the container is rebuilt multiple times. Therefore
    // we have to keep the added filenames across those rebuilds. This is not a
    // final design, but rather just a workaround resolved at some point,
    // hopefully.
    // @todo Remove as part of https://drupal.org/project/drupal/issues/2934063
    static::$staticAddedPathNames[$extension_name] = $pathname;
  }

  /**
   * @see \Drupal\Core\Extension\ExtensionList::getPathname()
   */
  public function getPathname($extension_name) {
    if (isset($this->addedPathNames[$extension_name])) {
      return $this->addedPathNames[$extension_name];
    }
    elseif (isset($this->pathNames[$extension_name])) {
      return $this->pathNames[$extension_name];
    }
    elseif (isset(static::$staticAddedPathNames[$extension_name])) {
      return static::$staticAddedPathNames[$extension_name];
    }
    elseif (($path_names = $this
      ->getPathnames()) && isset($path_names[$extension_name])) {

      // Ensure we don't have to do path scanning more than really needed.
      foreach ($path_names as $extension => $path_name) {
        static::$staticAddedPathNames[$extension] = $path_name;
      }
      return $path_names[$extension_name];
    }
    throw new \InvalidArgumentException("The {$this->type} {$extension_name} does not exist.");
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExtensionListTrait::$staticAddedPathNames protected static property Static version of the added file names during the installer.
ExtensionListTrait::getPathname public function
ExtensionListTrait::setPathname public function