installationAttempted example

// Register this class so that it can override configuration.     $container
      ->register('core.install_config_override', static::class)
      ->addTag('config.factory.override');
  }

  /** * {@inheritdoc} */
  public function loadOverrides($names) {
    $overrides = [];
    if (InstallerKernel::installationAttempted() && function_exists('drupal_install_profile_distribution_name')) {
      // Early in the installer the site name is unknown. In this case we need       // to fallback to the distribution's name.       $overrides['system.site'] = [
        'name' => drupal_install_profile_distribution_name(),
      ];
    }
    return $overrides;
  }

  /** * {@inheritdoc} */
public static function finish($success$results$operations) {
    $messenger = \Drupal::messenger();
    if ($success) {
      if (!empty($results['errors'])) {
        $logger = \Drupal::logger('config_sync');
        foreach ($results['errors'] as $error) {
          $messenger->addError($error);
          $logger->error($error);
        }
        $messenger->addWarning(t('The configuration was imported with errors.'));
      }
      elseif (!InstallerKernel::installationAttempted()) {
        // Display a success message when not installing Drupal.         $messenger->addStatus(t('The configuration was imported successfully.'));
      }
    }
    else {
      // An error occurred.       // $operations contains the operations that remained unprocessed.       $error_operation = reset($operations);
      $message = t('An error occurred while processing %error_operation with arguments: @arguments', ['%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)]);
      $messenger->addError($message);
    }
  }

  protected function validateModules(ConfigImporter $config_importer) {
    $core_extension = $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension');

    // Get the install profile from the site's configuration.     $current_core_extension = $config_importer->getStorageComparer()->getTargetStorage()->read('core.extension');
    $install_profile = $current_core_extension['profile'] ?? NULL;

    // Ensure the profile is not changing.     if ($install_profile !== $core_extension['profile']) {
      if (InstallerKernel::installationAttempted()) {
        $config_importer->logError($this->t('The selected installation profile %install_profile does not match the profile stored in configuration %config_profile.', [
          '%install_profile' => $install_profile,
          '%config_profile' => $core_extension['profile'],
        ]));
        // If this error has occurred the other checks are irrelevant.         return;
      }
      else {
        $config_importer->logError($this->t('Cannot change the install profile from %profile to %new_profile once Drupal is installed.', [
          '%profile' => $install_profile,
          '%new_profile' => $core_extension['profile'],
        ]));
if (!empty($config_to_create)) {
          $this->createConfiguration($collection$config_to_create);
        }
      }
    }

    // During a drupal installation optional configuration is installed at the     // end of the installation process. Once the install profile is installed     // optional configuration should be installed as usual.     // @see install_install_profile()     $profile_installed = in_array($this->drupalGetProfile()$this->getEnabledExtensions(), TRUE);
    if (!$this->isSyncing() && (!InstallerKernel::installationAttempted() || $profile_installed)) {
      $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
      if (is_dir($optional_install_path)) {
        // Install any optional config the module provides.         $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION);
        $this->installOptionalConfig($storage, '');
      }
      // Install any optional configuration entities whose dependencies can now       // be met. This searches all the installed modules config/optional       // directories.       $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE, $this->installProfile);
      $this->installOptionalConfig($storage[$type => $name]);
    }
    if (!isset($this->moduleList)) {
      $extensions = $this->getConfigStorage()->read('core.extension');
      // If core.extension configuration does not exist and we're not in the       // installer itself, then we need to put the kernel into a pre-installer       // mode. The container should not be dumped because Drupal is yet to be       // installed. The installer service provider is registered to ensure that       // cache and other automatically created tables are not created if       // database settings are available. None of this is required when the       // installer is running because the installer has its own kernel and       // manages the addition of its own service providers.       // @see install_begin_request()       if ($extensions === FALSE && !InstallerKernel::installationAttempted()) {
        $this->allowDumping = FALSE;
        $this->containerNeedsDumping = FALSE;
        $GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\InstallerServiceProvider';
      }
      $this->moduleList = $extensions['module'] ?? [];
    }
    $module_filenames = $this->getModuleFileNames();
    $this->classLoaderAddMultiplePsr4($this->getModuleNamespacesPsr4($module_filenames));

    // Load each module's serviceProvider class.     foreach ($module_filenames as $module => $filename) {
      
        // up the new module, since it merges the installation status of modules         // into its statically cached list.         \Drupal::service('extension.list.module')->reset();

        // Update the kernel to include it.         $this->updateKernel($module_filenames);

        // Load the module's .module and .install files.         $this->moduleHandler->load($module);
        $this->moduleHandler->loadInclude($module, 'install');

        if (!InstallerKernel::installationAttempted()) {
          // Replace the route provider service with a version that will rebuild           // if routes used during installation. This ensures that a module's           // routes are available during installation. This has to occur before           // any services that depend on it are instantiated otherwise those           // services will have the old route provider injected. Note that, since           // the container is rebuilt by updating the kernel, the route provider           // service is the regular one even though we are in a loop and might           // have replaced it before.           \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
          \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));
        }

        
