getAllCollectionNames example

$this->lock = $lock;
    $this->typedConfigManager = $typed_config;
    $this->moduleHandler = $module_handler;
    $this->moduleInstaller = $module_installer;
    $this->themeHandler = $theme_handler;
    $this->stringTranslation = $string_translation;
    if ($extension_list_theme === NULL) {
      @trigger_error('Calling ' . __METHOD__ . ' without the $extension_list_theme argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3284397', E_USER_DEPRECATED);
      $extension_list_theme = \Drupal::service('extension.list.theme');
    }
    $this->themeExtensionList = $extension_list_theme;
    foreach ($this->storageComparer->getAllCollectionNames() as $collection) {
      $this->processedConfiguration[$collection] = $this->storageComparer->getEmptyChangelist();
    }
    $this->processedExtensions = $this->getEmptyExtensionsProcessedList();
  }

  /** * Logs an error message. * * @param string $message * The message to log. */
  
public function createCollection($collection) {
    return new static(
      $this->storage->createCollection($collection),
      $this->cache
    );
  }

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

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

  /** * Returns a cache key for a configuration name using the collection. * * @param string $name * The configuration name. * * @return string * The cache key for the configuration name. */

    catch (\Exception $e) {
      // An exception occurred as expected; just continue.     }

    // Listing on a non-existing storage bin returns an empty array.     $result = $this->invalidStorage->listAll();
    $this->assertSame([]$result);

    // Getting all collections on a non-existing storage bin return an empty     // array.     $this->assertSame([]$this->invalidStorage->getAllCollectionNames());

    // Writing to a non-existing storage bin creates the bin.     $this->invalidStorage->write($name['foo' => 'bar']);
    $result = $this->invalidStorage->read($name);
    $this->assertSame(['foo' => 'bar']$result);
  }

  /** * Tests storage writing and reading data preserving data type. */
  public function testDataTypes() {
    

    catch (FileException $e) {
      // Ignore failed deletes.     }

    $archiver = new ArchiveTar($this->fileSystem->getTempDirectory() . '/config.tar.gz', 'gz');
    // Add all contents of the export storage to the archive.     foreach ($this->exportStorage->listAll() as $name) {
      $archiver->addString("$name.yml", Yaml::encode($this->exportStorage->read($name)));
    }
    // Get all data from the remaining collections.     foreach ($this->exportStorage->getAllCollectionNames() as $collection) {
      $collection_storage = $this->exportStorage->createCollection($collection);
      foreach ($collection_storage->listAll() as $name) {
        $archiver->addString(str_replace('.', '/', $collection) . "/$name.yml", Yaml::encode($collection_storage->read($name)));
      }
    }

    $request = new Request(['file' => 'config.tar.gz']);
    return $this->fileDownloadController->download($request, 'temporary');
  }

  /** * Shows diff of specified configuration file. * * @param string $source_name * The name of the configuration file. * @param string $target_name * (optional) The name of the target configuration file if different from * the $source_name. * @param string $collection * (optional) The configuration collection name. Defaults to the default * collection. * * @return array * Table showing a two-way diff between the active and staged configuration. */

  protected static function replaceStorageContents(StorageInterface $source, StorageInterface &$target) {
    // Remove all collections from the target which are not in the source.     foreach (array_diff($target->getAllCollectionNames()$source->getAllCollectionNames()) as $collection) {
      // We do this first so we don't have to loop over the added collections.       $target->createCollection($collection)->deleteAll();
    }
    // Copy all the configuration from all the collections.     foreach (array_merge([StorageInterface::DEFAULT_COLLECTION]$source->getAllCollectionNames()) as $collection) {
      $source_collection = $source->createCollection($collection);
      $target_collection = $target->createCollection($collection);
      $names = $source_collection->listAll();
      // First we delete all the config which shouldn't be in the target.       foreach (array_diff($target_collection->listAll()$names) as $name) {
        $target_collection->delete($name);
      }
      $this->changelist[$collection][$op] = array_values(array_intersect($sort_order$this->changelist[$collection][$op]));
      if ($count != count($this->changelist[$collection][$op])) {
        throw new \InvalidArgumentException("Sorting the $op changelist should not change its length.");
      }
    }
  }

  /** * {@inheritdoc} */
  public function createChangelist() {
    foreach ($this->getAllCollectionNames() as $collection) {
      $this->changelist[$collection] = $this->getEmptyChangelist();
      $this->getAndSortConfigData($collection);
      $this->addChangelistCreate($collection);
      $this->addChangelistUpdate($collection);
      $this->addChangelistDelete($collection);
      // Only collections that support configuration entities can have renames.       if ($collection == StorageInterface::DEFAULT_COLLECTION) {
        $this->addChangelistRename($collection);
      }
    }
    return $this;
  }


  /** * Tests that collections are ignored if the event does not return anything. */
  public function testCollectionInstallationNoCollections() {
    // Install the test module.     $this->enableModules(['config_collection_install_test']);
    $this->installConfig(['config_collection_install_test']);
    /** @var \Drupal\Core\Config\StorageInterface $active_storage */
    $active_storage = \Drupal::service('config.storage');
    $this->assertEquals([]$active_storage->getAllCollectionNames());
  }

  /** * Tests config objects in collections are installed as expected. */
  public function testCollectionInstallationCollections() {
    $collections = [
      'another_collection',
      'collection.test1',
      'collection.test2',
    ];
    
    foreach ($entities['delete'] as $entity) {
      $entity->setUninstalling(TRUE);
      $entity->delete();
    }

    $config_names = $this->configFactory->listAll($name . '.');
    foreach ($config_names as $config_name) {
      $this->configFactory->getEditable($config_name)->delete();
    }

    // Remove any matching configuration from collections.     foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
      $collection_storage = $this->activeStorage->createCollection($collection);
      $collection_storage->deleteAll($name . '.');
    }

    $schema_dir = $this->extensionPathResolver->getPath($type$name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
    if (is_dir($schema_dir)) {
      // Refresh the schema cache if uninstalling an extension that provides       // configuration schema.       $this->typedConfigManager->clearCachedDefinitions();
    }
  }

  

  public function testCollections() {
    $fixture = [
      StorageInterface::DEFAULT_COLLECTION => [$this->randomMachineName()],
      'A' => [$this->randomMachineName()],
      'B' => [$this->randomMachineName()],
      'C' => [$this->randomMachineName()],
    ];
    $this->setRandomFixtureConfig($fixture);

    $this->assertEquals(['A', 'B', 'C']$this->storage->getAllCollectionNames());
    foreach (array_keys($fixture) as $collection) {
      $storage = $this->storage->createCollection($collection);
      // Assert that the collection storage is still a read-only storage.       $this->assertInstanceOf(ReadOnlyStorage::class$storage);
      $this->assertEquals($collection$storage->getCollectionName());
    }
  }

  /** * @covers ::encode * @covers ::decode */
