當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Config::initWithData方法代碼示例

本文整理匯總了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);
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:18,代碼來源: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


注:本文中的Drupal\Core\Config\Config::initWithData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。