本文整理汇总了PHP中Drupal\Core\Config\ConfigImporter::import方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigImporter::import方法的具体用法?PHP ConfigImporter::import怎么用?PHP ConfigImporter::import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Config\ConfigImporter
的用法示例。
在下文中一共展示了ConfigImporter::import方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRecreateEntity
public function testRecreateEntity()
{
$type_name = Unicode::strtolower($this->randomMachineName(16));
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type one'));
$content_type->save();
node_add_body_field($content_type);
/** @var \Drupal\Core\Config\StorageInterface $active */
$active = $this->container->get('config.storage');
/** @var \Drupal\Core\Config\StorageInterface $sync */
$sync = $this->container->get('config.storage.sync');
$config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
$this->copyConfig($active, $sync);
// Delete the content type. This will also delete a field storage, a field,
// an entity view display and an entity form display.
$content_type->delete();
$this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
// Recreate with the same type - this will have a different UUID.
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type two'));
$content_type->save();
node_add_body_field($content_type);
$this->configImporter->reset();
// A node type, a field, an entity view display and an entity form display
// will be recreated.
$creates = $this->configImporter->getUnprocessedConfiguration('create');
$deletes = $this->configImporter->getUnprocessedConfiguration('delete');
$this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
$this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
$this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
$this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
$this->configImporter->import();
// Verify that there is nothing more to import.
$this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
$content_type = NodeType::load($type_name);
$this->assertEqual('Node type one', $content_type->label());
}
示例2: testRenameSimpleConfigValidation
/**
* Tests configuration renaming validation for simple configuration.
*/
public function testRenameSimpleConfigValidation()
{
$uuid = new Php();
// Create a simple configuration with a UUID.
$config = $this->config('config_test.new');
$uuid_value = $uuid->generate();
$config->set('uuid', $uuid_value)->save();
$active = $this->container->get('config.storage');
$sync = $this->container->get('config.storage.sync');
$this->copyConfig($active, $sync);
$config->delete();
// Create another simple configuration with the same UUID.
$config = $this->config('config_test.old');
$config->set('uuid', $uuid_value)->save();
// Confirm that the staged configuration is detected as a rename since the
// UUIDs match.
$this->configImporter->reset();
$expected = array('config_test.old::config_test.new');
$renames = $this->configImporter->getUnprocessedConfiguration('rename');
$this->assertIdentical($expected, $renames);
// Try to import the configuration. We expect an exception to be thrown
// because the rename is for simple configuration.
try {
$this->configImporter->import();
$this->fail('Expected ConfigImporterException thrown when simple configuration is renamed.');
} catch (ConfigImporterException $e) {
$this->pass('Expected ConfigImporterException thrown when simple configuration is renamed.');
$expected = array(SafeMarkup::format('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', array('@old_name' => 'config_test.old', '@new_name' => 'config_test.new')));
$this->assertEqual($expected, $this->configImporter->getErrors());
}
}
示例3: configImport
private function configImport(DrupalStyle $io, StorageComparer $storage_comparer)
{
$config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::lock(), \Drupal::service('config.typed'), \Drupal::moduleHandler(), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'));
if ($config_importer->alreadyImporting()) {
$io->success($this->trans('commands.config.import.messages.already-imported'));
} else {
try {
$config_importer->import();
$io->info($this->trans('commands.config.import.messages.importing'));
} catch (ConfigImporterException $e) {
$message = 'The import failed due for the following reasons:' . "\n";
$message .= implode("\n", $config_importer->getErrors());
$io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $message));
} catch (\Exception $e) {
$io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage()));
}
}
}
示例4: testSecondaryUpdateDeletedDeleterFirst
/**
* Tests that secondary updates for deleted files work as expected.
*/
function testSecondaryUpdateDeletedDeleterFirst()
{
$name_deleter = 'config_test.dynamic.deleter';
$name_deletee = 'config_test.dynamic.deletee';
$name_other = 'config_test.dynamic.other';
$storage = $this->container->get('config.storage');
$staging = $this->container->get('config.storage.staging');
$uuid = $this->container->get('uuid');
$values_deleter = array('id' => 'deleter', 'label' => 'Deleter', 'weight' => 0, 'uuid' => $uuid->generate());
$storage->write($name_deleter, $values_deleter);
$values_deleter['label'] = 'Updated Deleter';
$staging->write($name_deleter, $values_deleter);
$values_deletee = array('id' => 'deletee', 'label' => 'Deletee', 'weight' => 0, 'uuid' => $uuid->generate(), 'dependencies' => array('config' => array($name_deleter)));
$storage->write($name_deletee, $values_deletee);
$values_deletee['label'] = 'Updated Deletee';
$staging->write($name_deletee, $values_deletee);
// Ensure that import will continue after the error.
$values_other = array('id' => 'other', 'label' => 'Other', 'weight' => 0, 'uuid' => $uuid->generate(), 'dependencies' => array('config' => array($name_deleter)));
$storage->write($name_other, $values_other);
$values_other['label'] = 'Updated other';
$staging->write($name_other, $values_other);
// Check update changelist order.
$updates = $this->configImporter->reset()->getStorageComparer()->getChangelist('update');
$expected = array($name_deleter, $name_deletee, $name_other);
$this->assertIdentical($expected, $updates);
// Import.
$this->configImporter->import();
$entity_storage = \Drupal::entityManager()->getStorage('config_test');
$deleter = $entity_storage->load('deleter');
$this->assertEqual($deleter->id(), 'deleter');
$this->assertEqual($deleter->uuid(), $values_deleter['uuid']);
$this->assertEqual($deleter->label(), $values_deleter['label']);
// The deletee was deleted in
// \Drupal\config_test\Entity\ConfigTest::postSave().
$this->assertFalse($entity_storage->load('deletee'));
$other = $entity_storage->load('other');
$this->assertEqual($other->id(), 'other');
$this->assertEqual($other->uuid(), $values_other['uuid']);
$this->assertEqual($other->label(), $values_other['label']);
$logs = $this->configImporter->getErrors();
$this->assertEqual(count($logs), 1);
$this->assertEqual($logs[0], SafeMarkup::format('Update target "@name" is missing.', array('@name' => $name_deletee)));
}