readMultiple example


  public function __construct(StorageInterface $schema_storage) {
    $this->schemaStorage = $schema_storage;
  }

  /** * {@inheritdoc} */
  public function getDefinitions() {
    $definitions = [];
    foreach ($this->schemaStorage->readMultiple($this->schemaStorage->listAll()) as $schema) {
      foreach ($schema as $type => $definition) {
        $definitions[$type] = $definition;
      }
    }
    return $definitions;
  }

}

  public function testCRUD() {
    $name = 'config_test.storage';

    // Checking whether a non-existing name exists returns FALSE.     $this->assertFalse($this->storage->exists($name));

    // Checking whether readMultiple() works with empty storage.     $this->assertEmpty($this->storage->readMultiple([$name]));

    // Reading a non-existing name returns FALSE.     $data = $this->storage->read($name);
    $this->assertFalse($data);

    // Writing data returns TRUE and the data has been written.     $data = ['foo' => 'bar'];
    $result = $this->storage->write($name$data);
    $this->assertTrue($result);

    $raw_data = $this->read($name);
    
// Inform the entity.     return $entity->onDependencyRemoval($affected_dependencies);
  }

  /** * {@inheritdoc} */
  public function findMissingContentDependencies() {
    $content_dependencies = [];
    $missing_dependencies = [];
    foreach ($this->activeStorage->readMultiple($this->activeStorage->listAll()) as $config_data) {
      if (isset($config_data['dependencies']['content'])) {
        $content_dependencies[] = $config_data['dependencies']['content'];
      }
      if (isset($config_data['dependencies']['enforced']['content'])) {
        $content_dependencies[] = $config_data['dependencies']['enforced']['content'];
      }
    }
    $unique_content_dependencies = array_unique(array_merge(...$content_dependencies));
    foreach ($unique_content_dependencies as $content_dependency) {
      // Format of the dependency is entity_type:bundle:uuid.       [$entity_type$bundle$uuid] = explode(':', $content_dependency, 3);
      
$cache_keys_map = $this->getCacheKeys($names);
    $cache_keys = array_values($cache_keys_map);
    $cached_list = $this->cache->getMultiple($cache_keys);

    if (!empty($cache_keys)) {
      // $cache_keys_map contains the full $name => $cache_key map, while       // $cache_keys contains just the $cache_key values that weren't found in       // the cache.       // @see \Drupal\Core\Cache\CacheBackendInterface::getMultiple()       $names_to_get = array_keys(array_intersect($cache_keys_map$cache_keys));
      $list = $this->storage->readMultiple($names_to_get);
      // Cache configuration objects that were loaded from the storage, cache       // missing configuration objects as an explicit FALSE.       $items = [];
      foreach ($names_to_get as $name) {
        $data = $list[$name] ?? FALSE;
        $data_to_return[$name] = $data;
        $items[$cache_keys_map[$name]] = ['data' => $data];
      }

      $this->cache->setMultiple($items);
    }

    
    // should be created.     $list = array_filter($listfunction D$config_name) use ($existing_config) {
      // Only list configuration that:       // - does not already exist       // - is a configuration entity (this also excludes config that has an       // implicit dependency on modules that are not yet installed)       return !in_array($config_name$existing_config) && $this->configManager->getEntityTypeIdByName($config_name);
    });

    $all_config = array_merge($existing_config$list);
    $all_config = array_combine($all_config$all_config);
    $config_to_create = $storage->readMultiple($list);
    // Check to see if the corresponding override storage has any overrides or     // new configuration that can be installed.     if ($profile_storage) {
      $config_to_create = $profile_storage->readMultiple($list) + $config_to_create;
    }
    // Sort $config_to_create in the order of the least dependent first.     $dependency_manager = new ConfigDependencyManager();
    $dependency_manager->setData($config_to_create);
    $config_to_create = array_merge(array_flip($dependency_manager->sortAll())$config_to_create);
    if (!empty($dependency)) {
      // In order to work out dependencies we need the full config graph.
/** * {@inheritdoc} */
  public function read($name) {
    return $this->storage->read($name);
  }

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

  /** * {@inheritdoc} */
  public function write($name, array $data) {
    throw new \BadMethodCallException(__METHOD__ . ' is not allowed on a ReadOnlyStorage');
  }

  /** * {@inheritdoc} */
public function read($name) {
    if (isset($this->replacementData[$this->collection][$name])) {
      return $this->replacementData[$this->collection][$name];
    }
    return $this->storage->read($name);
  }

  /** * {@inheritdoc} */
  public function readMultiple(array $names) {
    $data = $this->storage->readMultiple(($names));
    foreach ($names as $name) {
      if (isset($this->replacementData[$this->collection][$name])) {
        $data[$name] = $this->replacementData[$this->collection][$name];
      }
    }
    return $data;
  }

  /** * {@inheritdoc} */
  
$cache_key = $this->getConfigCacheKey($name$immutable);
      if (isset($this->cache[$cache_key])) {
        $list[$name] = $this->cache[$cache_key];
        unset($names[$key]);
      }
    }

    // Pre-load remaining configuration files.     if (!empty($names)) {
      // Initialize override information.       $module_overrides = [];
      $storage_data = $this->storage->readMultiple($names);

      if ($immutable && !empty($storage_data)) {
        // Only get module overrides if we have configuration to override.         $module_overrides = $this->loadOverrides($names);
      }

      foreach ($storage_data as $name => $data) {
        $cache_key = $this->getConfigCacheKey($name$immutable);

        $this->cache[$cache_key] = $this->createConfigObject($name$immutable);
        $this->cache[$cache_key]->initWithData($data);
        
// Prior to negotiation the override language should be the default     // language.     $this->language = $default_language->get();
  }

  /** * {@inheritdoc} */
  public function loadOverrides($names) {
    if ($this->language) {
      $storage = $this->getStorage($this->language->getId());
      return $storage->readMultiple($names);
    }
    return [];
  }

  /** * {@inheritdoc} */
  public function getOverride($langcode$name) {
    $storage = $this->getStorage($langcode);
    $data = $storage->read($name);

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

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

  /** * {@inheritdoc} */
  public function write($name, array $data) {
    return $this->getStorage()->write($name$data);
  }

  /** * {@inheritdoc} */
/** * Gets and sorts configuration data from the source and target storages. */
  protected function getAndSortConfigData($collection) {
    $source_storage = $this->getSourceStorage($collection);
    $target_storage = $this->getTargetStorage($collection);
    $target_names = $target_storage->listAll();
    $source_names = $source_storage->listAll();
    // Prime the static caches by reading all the configuration in the source     // and target storages.     $target_data = $target_storage->readMultiple($target_names);
    $source_data = $source_storage->readMultiple($source_names);
    // If the collection only supports simple configuration do not use     // configuration dependencies.     if ($collection == StorageInterface::DEFAULT_COLLECTION) {
      $dependency_manager = new ConfigDependencyManager();
      $this->targetNames[$collection] = $dependency_manager->setData($target_data)->sortAll();
      $this->sourceNames[$collection] = $dependency_manager->setData($source_data)->sortAll();
    }
    else {
      $this->targetNames[$collection] = $target_names;
      $this->sourceNames[$collection] = $source_names;
    }
Home | Imprint | This part of the site doesn't use cookies.