当前位置: 首页>>代码示例>>PHP>>正文


PHP Config::setData方法代码示例

本文整理汇总了PHP中Drupal\Core\Config\Config::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::setData方法的具体用法?PHP Config::setData怎么用?PHP Config::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Config\Config的用法示例。


在下文中一共展示了Config::setData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMerge

 /**
  * @covers ::merge
  * @dataProvider mergeDataProvider
  */
 public function testMerge($data, $data_to_merge, $merged_data)
 {
     // Set initial data.
     $this->config->setData($data);
     // Data to merge.
     $this->config->merge($data_to_merge);
     // Check that data has merged correctly.
     $this->assertEquals($merged_data, $this->config->getRawData());
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:13,代码来源:ConfigTest.php

示例2: testSafeStringHandling

 /**
  * @covers ::setData
  * @covers ::set
  * @covers ::initWithData
  */
 public function testSafeStringHandling()
 {
     // Safe strings are cast when using ::set().
     $safe_string = Markup::create('bar');
     $this->config->set('foo', $safe_string);
     $this->assertSame('bar', $this->config->get('foo'));
     $this->config->set('foo', ['bar' => $safe_string]);
     $this->assertSame('bar', $this->config->get('foo.bar'));
     // Safe strings are cast when using ::setData().
     $this->config->setData(['bar' => $safe_string]);
     $this->assertSame('bar', $this->config->get('bar'));
     // Safe strings are not cast when using ::initWithData().
     $this->config->initWithData(['bar' => $safe_string]);
     $this->assertSame($safe_string, $this->config->get('bar'));
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:20,代码来源:ConfigTest.php

示例3: importInvokeRename

 /**
  * Imports a configuration entity rename.
  *
  * @param string $collection
  *   The configuration collection.
  * @param string $rename_name
  *   The rename configuration name, as provided by
  *   \Drupal\Core\Config\StorageComparer::createRenameName().
  *
  * @throws \Drupal\Core\Entity\EntityStorageException
  *   Thrown if the data is owned by an entity type, but the entity storage
  *   does not support imports.
  *
  * @return bool
  *   TRUE if the configuration was imported as a configuration entity. FALSE
  *   otherwise.
  *
  * @see \Drupal\Core\Config\ConfigImporter::createRenameName()
  */
 protected function importInvokeRename($collection, $rename_name)
 {
     $names = $this->storageComparer->extractRenameNames($rename_name);
     $entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']);
     $old_config = new Config($names['old_name'], $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager);
     if ($old_data = $this->storageComparer->getTargetStorage($collection)->read($names['old_name'])) {
         $old_config->initWithData($old_data);
     }
     $data = $this->storageComparer->getSourceStorage($collection)->read($names['new_name']);
     $new_config = new Config($names['new_name'], $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager);
     if ($data !== FALSE) {
         $new_config->setData($data);
     }
     $entity_storage = $this->configManager->getEntityManager()->getStorage($entity_type_id);
     // Call to the configuration entity's storage to handle the configuration
     // change.
     if (!$entity_storage instanceof ImportableEntityStorageInterface) {
         throw new EntityStorageException(SafeMarkup::format('The entity storage "@storage" for the "@entity_type" entity type does not support imports', array('@storage' => get_class($entity_storage), '@entity_type' => $entity_type_id)));
     }
     $entity_storage->importRename($names['old_name'], $new_config, $old_config);
     $this->setProcessedConfiguration($collection, 'rename', $rename_name);
     return TRUE;
 }
开发者ID:brstde,项目名称:gap1,代码行数:42,代码来源:ConfigImporter.php

示例4: createConfiguration

 /**
  * Creates configuration in a collection based on the provided list.
  *
  * @param string $collection
  *   The configuration collection.
  * @param array $config_to_create
  *   An array of configuration data to create, keyed by name.
  */
 protected function createConfiguration($collection, array $config_to_create)
 {
     // Order the configuration to install in the order of dependencies.
     if ($collection == StorageInterface::DEFAULT_COLLECTION) {
         $dependency_manager = new ConfigDependencyManager();
         $config_names = $dependency_manager->setData($config_to_create)->sortAll();
     } else {
         $config_names = array_keys($config_to_create);
     }
     foreach ($config_names as $name) {
         // Allow config factory overriders to use a custom configuration object if
         // they are responsible for the collection.
         $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection);
         if ($overrider) {
             $new_config = $overrider->createConfigObject($name, $collection);
         } else {
             $new_config = new Config($name, $this->getActiveStorages($collection), $this->eventDispatcher, $this->typedConfig);
         }
         if ($config_to_create[$name] !== FALSE) {
             $new_config->setData($config_to_create[$name]);
         }
         if ($collection == StorageInterface::DEFAULT_COLLECTION && ($entity_type = $this->configManager->getEntityTypeIdByName($name))) {
             // If we are syncing do not create configuration entities. Pluggable
             // configuration entities can have dependencies on modules that are
             // not yet enabled. This approach means that any code that expects
             // default configuration entities to exist will be unstable after the
             // module has been enabled and before the config entity has been
             // imported.
             if ($this->isSyncing()) {
                 continue;
             }
             /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_storage */
             $entity_storage = $this->configManager->getEntityManager()->getStorage($entity_type);
             // It is possible that secondary writes can occur during configuration
             // creation. Updates of such configuration are allowed.
             if ($this->getActiveStorages($collection)->exists($name)) {
                 $id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix());
                 $entity = $entity_storage->load($id);
                 $entity = $entity_storage->updateFromStorageRecord($entity, $new_config->get());
             } else {
                 $entity = $entity_storage->createFromStorageRecord($new_config->get());
             }
             if ($entity->isInstallable()) {
                 $entity->trustData()->save();
             }
         } else {
             $new_config->save(TRUE);
         }
     }
 }
