class MultisiteValidator

Checks that the current site is not part of a multisite.

@internal This is an internal part of Package Manager and may be changed or removed at any time without warning. External code should not interact with this class.

Hierarchy

Expanded class hierarchy of MultisiteValidator

File

core/modules/package_manager/src/Validator/MultisiteValidator.php, line 20

Namespace

Drupal\package_manager\Validator
View source
final class MultisiteValidator implements EventSubscriberInterface {
    use BaseRequirementValidatorTrait;
    use StringTranslationTrait;
    public function __construct(PathLocator $pathLocator) {
    }
    
    /**
     * Validates that the current site is not part of a multisite.
     */
    public function validate(PreOperationStageEvent $event) : void {
        if ($this->isMultisite()) {
            $event->addError([
                $this->t('Drupal multisite is not supported by Package Manager.'),
            ]);
        }
    }
    
    /**
     * Detects if the current site is part of a multisite.
     *
     * @return bool
     *   TRUE if the current site is part of a multisite, otherwise FALSE.
     */
    private function isMultisite() : bool {
        $web_root = $this->pathLocator
            ->getWebRoot();
        if ($web_root) {
            $web_root .= '/';
        }
        $sites_php_path = $this->pathLocator
            ->getProjectRoot() . '/' . $web_root . 'sites/sites.php';
        if (!file_exists($sites_php_path)) {
            return FALSE;
        }
        // @see \Drupal\Core\DrupalKernel::findSitePath()
        $sites = [];
        include $sites_php_path;
        // @see example.sites.php
        return count(array_unique($sites)) > 1;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
BaseRequirementValidatorTrait::getSubscribedEvents public static function Implements EventSubscriberInterface::getSubscribedEvents().
MultisiteValidator::isMultisite private function Detects if the current site is part of a multisite.
MultisiteValidator::validate public function Validates that the current site is not part of a multisite. Overrides BaseRequirementValidatorTrait::validate
MultisiteValidator::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.