getCollectionName example


        else {
          $target_collection->delete($name);
          \Drupal::logger('config')->notice('Missing required data for configuration: %config', [
            '%config' => $name,
          ]);
        }
      }
    }

    // Make sure that the target is set to the same collection as the source.     $target = $target->createCollection($source->getCollectionName());
  }

}
/** * {@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. */
  


  /** * Tests if new collections created correctly. * * @param string $collection * The collection name. * * @dataProvider providerCollections */
  public function testCreateCollection($collection) {
    $initial_collection_name = $this->storage->getCollectionName();

    // Create new storage with given collection and check it is set correctly.     $new_storage = $this->storage->createCollection($collection);
    $this->assertSame($collection$new_storage->getCollectionName());

    // Check collection not changed in the current storage instance.     $this->assertSame($initial_collection_name$this->storage->getCollectionName());
  }

  /** * Data provider for testing different collections. * * @return array * Returns an array of collection names. */
    for ($i = 0; $i <= 5; $i++) {
      $this->objects[$i] = $this->randomObject();
    }
  }

  /** * Tests CRUD operations. */
  public function testCRUD() {
    $stores = $this->createStorage();
    // Verify that each store returns its own collection name.     $this->assertSame($this->collections[0]$stores[0]->getCollectionName());
    $this->assertSame($this->collections[1]$stores[1]->getCollectionName());

    // Verify that an item can be stored.     $stores[0]->set('foo', $this->objects[0]);
    $this->assertTrue($stores[0]->has('foo'));
    $this->assertEquals($this->objects[0]$stores[0]->get('foo'));
    // Verify that the other collection is not affected.     $this->assertFalse($stores[1]->has('foo'));
    $this->assertNull($stores[1]->get('foo'));

    // Verify that an item can be updated.

  public function set($key$value) {
    if (!$this->lockBackend->acquire($key)) {
      $this->lockBackend->wait($key);
      if (!$this->lockBackend->acquire($key)) {
        throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage.");
      }
    }

    $value = (object) [
      'owner' => $this->owner,
      'data' => $value,
      'updated' => (int) $this->requestStack->getMainRequest()->server->get('REQUEST_TIME'),
    ];
    $this->ensureAnonymousSession();
    $this->storage->setWithExpire($key$value$this->expire);
    $this->lockBackend->release($key);
  }

class NullStorageTest extends UnitTestCase {

  /** * Tests createCollection. */
  public function testCollection() {
    $nullStorage = new NullStorage();
    $collection = $nullStorage->createCollection('test');
    $this->assertInstanceOf(StorageInterface::class$collection);
    $this->assertEquals(StorageInterface::DEFAULT_COLLECTION, $nullStorage->getCollectionName());
    $this->assertEquals('test', $collection->getCollectionName());
    $this->assertSame([]$collection->getAllCollectionNames());
  }

}
protected $targetCacheStorage;

  /** * Constructs the Configuration storage comparer. * * @param \Drupal\Core\Config\StorageInterface $source_storage * Storage object used to read configuration. * @param \Drupal\Core\Config\StorageInterface $target_storage * Storage object used to write configuration. */
  public function __construct(StorageInterface $source_storage, StorageInterface $target_storage) {
    if ($source_storage->getCollectionName() !== StorageInterface::DEFAULT_COLLECTION) {
      $source_storage = $source_storage->createCollection(StorageInterface::DEFAULT_COLLECTION);
    }
    if ($target_storage->getCollectionName() !== StorageInterface::DEFAULT_COLLECTION) {
      $target_storage = $target_storage->createCollection(StorageInterface::DEFAULT_COLLECTION);
    }

    // Wrap the storages in a static cache so that multiple reads of the same     // raw configuration object are not costly.     $this->sourceCacheStorage = new MemoryBackend();
    $this->sourceStorage = new CachedStorage(
      $source_storage,
      
public function testCreateCollection() {
    $memory = new MemoryStorage();
    $include_profile = FALSE;
    $profile = $this->randomMachineName();
    $collectionName = $this->randomMachineName();

    // Set up the storage.     $storage = new ExtensionInstallStorage($memory, InstallStorage::CONFIG_INSTALL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, $include_profile$profile);
    // Create a collection.     $collection = $storage->createCollection($collectionName);

    static::assertEquals($collectionName$collection->getCollectionName());
  }

}
$this->originalData = $this->data;
    return $this;
  }

  /** * Returns the language code of this language override. * * @return string * The language code. */
  public function getLangcode() {
    return $this->getLangcodeFromCollectionName($this->getStorage()->getCollectionName());
  }

}

  public function onConfigSave(ConfigCrudEvent $event) {
    $saved_config = $event->getConfig();

    // We are only concerned with config objects that belong to the collection     // that matches the storage we depend on. Skip if the event was fired for a     // config object belonging to a different collection.     if ($saved_config->getStorage()->getCollectionName() !== $this->storage->getCollectionName()) {
      return;
    }

    // Ensure that the static cache contains up to date configuration objects by     // replacing the data on any entries for the configuration object apart     // from the one that references the actual config object being saved.     foreach ($this->getConfigCacheKeys($saved_config->getName()) as $cache_key) {
      $cached_config = $this->cache[$cache_key];
      if ($cached_config !== $saved_config) {
        // We can not just update the data since other things about the object         // might have changed. For example, whether or not it is new.
      $this->startSession();
      $session = $this->requestStack->getCurrentRequest()->getSession();
      if (!$session->has('core.tempstore.private.owner')) {
        $session->set('core.tempstore.private.owner', Crypt::randomBytesBase64());
      }
    }

    $key = $this->createkey($key);
    if (!$this->lockBackend->acquire($key)) {
      $this->lockBackend->wait($key);
      if (!$this->lockBackend->acquire($key)) {
        throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage.");
      }
    }

    $value = (object) [
      'owner' => $this->getOwner(),
      'data' => $value,
      'updated' => (int) $this->requestStack->getMainRequest()->server->get('REQUEST_TIME'),
    ];
    $this->storage->setWithExpire($key$value$this->expire);
    $this->lockBackend->release($key);
  }

  

  public function __construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher$install_profile, ExtensionPathResolver $extension_path_resolver) {
    $this->configFactory = $config_factory;
    $this->activeStorages[$active_storage->getCollectionName()] = $active_storage;
    $this->typedConfig = $typed_config;
    $this->configManager = $config_manager;
    $this->eventDispatcher = $event_dispatcher;
    $this->installProfile = $install_profile;
    $this->extensionPathResolver = $extension_path_resolver;
  }

  /** * {@inheritdoc} */
  public function installDefaultConfig($type$name) {
    
/** * {@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. */
  protected function getStorage() {
    // Get the storage from the manager the first time it is needed.     if (!isset($this->storage)) {
      

  public function onConfigSave(ConfigCrudEvent $event) {
    // Only validate configuration if in the default collection. Other     // collections may have incomplete configuration (for example language     // overrides only). These are not valid in themselves.     $saved_config = $event->getConfig();
    if ($saved_config->getStorage()->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) {
      return;
    }

    $name = $saved_config->getName();
    $data = $saved_config->get();
    $checksum = Crypt::hashBase64(serialize($data));
    if (!in_array($name$this->exclude) && !isset($this->checked[$name . ':' . $checksum])) {
      $this->checked[$name . ':' . $checksum] = TRUE;
      $errors = $this->checkConfigSchema($this->typedManager, $name$data);
      if ($errors === FALSE) {
        throw new SchemaIncompleteException("No schema for $name");
      }
'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 */
  public function testEncodeDecode() {
    $array = (array) $this->getRandomGenerator()->object();
    $string = $this->getRandomGenerator()->string();

    
Home | Imprint | This part of the site doesn't use cookies.