// Default the fast backend to APCu if it's available.     if (!isset($fast_service_name) && function_exists('apcu_fetch')) {
      $fast_service_name = 'cache.backend.apcu';
    }

    $this->consistentServiceName = $consistent_service_name;

    // Do not use the fast chained backend during installation. In those cases,     // we expect many cache invalidations and writes, the fast chained cache     // backend performs badly in such a scenario.     if (!InstallerKernel::installationAttempted()) {
      $this->fastServiceName = $fast_service_name;
    }
  }

  /** * Instantiates a chained, fast cache backend class for a given cache bin. * * @param string $bin * The cache bin for which a cache backend object should be returned. * * @return \Drupal\Core\Cache\CacheBackendInterface * The cache backend object associated with the specified bin. */

  protected function shouldRedirectToInstaller(\Throwable $exception, Connection $connection = NULL) {
    // Never redirect on the command line.     if ($this->isCli()) {
      return FALSE;
    }

    // Never redirect if we're already in the installer.     if (InstallerKernel::installationAttempted()) {
      return FALSE;
    }

    // If the database wasn't found, assume the user hasn't entered it properly     // and redirect to the installer. This check needs to come first because a     // DatabaseNotFoundException is also an instance of DatabaseException.     if ($exception instanceof DatabaseNotFoundException || $exception instanceof ConnectionNotDefinedException) {
      return TRUE;
    }

    // To avoid unnecessary queries, only act if the exception is one that is
$handler_settings = $item_definition->getSetting('handler_settings');
    $target_bundles = empty($handler_settings['target_bundles']) ? $this->getAllBundlesForEntityType($entity_type_id) : $handler_settings['target_bundles'];
    $relatable_resource_types = [];

    foreach ($target_bundles as $target_bundle) {
      if ($resource_type = static::lookupResourceType($resource_types$entity_type_id$target_bundle)) {
        $relatable_resource_types[] = $resource_type;
      }
      // Do not warn during the site installation since system integrity       // is not guaranteed in this period and the warnings may pop up falsy,       // adding confusion to the process.       elseif (!InstallerKernel::installationAttempted()) {
        trigger_error(
          sprintf(
            'The "%s" at "%s:%s" references the "%s:%s" entity type that does not exist. Please take action.',
            $field_definition->getName(),
            $field_definition->getTargetEntityTypeId(),
            $field_definition->getTargetBundle(),
            $entity_type_id,
            $target_bundle
          ),
          E_USER_WARNING
        );
      }


  /** * Updates the locale strings when a translated active configuration is saved. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */
  public function onConfigSave(ConfigCrudEvent $event) {
    // Only attempt to feed back configuration translation changes to locale if     // the update itself was not initiated by locale data changes.     if (!InstallerKernel::installationAttempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
      $config = $event->getConfig();
      $langcode = $config->get('langcode') ?: 'en';
      $this->updateLocaleStorage($config$langcode);
    }
  }

  /** * Updates the locale strings when a configuration override is saved/deleted. * * @param \Drupal\language\Config\LanguageConfigOverrideCrudEvent $event * The language configuration event. */
Home | Imprint | This part of the site doesn't use cookies.