本文整理汇总了PHP中Drupal\Core\Config\Config::initWithData方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::initWithData方法的具体用法?PHP Config::initWithData怎么用?PHP Config::initWithData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Config\Config
的用法示例。
在下文中一共展示了Config::initWithData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInitWithData
/**
* @covers ::initWithData
* @dataProvider nestedDataProvider
*/
public function testInitWithData($data)
{
$config = $this->config->initWithData($data);
// Should return the Config object.
$this->assertInstanceOf('\\Drupal\\Core\\Config\\Config', $config);
// Check config is not new.
$this->assertEquals(FALSE, $this->config->isNew());
// Check that data value was set correctly.
$this->assertConfigDataEquals($data);
// Check that original data was set.
$this->assertOriginalConfigDataEquals($data, TRUE);
// Check without applying overrides.
$this->assertOriginalConfigDataEquals($data, FALSE);
}
示例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'));
}
示例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;
}