本文整理汇总了PHP中Drupal\Core\Config\StorageInterface::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface::exists方法的具体用法?PHP StorageInterface::exists怎么用?PHP StorageInterface::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Config\StorageInterface
的用法示例。
在下文中一共展示了StorageInterface::exists方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exists
/**
* Implements Drupal\Core\Config\StorageInterface::exists().
*/
public function exists($name)
{
// The cache would read in the entire data (instead of only checking whether
// any data exists), and on a potential cache miss, an additional storage
// lookup would have to happen, so check the storage directly.
return $this->storage->exists($name);
}
示例2: exists
/**
* {@inheritdoc}
*/
public function exists($name)
{
$exists = $this->storage->exists($name);
foreach ($this->filters as $filter) {
$exists = $filter->filterExists($name, $exists, $this->storage);
}
return $exists;
}
示例3: read
/**
* Read a configuration from install storage or default languages.
*
* @param string $name
* Configuration object name.
*
* @return array
* Configuration data from install storage or default language.
*/
public function read($name)
{
if ($this->requiredInstallStorage->exists($name)) {
return $this->requiredInstallStorage->read($name);
} elseif ($this->optionalInstallStorage->exists($name)) {
return $this->optionalInstallStorage->read($name);
} elseif (strpos($name, 'language.entity.') === 0) {
// Simulate default languages as if they were shipped as default
// configuration.
$langcode = str_replace('language.entity.', '', $name);
$predefined_languages = $this->languageManager->getStandardLanguageList();
if (isset($predefined_languages[$langcode])) {
$data = $this->configStorage->read($name);
$data['label'] = $predefined_languages[$langcode][0];
return $data;
}
}
}
示例4: testSubscribers
/**
* Test the import subscriber.
*/
public function testSubscribers()
{
// Without this the config exporter breaks.
\Drupal::service('config.installer')->installDefaultConfig('module', 'config_devel');
$filename = vfsStream::url('public://' . static::CONFIGNAME . '.yml');
drupal_mkdir(vfsStream::url('public://exported'));
$exported_filename = vfsStream::url('public://exported/' . static::CONFIGNAME . '.yml');
\Drupal::configFactory()->getEditable('config_devel.settings')->set('auto_import', array(array('filename' => $filename, 'hash' => '')))->set('auto_export', array($exported_filename))->save();
$this->storage = \Drupal::service('config.storage');
$this->assertFalse($this->storage->exists(static::CONFIGNAME));
$subscriber = \Drupal::service('config_devel.auto_import_subscriber');
for ($i = 2; $i; $i--) {
$data['label'] = $this->randomString();
file_put_contents($filename, Yaml::encode($data));
// The import fires an export too.
$subscriber->autoImportConfig();
$this->doAssert($data, Yaml::decode(file_get_contents($exported_filename)));
}
}
示例5: exists
/**
* {@inheritdoc}
*/
public function exists($name)
{
return $this->baseStorage->exists($name);
}
示例6: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Import all'));
$source_list = $this->syncStorage->listAll();
$storage_comparer = new StorageComparer($this->syncStorage, $this->activeStorage, $this->configManager);
if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) {
$form['no_changes'] = array('#type' => 'table', '#header' => array($this->t('Name'), $this->t('Operations')), '#rows' => array(), '#empty' => $this->t('There are no configuration changes to import.'));
$form['actions']['#access'] = FALSE;
return $form;
} elseif (!$storage_comparer->validateSiteUuid()) {
drupal_set_message($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.'), 'error');
$form['actions']['#access'] = FALSE;
return $form;
}
// A list of changes will be displayed, so check if the user should be
// warned of potential losses to configuration.
if ($this->snapshotStorage->exists('core.extension')) {
$snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage, $this->configManager);
if (!$form_state->getUserInput() && $snapshot_comparer->createChangelist()->hasChanges()) {
$change_list = array();
foreach ($snapshot_comparer->getAllCollectionNames() as $collection) {
foreach ($snapshot_comparer->getChangelist(NULL, $collection) as $config_names) {
if (empty($config_names)) {
continue;
}
foreach ($config_names as $config_name) {
$change_list[] = $config_name;
}
}
}
sort($change_list);
$message = [['#markup' => $this->t('The following items in your active configuration have changes since the last import that may be lost on the next import.')], ['#theme' => 'item_list', '#items' => $change_list]];
drupal_set_message($this->renderer->renderPlain($message), 'warning');
}
}
// Store the comparer for use in the submit.
$form_state->set('storage_comparer', $storage_comparer);
// Add the AJAX library to the form for dialog support.
$form['#attached']['library'][] = 'core/drupal.ajax';
foreach ($storage_comparer->getAllCollectionNames() as $collection) {
if ($collection != StorageInterface::DEFAULT_COLLECTION) {
$form[$collection]['collection_heading'] = array('#type' => 'html_tag', '#tag' => 'h2', '#value' => $this->t('@collection configuration collection', array('@collection' => $collection)));
}
foreach ($storage_comparer->getChangelist(NULL, $collection) as $config_change_type => $config_names) {
if (empty($config_names)) {
continue;
}
// @todo A table caption would be more appropriate, but does not have the
// visual importance of a heading.
$form[$collection][$config_change_type]['heading'] = array('#type' => 'html_tag', '#tag' => 'h3');
switch ($config_change_type) {
case 'create':
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count new', '@count new');
break;
case 'update':
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count changed', '@count changed');
break;
case 'delete':
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count removed', '@count removed');
break;
case 'rename':
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count renamed', '@count renamed');
break;
}
$form[$collection][$config_change_type]['list'] = array('#type' => 'table', '#header' => array($this->t('Name'), $this->t('Operations')));
foreach ($config_names as $config_name) {
if ($config_change_type == 'rename') {
$names = $storage_comparer->extractRenameNames($config_name);
$route_options = array('source_name' => $names['old_name'], 'target_name' => $names['new_name']);
$config_name = $this->t('@source_name to @target_name', array('@source_name' => $names['old_name'], '@target_name' => $names['new_name']));
} else {
$route_options = array('source_name' => $config_name);
}
if ($collection != StorageInterface::DEFAULT_COLLECTION) {
$route_name = 'config.diff_collection';
$route_options['collection'] = $collection;
} else {
$route_name = 'config.diff';
}
$links['view_diff'] = array('title' => $this->t('View differences'), 'url' => Url::fromRoute($route_name, $route_options), 'attributes' => array('class' => array('use-ajax'), 'data-dialog-type' => 'modal', 'data-dialog-options' => json_encode(array('width' => 700))));
$form[$collection][$config_change_type]['list']['#rows'][] = array('name' => $config_name, 'operations' => array('data' => array('#type' => 'operations', '#links' => $links)));
}
}
}
return $form;
}
示例7: testCRUD
/**
* Tests storage CRUD operations.
*
* @todo Coverage: Trigger PDOExceptions / Database exceptions.
*/
function testCRUD()
{
$name = 'config_test.storage';
// Checking whether a non-existing name exists returns FALSE.
$this->assertIdentical($this->storage->exists($name), FALSE);
// Reading a non-existing name returns FALSE.
$data = $this->storage->read($name);
$this->assertIdentical($data, FALSE);
// Writing data returns TRUE and the data has been written.
$data = array('foo' => 'bar');
$result = $this->storage->write($name, $data);
$this->assertIdentical($result, TRUE);
$raw_data = $this->read($name);
$this->assertIdentical($raw_data, $data);
// Checking whether an existing name exists returns TRUE.
$this->assertIdentical($this->storage->exists($name), TRUE);
// Writing the identical data again still returns TRUE.
$result = $this->storage->write($name, $data);
$this->assertIdentical($result, TRUE);
// Listing all names returns all.
$names = $this->storage->listAll();
$this->assertTrue(in_array('system.performance', $names));
$this->assertTrue(in_array($name, $names));
// Listing all names with prefix returns names with that prefix only.
$names = $this->storage->listAll('config_test.');
$this->assertFalse(in_array('system.performance', $names));
$this->assertTrue(in_array($name, $names));
// Rename the configuration storage object.
$new_name = 'config_test.storage_rename';
$this->storage->rename($name, $new_name);
$raw_data = $this->read($new_name);
$this->assertIdentical($raw_data, $data);
// Rename it back so further tests work.
$this->storage->rename($new_name, $name);
// Deleting an existing name returns TRUE.
$result = $this->storage->delete($name);
$this->assertIdentical($result, TRUE);
// Deleting a non-existing name returns FALSE.
$result = $this->storage->delete($name);
$this->assertIdentical($result, FALSE);
// Deleting all names with prefix deletes the appropriate data and returns
// TRUE.
$files = array('config_test.test.biff', 'config_test.test.bang', 'config_test.test.pow');
foreach ($files as $name) {
$this->storage->write($name, $data);
}
$result = $this->storage->deleteAll('config_test.');
$names = $this->storage->listAll('config_test.');
$this->assertIdentical($result, TRUE);
$this->assertIdentical($names, array());
// Test renaming an object that does not exist throws an exception.
try {
$this->storage->rename('config_test.storage_does_not_exist', 'config_test.storage_does_not_exist_rename');
} catch (\Exception $e) {
$class = get_class($e);
$this->pass($class . ' thrown upon renaming a nonexistent storage bin.');
}
// Test renaming to an object that already exists throws an exception.
try {
$this->storage->rename('system.cron', 'system.performance');
} catch (\Exception $e) {
$class = get_class($e);
$this->pass($class . ' thrown upon renaming a nonexistent storage bin.');
}
}
示例8: exists
/**
* {@inheritdoc}
*/
public function exists($name)
{
return isset($this->replacementData[$this->collection][$name]) || $this->storage->exists($name);
}