本文整理汇总了PHP中Drupal\Core\Config\ConfigFactoryInterface::getOverrideState方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigFactoryInterface::getOverrideState方法的具体用法?PHP ConfigFactoryInterface::getOverrideState怎么用?PHP ConfigFactoryInterface::getOverrideState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Config\ConfigFactoryInterface
的用法示例。
在下文中一共展示了ConfigFactoryInterface::getOverrideState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request)
{
$entity_type = substr($definition['type'], strlen('entity:'));
if ($storage = $this->entityManager->getStorage($entity_type)) {
// Make sure no overrides are loaded.
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$entity = $storage->load($value);
$this->configFactory->setOverrideState($old_state);
return $entity;
}
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form = parent::buildForm($form, $form_state);
$old_state = $this->configFactory->getOverrideState();
$search_settings = $this->configFactory->setOverrideState(FALSE)->get('search.settings');
$this->configFactory->setOverrideState($old_state);
// Collect some stats.
$remaining = 0;
$total = 0;
foreach ($this->entities as $entity) {
if ($entity->isIndexable() && ($status = $entity->getPlugin()->indexStatus())) {
$remaining += $status['remaining'];
$total += $status['total'];
}
}
$this->moduleHandler->loadAllIncludes('admin.inc');
$count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
$done = $total - $remaining;
// Use floor() to calculate the percentage, so if it is not quite 100%, it
// will show as 99%, to indicate "almost done".
$percentage = $total > 0 ? floor(100 * $done / $total) : 100;
$percentage .= '%';
$status = '<p><strong>' . $this->t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>';
$form['status'] = array('#type' => 'details', '#title' => $this->t('Indexing progress'), '#open' => TRUE);
$form['status']['status'] = array('#markup' => $status);
$form['status']['wipe'] = array('#type' => 'submit', '#value' => $this->t('Re-index site'), '#submit' => array(array($this, 'searchAdminReindexSubmit')));
$items = array(10, 20, 50, 100, 200, 500);
$items = array_combine($items, $items);
// Indexing throttle:
$form['indexing_throttle'] = array('#type' => 'details', '#title' => $this->t('Indexing throttle'), '#open' => TRUE);
$form['indexing_throttle']['cron_limit'] = array('#type' => 'select', '#title' => $this->t('Number of items to index per cron run'), '#default_value' => $search_settings->get('index.cron_limit'), '#options' => $items, '#description' => $this->t('The maximum number of items indexed in each pass of a <a href="@cron">cron maintenance task</a>. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))));
// Indexing settings:
$form['indexing_settings'] = array('#type' => 'details', '#title' => $this->t('Indexing settings'), '#open' => TRUE);
$form['indexing_settings']['info'] = array('#markup' => $this->t('<p><em>Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>'));
$form['indexing_settings']['minimum_word_size'] = array('#type' => 'number', '#title' => $this->t('Minimum word length to index'), '#default_value' => $search_settings->get('index.minimum_word_size'), '#min' => 1, '#max' => 1000, '#description' => $this->t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).'));
$form['indexing_settings']['overlap_cjk'] = array('#type' => 'checkbox', '#title' => $this->t('Simple CJK handling'), '#default_value' => $search_settings->get('index.overlap_cjk'), '#description' => $this->t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.'));
// Indexing settings:
$form['logging'] = array('#type' => 'details', '#title' => $this->t('Logging'), '#open' => TRUE);
$form['logging']['logging'] = array('#type' => 'checkbox', '#title' => $this->t('Log searches'), '#default_value' => $search_settings->get('logging'), '#description' => $this->t('If checked, all searches will be logged. Uncheck to skip logging. Logging may affect performance.'));
$form['search_pages'] = array('#type' => 'details', '#title' => $this->t('Search pages'), '#open' => TRUE);
$form['search_pages']['add_page'] = array('#type' => 'container', '#attributes' => array('class' => array('container-inline')), '#attached' => array('css' => array(drupal_get_path('module', 'search') . '/css/search.admin.css')));
// In order to prevent validation errors for the parent form, this cannot be
// required, see self::validateAddSearchPage().
$form['search_pages']['add_page']['search_type'] = array('#type' => 'select', '#title' => $this->t('Search page type'), '#empty_option' => $this->t('- Choose page type -'), '#options' => array_map(function ($definition) {
return $definition['title'];
}, $this->searchManager->getDefinitions()));
$form['search_pages']['add_page']['add_search_submit'] = array('#type' => 'submit', '#value' => $this->t('Add new page'), '#validate' => array(array($this, 'validateAddSearchPage')), '#submit' => array(array($this, 'submitAddSearchPage')), '#limit_validation_errors' => array(array('search_type')));
// Move the listing into the search_pages element.
$form['search_pages'][$this->entitiesKey] = $form[$this->entitiesKey];
$form['search_pages'][$this->entitiesKey]['#empty'] = $this->t('No search pages have been configured.');
unset($form[$this->entitiesKey]);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save configuration'), '#button_type' => 'primary');
return $form;
}
示例3: convert
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults)
{
$entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults);
// If the entity type is dynamic, confirm it to be a config entity. Static
// entity types will have performed this check in self::applies().
if (strpos($definition['type'], 'entity:{') === 0) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
if (!$entity_type->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
return parent::convert($value, $definition, $name, $defaults);
}
}
if ($storage = $this->entityManager->getStorage($entity_type_id)) {
// Make sure no overrides are loaded.
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$entity = $storage->load($value);
$this->configFactory->setOverrideState($old_state);
return $entity;
}
}
示例4: installCollectionDefaultConfig
/**
* {@inheritdoc}
*/
public function installCollectionDefaultConfig($collection)
{
$config_to_install = $this->getSourceStorage($collection)->listAll();
$extension_config = $this->configFactory->get('core.extension');
$enabled_extensions = array_keys((array) $extension_config->get('module'));
$enabled_extensions += array_keys((array) $extension_config->get('theme'));
$config_to_install = array_filter($config_to_install, function ($config_name) use($enabled_extensions) {
$provider = Unicode::substr($config_name, 0, strpos($config_name, '.'));
return in_array($provider, $enabled_extensions);
});
if (!empty($config_to_install)) {
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$this->createConfiguration($collection, $config_to_install);
$this->configFactory->setOverrideState($old_state);
// Reset all the static caches and list caches.
$this->configFactory->reset();
}
}