本文整理汇总了PHP中Drupal\Core\State\StateInterface::set方法的典型用法代码示例。如果您正苦于以下问题:PHP StateInterface::set方法的具体用法?PHP StateInterface::set怎么用?PHP StateInterface::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\State\StateInterface
的用法示例。
在下文中一共展示了StateInterface::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setPluralFormula
/**
* {@inheritdoc}
*/
public function setPluralFormula($langcode, $plural_count, array $formula)
{
// Ensure that the formulae are loaded.
$this->loadFormulae();
$this->formulae[$langcode] = ['plurals' => $plural_count, 'formula' => $formula];
$this->state->set('locale.translation.formulae', $this->formulae);
return $this;
}
示例2: import
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array())
{
if ($row->isStub() && ($state = $this->state->get('comment.maintain_entity_statistics', 0))) {
$this->state->set('comment.maintain_entity_statistics', 0);
}
$return = parent::import($row, $old_destination_id_values);
if ($row->isStub() && $state) {
$this->state->set('comment.maintain_entity_statistics', $state);
}
return $return;
}
示例3: testChanges
/**
* Tests that changes to the info file are picked up.
*/
public function testChanges()
{
$this->themeHandler->install(array('test_theme'));
$this->themeHandler->setDefault('test_theme');
$this->themeManager->resetActiveTheme();
$active_theme = $this->themeManager->getActiveTheme();
// Make sure we are not testing the wrong theme.
$this->assertEqual('test_theme', $active_theme->getName());
$this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling'], $active_theme->getLibraries());
// @see theme_test_system_info_alter()
$this->state->set('theme_test.modify_info_files', TRUE);
drupal_flush_all_caches();
$active_theme = $this->themeManager->getActiveTheme();
$this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries());
}
示例4: testDeleteAllIndexItems
/**
* Tests task system integration for the deleteAllIndexItems() method.
*/
public function testDeleteAllIndexItems()
{
// Set exception for deleteAllIndexItems() and reset the list of successful
// backend method calls.
$this->state->set('search_api_test_backend.exception.deleteAllIndexItems', TRUE);
$this->getCalledServerMethods();
// Try to update the index.
$this->server->deleteAllIndexItems($this->index);
$this->assertEqual($this->getCalledServerMethods(), array(), 'deleteAllIndexItems correctly threw an exception.');
$tasks = $this->getServerTasks();
if (count($tasks) == 1) {
$task_created = $tasks[0]->type === 'deleteAllIndexItems';
}
$this->assertTrue(!empty($task_created), 'The deleteAllIndexItems task was successfully added.');
if ($tasks) {
$this->assertEqual($tasks[0]->index_id, $this->index->id(), 'The right index ID was used for the deleteAllIndexItems task.');
}
// Check whether other task-system-integrated methods now fail, too.
$this->server->updateIndex($this->index);
$this->assertEqual($this->getCalledServerMethods(), array(), 'updateIndex was not executed.');
$tasks = $this->getServerTasks();
if (count($tasks) == 2) {
$this->pass("Second task ('updateIndex') was added.");
$this->assertEqual($tasks[0]->type, 'deleteAllIndexItems', 'First task stayed the same.');
$this->assertEqual($tasks[1]->type, 'updateIndex', 'New task was queued as last.');
} else {
$this->fail("Second task (updateIndex) was not added.");
}
// Let deleteAllIndexItems() succeed again, then trigger the task execution
// with a call to indexItems().
$this->state->set('search_api_test_backend.exception.deleteAllIndexItems', FALSE);
$this->server->indexItems($this->index, array());
$this->assertEqual($this->getServerTasks(), array(), 'Server tasks were correctly executed.');
$this->assertEqual($this->getCalledServerMethods(), array('deleteAllIndexItems', 'updateIndex', 'indexItems'), 'Right methods were called during task execution.');
}
示例5: stopTracking
/**
* {@inheritdoc}
*/
public function stopTracking(IndexInterface $index, array $datasource_ids = NULL)
{
$valid_tracker = $index->hasValidTracker();
if (!isset($datasource_ids)) {
$this->state->delete($this->getIndexStateKey($index));
if ($valid_tracker) {
$index->getTrackerInstance()->trackAllItemsDeleted();
}
return;
}
// Catch the case of being called with an empty array of datasources.
if (!$datasource_ids) {
return;
}
// If no state is saved, this will return NULL, making the following unset()
// statements no-ops.
$index_state = $this->getIndexState($index, FALSE);
foreach ($datasource_ids as $datasource_id) {
unset($index_state['pages'][$datasource_id]);
if ($valid_tracker) {
$index->getTrackerInstance()->trackAllItemsDeleted($datasource_id);
}
}
// If we had an index state saved, update it now.
if (isset($index_state)) {
if (empty($index_state['pages'])) {
$this->state->delete($this->getIndexStateKey($index));
} else {
$this->state->set($this->getIndexStateKey($index), $index_state);
}
}
}
示例6: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$this->config('system.site')->set('name', (string) $form_state->getValue('site_name'))->set('mail', (string) $form_state->getValue('site_mail'))->save(TRUE);
$this->config('system.date')->set('timezone.default', (string) $form_state->getValue('date_default_timezone'))->set('country.default', (string) $form_state->getValue('site_default_country'))->save(TRUE);
$account_values = $form_state->getValue('account');
// Enable update.module if this option was selected.
$update_status_module = $form_state->getValue('update_status_module');
if ($update_status_module[1]) {
$this->moduleInstaller->install(array('file', 'update'), FALSE);
// Add the site maintenance account's email address to the list of
// addresses to be notified when updates are available, if selected.
if ($update_status_module[2]) {
// Reset the configuration factory so it is updated with the new module.
$this->resetConfigFactory();
$this->config('update.settings')->set('notification.emails', array($account_values['mail']))->save(TRUE);
}
}
// We precreated user 1 with placeholder values. Let's save the real values.
$account = $this->userStorage->load(1);
$account->init = $account->mail = $account_values['mail'];
$account->roles = $account->getRoles();
$account->activate();
$account->timezone = $form_state->getValue('date_default_timezone');
$account->pass = $account_values['pass'];
$account->name = $account_values['name'];
$account->save();
// Record when this install ran.
$this->state->set('install_time', $_SERVER['REQUEST_TIME']);
}
示例7: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$modules = $input->getArgument('module');
if (!$this->lock->acquire('cron', 900.0)) {
$io->warning($this->trans('commands.cron.execute.messages.lock'));
return 1;
}
if (in_array('all', $modules)) {
$modules = $this->moduleHandler->getImplementations('cron');
}
foreach ($modules as $module) {
if (!$this->moduleHandler->implementsHook($module, 'cron')) {
$io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module));
continue;
}
try {
$io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module));
$this->moduleHandler->invoke($module, 'cron');
} catch (\Exception $e) {
watchdog_exception('cron', $e);
$io->error($e->getMessage());
}
}
$this->state->set('system.cron_last', REQUEST_TIME);
$this->lock->release('cron');
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
$io->success($this->trans('commands.cron.execute.messages.success'));
return 0;
}
示例8: getHooksInfo
/**
* Returns the entity_test hook invocation info.
*
* @return array
* An associative array of arbitrary hook data keyed by hook name.
*/
protected function getHooksInfo()
{
$key = 'entity_test.hooks';
$hooks = $this->state->get($key);
$this->state->set($key, array());
return $hooks;
}
示例9: onConfigDelete
/**
* Reacts to a config delete and records information in state for testing.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
*/
public function onConfigDelete(ConfigCrudEvent $event)
{
$config = $event->getConfig();
if ($config->getName() == 'action.settings') {
$value = $this->state->get('ConfigImportUITest.action.settings.delete', 0);
$this->state->set('ConfigImportUITest.action.settings.delete', $value + 1);
}
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$show_global = $form_state->getValue('block_visibility_group_show_global', 1);
$this->state->set('block_visibility_group_show_global', $show_global);
// Prevent sending an empty value, which would unset all blocks.
if (!empty($form_state->getValue('blocks'))) {
parent::submitForm($form, $form_state);
}
}
示例11: delete
/**
* {@inheritdoc}
*/
public function delete(array $entities)
{
$return = parent::delete($entities);
// Update the state of registered events.
// @todo Should we trigger a container rebuild here as well? Might be a bit
// expensive on every delete?
$this->stateService->set('rules.registered_events', $this->getRegisteredEvents());
return $return;
}
示例12: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Save the state
$values = $form_state->getValues();
$this->state->set($values['state_name'], $values['parsed_value']);
$form_state->setRedirectUrl(Url::fromRoute('devel.state_system_page'));
drupal_set_message($this->t('Variable %variable was successfully edited.', array('%variable' => $values['state_name'])));
$this->logger('devel')->info('Variable %variable was successfully edited.', array('%variable' => $values['state_name']));
}
示例13: submitConfirmForm
/**
* Submission handler for the confirmation form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitConfirmForm(array &$form, FormStateInterface $form_state)
{
$storage = $form_state->getStorage();
$migrations = $storage['migrations'];
$config['source_base_path'] = $storage['source_base_path'];
$batch = ['title' => $this->t('Running upgrade'), 'progress_message' => '', 'operations' => [[[MigrateUpgradeRunBatch::class, 'run'], [array_keys($migrations), 'import', $config]]], 'finished' => [MigrateUpgradeRunBatch::class, 'finished']];
batch_set($batch);
$form_state->setRedirect('<front>');
$this->state->set('migrate_drupal_ui.performed', REQUEST_TIME);
}
示例14: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
//$state = $this->getDrupalService('state');
$io->info($this->trans('commands.site.maintenance.messages.maintenance-on'));
$io->info($this->trans('commands.update.entities.messages.start'));
$this->state->set('system.maintenance_mode', true);
try {
$this->entityDefinitionUpdateManager->applyUpdates();
/* @var EntityStorageException $e */
} catch (EntityStorageException $e) {
/* @var Error $variables */
$variables = Error::decodeException($e);
$io->info($this->trans('commands.update.entities.messages.error'));
$io->info($variables);
}
$this->state->set('system.maintenance_mode', false);
$io->info($this->trans('commands.update.entities.messages.end'));
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
$io->info($this->trans('commands.site.maintenance.messages.maintenance-off'));
}
示例15: testStateEdit
/**
* Tests state edit.
*/
public function testStateEdit()
{
// Create some state variables for the test.
$this->state->set('devel.simple', 0);
$this->state->set('devel.array', ['devel' => 'value']);
$this->state->set('devel.object', $this->randomObject());
// Ensure that state edit form is accessible only by users with the
// adequate permissions.
$this->drupalLogin($this->develUser);
$this->drupalGet('devel/state/edit/devel.simple');
$this->assertResponse(403);
$this->drupalLogin($this->adminUser);
// Ensure that accessing an un-existent state variable cause a warning
// message.
$this->drupalGet('devel/state/edit/devel.unknown');
$this->assertText(t('State @name does not exist in the system.', ['@name' => 'devel.unknown']));
// Ensure that state variables that contain simple type can be edited and
// saved.
$this->drupalGet('devel/state/edit/devel.simple');
$this->assertResponse(200);
$this->assertText(t('Edit state variable: @name', ['@name' => 'devel.simple']));
$this->assertInputNotDisabledById('edit-new-value');
$this->assertInputNotDisabledById('edit-submit');
$edit = ['new_value' => 1];
$this->drupalPostForm('devel/state/edit/devel.simple', $edit, t('Save'));
$this->assertText(t('Variable @name was successfully edited.', ['@name' => 'devel.simple']));
$this->assertEqual(1, $this->state->get('devel.simple'));
// Ensure that state variables that contain array can be edited and saved
// and the new value is properly validated.
$this->drupalGet('devel/state/edit/devel.array');
$this->assertResponse(200);
$this->assertText(t('Edit state variable: @name', ['@name' => 'devel.array']));
$this->assertInputNotDisabledById('edit-new-value');
$this->assertInputNotDisabledById('edit-submit');
// Try to save an invalid yaml input.
$edit = ['new_value' => 'devel: \'value updated'];
$this->drupalPostForm('devel/state/edit/devel.array', $edit, t('Save'));
$this->assertText(t('Invalid input:'));
$edit = ['new_value' => 'devel: \'value updated\''];
$this->drupalPostForm('devel/state/edit/devel.array', $edit, t('Save'));
$this->assertText(t('Variable @name was successfully edited.', ['@name' => 'devel.array']));
$this->assertEqual(['devel' => 'value updated'], $this->state->get('devel.array'));
// Ensure that state variables that contain objects cannot be edited.
$this->drupalGet('devel/state/edit/devel.object');
$this->assertResponse(200);
$this->assertText(t('Edit state variable: @name', ['@name' => 'devel.object']));
$this->assertText(t('Only simple structures are allowed to be edited. State @name contains objects.', ['@name' => 'devel.object']));
$this->assertInputDisabledById('edit-new-value');
$this->assertInputDisabledById('edit-submit');
// Ensure that the cancel link works as expected.
$this->clickLink(t('Cancel'));
$this->assertUrl('devel/state');
}