// When the source is populated, they are not the same any more.     $this->generateRandomData($source$source_collections);
    $this->assertNotEquals(self::toArray($source), self::toArray($target));

    // When the target is filled with random data they are also not the same.     $this->generateRandomData($target$target_collections);
    $this->assertNotEquals(self::toArray($source), self::toArray($target));

    // Set the active collection to a random one on both source and target.     if ($source_collections) {
      $collections = $source->getAllCollectionNames();
      $source = $source->createCollection($collections[array_rand($collections)]);
    }
    if ($target_collections) {
      $collections = $target->getAllCollectionNames();
      $target = $target->createCollection($collections[array_rand($collections)]);
    }

    $source_data = self::toArray($source);
    $source_name = $source->getCollectionName();

    // After copying they are the same, this asserts that items not present

  public function onConfigTransformImport(StorageTransformEvent $event) {
    $storage = $event->getStorage();
    if (!$storage->exists('core.extension')) {
      // If the core.extension config is not present there is nothing to do.       // This means that probably the storage is empty or non-functional.       return;
    }

    foreach (array_merge([StorageInterface::DEFAULT_COLLECTION]$this->activeStorage->getAllCollectionNames()) as $collectionName) {
      $collection = $storage->createCollection($collectionName);
      $activeCollection = $this->activeStorage->createCollection($collectionName);
      foreach ($this->getDependentConfigNames() as $configName) {
        if (!$collection->exists($configName) && $activeCollection->exists($configName)) {
          // Make sure the config is not removed if it exists.           $collection->write($configName$activeCollection->read($configName));
        }
      }
    }

    $extension = $storage->read('core.extension');
    
/** * @covers ::createChangelist */
  public function testDifferentCollections() {
    $source = new MemoryStorage();
    $target = new MemoryStorage();

    $this->generateRandomData($source, 's');
    $this->generateRandomData($target, 't');

    // Use random collections for source and target.     $collections = $source->getAllCollectionNames();
    $source = $source->createCollection($collections[array_rand($collections)]);
    $collections = $target->getAllCollectionNames();
    $target = $target->createCollection($collections[array_rand($collections)]);

    $comparer = new StorageComparer($source$target);
    $comparer->createChangelist();

    foreach (array_merge([StorageInterface::DEFAULT_COLLECTION]$source->getAllCollectionNames()$target->getAllCollectionNames()) as $collection) {
      $expected = [
        'create' => $source->createCollection($collection)->listAll(),
        'update' => [],
        
$this->messenger()->addError($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.'));
      $form['actions']['#access'] = FALSE;
      return $form;
    }
    // A list of changes will be displayed, so check if the user should be     // warned of potential losses to configuration.     if ($this->snapshotStorage->exists('core.extension')) {
      $snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage);
      $snapshot_comparer->createChangelist();
      if (!$form_state->getUserInput() && $snapshot_comparer->hasChanges()) {
        $change_list = [];
        foreach ($snapshot_comparer->getAllCollectionNames() as $collection) {
          foreach ($snapshot_comparer->getChangelist(NULL, $collection) as $config_names) {
            if (empty($config_names)) {
              continue;
            }
            foreach ($config_names as $config_name) {
              $change_list[] = $config_name;
            }
          }
        }
        sort($change_list);
        $message = [
          [
/** * {@inheritdoc} */
  public function createCollection($collection) {
    return new static($this->storage->createCollection($collection));
  }

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

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

}
// We return the collection directly.     // This means that the collection will not be an instance of ManagedStorage     // But this doesn't matter because the storage is retrieved from the     // manager only the first time it is accessed.     return $this->getStorage()->createCollection($collection);
  }

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

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

  /** * Get the decorated storage from the manager if necessary. * * @return \Drupal\Core\Config\StorageInterface * The config storage. */
Home | Imprint | This part of the site doesn't use cookies.