getSourceStorage example

$default_install_path = $this->getDefaultConfigDirectory($type$name);
    if (is_dir($default_install_path)) {
      if (!$this->isSyncing()) {
        $storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
        $prefix = '';
      }
      else {
        // The configuration importer sets the source storage on the config         // installer. The configuration importer handles all of the         // configuration entity imports. We only need to ensure that simple         // configuration is created when the extension is installed.         $storage = $this->getSourceStorage();
        $prefix = $name . '.';
      }

      // Gets profile storages to search for overrides if necessary.       $profile_storages = $this->getProfileStorages($name);

      // Gather information about all the supported collections.       $collection_info = $this->configManager->getConfigCollectionInfo();
      foreach ($collection_info->getCollectionNames() as $collection) {
        $config_to_create = $this->getConfigToCreate($storage$collection$prefix$profile_storages);
        if ($name == $this->drupalGetProfile()) {
          


  /** * Populates the extension change list. */
  protected function createExtensionChangelist() {
    // Create an empty changelist.     $this->extensionChangelist = $this->getEmptyExtensionsProcessedList();

    // Read the extensions information to determine changes.     $current_extensions = $this->storageComparer->getTargetStorage()->read('core.extension');
    $new_extensions = $this->storageComparer->getSourceStorage()->read('core.extension');

    // If there is no extension information in sync then exit. This is probably     // due to an empty sync directory.     if (!$new_extensions) {
      return;
    }

    // Reset the module list in case a stale cache item has been set by another     // process during deployment.     $this->moduleExtensionList->reset();
    // Get a list of modules with dependency weights as values.
/** * {@inheritdoc} */
  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    foreach (['update', 'delete'] as $op) {
      $unprocessed_configurations = $event->getConfigImporter()->getUnprocessedConfiguration($op);
      foreach ($unprocessed_configurations as $unprocessed_configuration) {
        if ($workflow = $this->getWorkflow($unprocessed_configuration)) {
          if ($op === 'update') {
            $original_workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->getSourceStorage()
              ->read($unprocessed_configuration);
            $workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->getTargetStorage()
              ->read($unprocessed_configuration);
            $diff = array_diff_key($workflow_config['type_settings']['states']$original_workflow_config['type_settings']['states']);
            foreach (array_keys($diff) as $state_id) {
              $state = $workflow->getTypePlugin()->getState($state_id);
              if ($workflow->getTypePlugin()->workflowStateHasData($workflow$state)) {
                $event->getConfigImporter()->logError($this->t('The moderation state @state_label is being used, but is not in the source storage.', ['@state_label' => $state->label()]));
              }
            }
/** * Checks that the configuration synchronization is valid. * * This event listener prevents deleting all configuration. If there is * nothing to import then event propagation is stopped because there is no * config import to validate. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The config import event. */
  public function onConfigImporterValidateNotEmpty(ConfigImporterEvent $event) {
    $importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll();
    if (empty($importList)) {
      $event->getConfigImporter()->logError($this->t('This import is empty and if applied would delete all of your configuration, so has been rejected.'));
      $event->stopPropagation();
    }
  }

  /** * Checks that the configuration synchronization is valid. * * This event listener checks that the system.site:uuid's in the source and * target match. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The config import event. */

        public function setSourceStorage(\Drupal\Core\Config\StorageInterface $storage)
        {
            return $this->lazyLoadItself()->setSourceStorage($storage);
        }

        /** * {@inheritdoc} */
        public function getSourceStorage()
        {
            return $this->lazyLoadItself()->getSourceStorage();
        }

        /** * {@inheritdoc} */
        public function setSyncing($status)
        {
            return $this->lazyLoadItself()->setSyncing($status);
        }

        /** * {@inheritdoc} */

  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    // Make sure config syncs performed via the Config UI don't break, but     // don't worry about syncs initiated via the command line.     if (PHP_SAPI === 'cli') {
      return;
    }
    $importer = $event->getConfigImporter();
    $core_extension = $importer->getStorageComparer()->getSourceStorage()->read('core.extension');
    if (!isset($core_extension['module']['config'])) {
      $importer->logError($this->t('Can not uninstall the Configuration module as part of a configuration synchronization through the user interface.'));
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidate', 20];
    return $events;
  }

  protected function addChangelistUpdate($collection) {
    $recreates = [];
    foreach (array_intersect($this->sourceNames[$collection]$this->targetNames[$collection]) as $name) {
      $source_data = $this->getSourceStorage($collection)->read($name);
      $target_data = $this->getTargetStorage($collection)->read($name);
      if ($source_data !== $target_data) {
        if (isset($source_data['uuid']) && $source_data['uuid'] !== $target_data['uuid']) {
          // The entity has the same file as an existing entity but the UUIDs do           // not match. This means that the entity has been recreated so config           // synchronization should do the same.           $recreates[] = $name;
        }
        else {
          $this->addChangeList($collection, 'update', [$name]);
        }
      }
foreach ($event->getConfigImporter()->getUnprocessedConfiguration($op) as $name) {
        try {
          Config::validateName($name);
        }
        catch (ConfigNameException $e) {
          $message = $this->t('The config name @config_name is invalid.', ['@config_name' => $name]);
          $event->getConfigImporter()->logError($message);
        }
      }
    }
    $config_importer = $event->getConfigImporter();
    if ($config_importer->getStorageComparer()->getSourceStorage()->exists('core.extension')) {
      $this->validateModules($config_importer);
      $this->validateThemes($config_importer);
      $this->validateDependencies($config_importer);
    }
    else {
      $config_importer->logError($this->t('The core.extension configuration does not exist.'));
    }
  }

  /** * Validates module installations and uninstallations. * * @param \Drupal\Core\Config\ConfigImporter $config_importer * The configuration importer. */

  protected static function initializeSandbox(array &$context, ConfigImporter $config_importer) {
    $context['sandbox']['field']['purge_batch_size'] = \Drupal::config('field.settings')->get('purge_batch_size');
    // Save the future list of installed extensions to limit the amount of times     // the configuration is read from disk.     $context['sandbox']['field']['extensions'] = $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension');

    $context['sandbox']['field']['steps_to_delete'] = 0;
    $fields = static::getFieldStoragesToPurge($context['sandbox']['field']['extensions']$config_importer->getUnprocessedConfiguration('delete'));
    foreach ($fields as $field) {
      $row_count = \Drupal::entityTypeManager()->getStorage($field->getTargetEntityTypeId())
        ->countFieldData($field);
      if ($row_count > 0) {
        // The number of steps to delete each field is determined by the         // purge_batch_size setting. For example if the field has 9 rows and the         // batch size is 10 then this will add 1 step to $number_of_steps.         $how_many_steps = ceil($row_count / $context['sandbox']['field']['purge_batch_size']);
        
      arsort($module_list);
      $module_list = array_keys($module_list);
    }

    // Required for module installation checks.     include_once $this->root . '/core/includes/install.inc';

    /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */
    $config_installer = \Drupal::service('config.installer');
    $sync_status = $config_installer->isSyncing();
    if ($sync_status) {
      $source_storage = $config_installer->getSourceStorage();
    }
    $modules_installed = [];
    foreach ($module_list as $module) {
      $enabled = $extension_config->get("module.$module") !== NULL;
      if (!$enabled) {
        // Throw an exception if the module name is too long.         if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) {
          throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters');
        }

        // Load a new config object for each iteration, otherwise changes made
Home | Imprint | This part of the site doesn't use cookies.