开发者ID:dmyerson,项目名称:d8ecs,代码行数:58,代码来源:ConfigInstaller.php

示例5: createConfiguration

 /**
  * Creates configuration in a collection based on the provided list.
  *
  * @param string $collection
  *   The configuration collection.
  * @param array $config_to_install
  *   A list of configuration object names to create.
  */
 protected function createConfiguration($collection, array $config_to_install)
 {
     // Order the configuration to install in the order of dependencies.
     $data = $this->getSourceStorage($collection)->readMultiple($config_to_install);
     $config_entity_support = $this->configManager->supportsConfigurationEntities($collection);
     if ($config_entity_support) {
         $dependency_manager = new ConfigDependencyManager();
         $config_to_install = $dependency_manager->setData($data)->sortAll();
     }
     // Remove configuration that already exists in the active storage.
     $config_to_install = array_diff($config_to_install, $this->getActiveStorage($collection)->listAll());
     foreach ($config_to_install as $name) {
         // Allow config factory overriders to use a custom configuration object if
         // they are responsible for the collection.
         $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection);
         if ($overrider) {
             $new_config = $overrider->createConfigObject($name, $collection);
         } else {
             $new_config = new Config($name, $this->getActiveStorage($collection), $this->eventDispatcher, $this->typedConfig);
         }
         if ($data[$name] !== FALSE) {
             $new_config->setData($data[$name]);
         }
         if ($config_entity_support && ($entity_type = $this->configManager->getEntityTypeIdByName($name))) {
             // If we are syncing do not create configuration entities. Pluggable
             // configuration entities can have dependencies on modules that are
             // not yet enabled. This approach means that any code that expects
             // default configuration entities to exist will be unstable after the
             // module has been enabled and before the config entity has been
             // imported.
             if ($this->isSyncing) {
                 continue;
             }
             $entity_storage = $this->configManager->getEntityManager()->getStorage($entity_type);
             // It is possible that secondary writes can occur during configuration
             // creation. Updates of such configuration are allowed.
             if ($this->getActiveStorage($collection)->exists($name)) {
                 $id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix());
                 $entity = $entity_storage->load($id);
                 foreach ($new_config->get() as $property => $value) {
                     $entity->set($property, $value);
                 }
                 $entity->save();
             } else {
                 $entity_storage->create($new_config->get())->save();
             }
         } else {
             $new_config->save();
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:59,代码来源:ConfigInstaller.php


注:本文中的Drupal\Core\Config\Config::setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。