当前位置: 首页>>代码示例>>PHP>>正文


PHP Config::set方法代码示例

本文整理汇总了PHP中Drupal\Core\Config\Config::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::set方法的具体用法?PHP Config::set怎么用?PHP Config::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Config\Config的用法示例。


在下文中一共展示了Config::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testConfigEvents

 /**
  * Tests configuration events.
  */
 function testConfigEvents()
 {
     $name = 'config_events_test.test';
     $config = new Config($name, \Drupal::service('config.storage'), \Drupal::service('event_dispatcher'), \Drupal::service('config.typed'));
     $config->set('key', 'initial');
     \Drupal::state()->get('config_events_test.event', FALSE);
     $this->assertIdentical(\Drupal::state()->get('config_events_test.event', array()), array(), 'No events fired by creating a new configuration object');
     $config->save();
     $event = \Drupal::state()->get('config_events_test.event', array());
     $this->assertIdentical($event['event_name'], ConfigEvents::SAVE);
     $this->assertIdentical($event['current_config_data'], array('key' => 'initial'));
     $this->assertIdentical($event['raw_config_data'], array('key' => 'initial'));
     $this->assertIdentical($event['original_config_data'], array());
     $config->set('key', 'updated')->save();
     $event = \Drupal::state()->get('config_events_test.event', array());
     $this->assertIdentical($event['event_name'], ConfigEvents::SAVE);
     $this->assertIdentical($event['current_config_data'], array('key' => 'updated'));
     $this->assertIdentical($event['raw_config_data'], array('key' => 'updated'));
     $this->assertIdentical($event['original_config_data'], array('key' => 'initial'));
     $config->delete();
     $event = \Drupal::state()->get('config_events_test.event', array());
     $this->assertIdentical($event['event_name'], ConfigEvents::DELETE);
     $this->assertIdentical($event['current_config_data'], array());
     $this->assertIdentical($event['raw_config_data'], array());
     $this->assertIdentical($event['original_config_data'], array('key' => 'updated'));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:29,代码来源:ConfigEventsTest.php

示例2: testCronExampleBasic

 /**
  * Create an example node, test block through admin and user interfaces.
  */
 public function testCronExampleBasic()
 {
     // Pretend that cron has never been run (even though simpletest seems to
     // run it once...)
     $this->cronConfig->set('cron_example_next_execution', 0);
     $this->drupalGet('examples/cron_example');
     // Initial run should cause cron_example_cron() to fire.
     $post = [];
     $this->drupalPostForm('examples/cron_example', $post, t('Run cron now'));
     $this->assertText(t('cron_example executed at'));
     // Forcing should also cause cron_example_cron() to fire.
     $post['cron_reset'] = TRUE;
     $this->drupalPostForm(NULL, $post, t('Run cron now'));
     $this->assertText(t('cron_example executed at'));
     // But if followed immediately and not forced, it should not fire.
     $post['cron_reset'] = FALSE;
     $this->drupalPostForm(NULL, $post, t('Run cron now'));
     $this->assertNoText(t('cron_example executed at'));
     $this->assertText(t('There are currently 0 items in queue 1 and 0 items in queue 2'));
     $post = ['num_items' => 5, 'queue' => 'cron_example_queue_1'];
     $this->drupalPostForm(NULL, $post, t('Add jobs to queue'));
     $this->assertText('There are currently 5 items in queue 1 and 0 items in queue 2');
     $post = ['num_items' => 100, 'queue' => 'cron_example_queue_2'];
     $this->drupalPostForm(NULL, $post, t('Add jobs to queue'));
     $this->assertText('There are currently 5 items in queue 1 and 100 items in queue 2');
     $post = [];
     $this->drupalPostForm('examples/cron_example', $post, t('Run cron now'));
     $this->assertPattern('/Queue 1 worker processed item with sequence 5 /');
     $this->assertPattern('/Queue 2 worker processed item with sequence 100 /');
 }
开发者ID:seongbae,项目名称:drumo-distribution,代码行数:33,代码来源:CronExampleTestCase.php

示例3: import

 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     foreach ($row->getRawDestination() as $key => $value) {
         if (isset($value) || !empty($this->configuration['store null'])) {
             $this->config->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $key), $value);
         }
     }
     $this->config->save();
     return [$this->config->getName()];
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:13,代码来源:Config.php

示例4: import

 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     if ($row->hasDestinationProperty('langcode')) {
         $this->config = $this->language_manager->getLanguageConfigOverride($row->getDestinationProperty('langcode'), $this->config->getName());
     }
     foreach ($row->getRawDestination() as $key => $value) {
         if (isset($value) || !empty($this->configuration['store null'])) {
             $this->config->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $key), $value);
         }
     }
     $this->config->save();
     return [$this->config->getName()];
 }
开发者ID:systemick3,项目名称:systemick.co.uk,代码行数:16,代码来源:Config.php

示例5: testDelete

 /**
  * @covers ::delete
  * @dataProvider overrideDataProvider
  */
 public function testDelete($data, $module_data)
 {
     $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(['config:config.test']);
     // Set initial data.
     foreach ($data as $key => $value) {
         $this->config->set($key, $value);
     }
     // Set overrides.
     $this->config->setModuleOverride($module_data);
     // Save.
     $this->config->save();
     // Check that original data is still correct.
     $this->assertOriginalConfigDataEquals($data, FALSE);
     // Check overrides have been set.
     $this->assertConfigDataEquals($module_data);
     $this->assertOriginalConfigDataEquals($module_data, TRUE);
     // Check that config is new.
     $this->assertFalse($this->config->isNew());
     // Delete.
     $this->config->delete();
     // Check object properties have been reset.
     $this->assertTrue($this->config->isNew());
     foreach ($data as $key => $value) {
         $this->assertEmpty($this->config->getOriginal($key, FALSE));
     }
     // Check that overrides have persisted.
     foreach ($module_data as $key => $value) {
         $this->assertConfigDataEquals($module_data);
         $this->assertOriginalConfigDataEquals($module_data, TRUE);
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:35,代码来源:ConfigTest.php

示例6: testTagUnicity

 /**
  * Tags should differ between languages and from generic tags.
  */
 public function testTagUnicity()
 {
     // Enable some languages first.
     $this->config->set('language.php.enabled', TRUE);
     $this->config->set('language.python.enabled', TRUE);
     // First round: without format specific tag options.
     $this->config->set('use_format_specific_options', FALSE);
     $this->config->set('tags', 'code blockcode generictag');
     $this->config->save();
     // A language tag should differ from the generic tags.
     $form_values = array('language[php][tags]' => 'php generictag');
     $this->drupalPostForm('admin/config/content/formats/geshifilter/languages/all', $form_values, t('Save configuration'));
     $this->assertText(t('The language tags should differ between languages and from the generic tags.'), t('Language tags should differ from generic tags (with generic tag options)'));
     // Language tags should differ between languages.
     $form_values = array('language[php][tags]' => 'php languagetag', 'language[python][tags]' => 'languagetag python');
     $this->drupalPostForm('admin/config/content/formats/geshifilter/languages/all', $form_values, t('Save configuration'));
     $this->assertText(t('The language tags should differ between languages and from the generic tags.'), t('Language tags should differ between languages (with generic tag options)'));
     // Second round: with format specific tag options.
     // $this->config->set('use_format_specific_options', TRUE);
     // $this->drupalPostForm('admin/config/content/formats/manage/geshifilter_text_format', array(),t('Save configuration'));
     /*$this->config->set('tags_' . $this->input_format_id,
          'code blockcode generictag');
       // A language tag should differ from the generic tags.
       $form_values = array(
         'geshifilter_language_tags_php_' . $this->input_format_id =>
         'php generictag');
       $this->drupalPostForm('admin/config/content/formats/' .
       $this->input_format_id
         . '/configure', $form_values, t('Save configuration'));
       $this->assertText(t('The language tags should differ between languages
         and from the generic tags.'), t('Language tags should differ from
         (with format specific tag options)'));
       // Language tags should differ between languages.
       $form_values = array(
        'geshifilter_language_tags_php_' . $this->input_format_id =>
        'php languagetag',
        'geshifilter_language_tags_python_' . $this->input_format_id =>
        'languagetag python',
       );
       $this->drupalPostForm('admin/config/content/formats/' .
       $this->input_format_id .
         '/configure', $form_values, t('Save configuration'));
       $this->assertText(t('The language tags should differ between languages
         and from the
         generic tags.'), t('Language tags should differ between languages (with
         format specific tag options)'));*/
 }
开发者ID:hugronaphor,项目名称:cornel,代码行数:50,代码来源:GeshiFilterAdministrationTest.php

示例7: setUp

 /**
  * Set up the tests and create the users.
  */
 public function setUp()
 {
     parent::setUp();
     // Create object with configuration.
     $this->config = \Drupal::configFactory()->getEditable('geshifilter.settings');
     // And set the path to the geshi library.
     $this->config->set('geshi_dir', '/libraries/geshi');
     $settings = array('type' => 'geshifilter_content_type', 'name' => 'Geshifilter Content');
     $this->drupalCreateContentType($settings);
     // Create a filter admin user.
     $permissions = array('administer filters', 'access administration pages', 'administer site configuration');
     $this->filterAdminUser = $this->drupalCreateUser($permissions);
     // Log in with filter admin user.
     $this->drupalLogin($this->filterAdminUser);
     // Add an text format with only geshi filter.
     $this->createTextFormat('geshifilter_text_format', array('filter_geshifilter'));
 }
开发者ID:hugronaphor,项目名称:cornel,代码行数:20,代码来源:GeshiFilterCssTest.php

示例8: testRedirects

 /**
  * Will test the redirects.
  */
 public function testRedirects()
 {
     // Test alias normalization.
     $this->config->set('normalize_aliases', TRUE)->save();
     $this->assertRedirect('node/' . $this->node->id(), 'test-node');
     $this->assertRedirect('Test-node', 'test-node');
     $this->config->set('normalize_aliases', FALSE)->save();
     $this->assertRedirect('node/' . $this->node->id(), NULL, 'HTTP/1.1 200 OK');
     $this->assertRedirect('Test-node', NULL, 'HTTP/1.1 200 OK');
     // Test deslashing.
     $this->config->set('deslash', TRUE)->save();
     $this->assertRedirect('test-node/', 'test-node');
     $this->config->set('deslash', FALSE)->save();
     $this->assertRedirect('test-node/', NULL, 'HTTP/1.1 200 OK');
     // Test front page redirects.
     $this->config->set('frontpage_redirect', TRUE)->save();
     $this->config('system.site')->set('page.front', '/node')->save();
     $this->assertRedirect('node', '<front>');
     // Test front page redirects with an alias.
     \Drupal::service('path.alias_storage')->save('/node', '/node-alias');
     $this->assertRedirect('node-alias', '<front>');
     $this->config->set('frontpage_redirect', FALSE)->save();
     $this->assertRedirect('node', NULL, 'HTTP/1.1 200 OK');
     $this->assertRedirect('node-alias', NULL, 'HTTP/1.1 200 OK');
     // Test post request.
     $this->config->set('normalize_aliases', TRUE)->save();
     $this->drupalPost('Test-node', 'application/json', array());
     // Does not do a redirect, stays in the same path.
     $this->assertEqual(basename($this->getUrl()), 'Test-node');
     // Test the access checking.
     $this->config->set('normalize_aliases', TRUE)->save();
     $this->config->set('access_check', TRUE)->save();
     $this->assertRedirect('admin/config/system/site-information', NULL, 'HTTP/1.1 403 Forbidden');
     $this->config->set('access_check', FALSE)->save();
     // @todo - here it seems that the access check runs prior to our redirecting
     //   check why so and enable the test.
     //$this->assertRedirect('admin/config/system/site-information', 'site-info');
     // Login as user with admin privileges.
     $this->drupalLogin($this->adminUser);
     // Test ignoring admin paths.
     $this->config->set('ignore_admin_path', FALSE)->save();
     $this->assertRedirect('admin/config/system/site-information', 'site-info');
     $this->config->set('ignore_admin_path', TRUE)->save();
     $this->assertRedirect('admin/config/system/site-information', NULL, 'HTTP/1.1 200 OK');
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:48,代码来源:GlobalRedirectTest.php

示例9: saveConfiguration

 /**
  * Implements Mollom::saveConfiguration().
  */
 public function saveConfiguration($name, $value)
 {
     // Save it to the class properties if applicable.
     if (property_exists('\\Drupal\\mollom\\API\\DrupalClient', $name)) {
         $this->{$name} = $value;
     }
     // Persist in Drupal too.
     $name = $this->configuration_map[$name];
     $this->config->set($name, $value)->save();
 }
开发者ID:ABaldwinHunter,项目名称:durhamatletico-cms,代码行数:13,代码来源:DrupalClient.php

示例10: skip

 /**
  * Marks the check as skipped. It still can be ran manually, but will remain
  * skipped on the Run & Review page.
  */
 public function skip()
 {
     if (!$this->isSkipped()) {
         $this->config->set('skipped', TRUE);
         $this->config->set('skipped_by', Drupal::currentUser()->id());
         $this->config->set('skipped_on', time());
         $this->config->save();
         // Log.
         $context = array('!name' => $this->getTitle());
         SecurityReview::log($this, '!name check skipped', $context, RfcLogLevel::NOTICE);
     }
 }
开发者ID:AohRveTPV,项目名称:security_review,代码行数:16,代码来源:Check.php

示例11: batchVariableSet

 /**
  * {@inheritdoc}
  */
 public function batchVariableSet(array $variables)
 {
     $state_variables = xmlsitemap_state_variables();
     $config_variables = xmlsitemap_config_variables();
     foreach ($variables as $variable => $value) {
         if (isset($state_variables[$variable])) {
             $this->state->set($variable, $value);
         } else {
             $this->config->set($variable, $value);
         }
     }
     $this->config->save();
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:16,代码来源:XmlSitemapGenerator.php

示例12: assertFlag

 protected function assertFlag($variable, $assert_value = TRUE, $reset_if_true = TRUE)
 {
     $value = xmlsitemap_var($variable);
     if ($reset_if_true && $value) {
         $state_variables = xmlsitemap_state_variables();
         if (isset($state_variables[$variable])) {
             $this->state->set($variable, FALSE);
         } else {
             $this->config->set($variable, FALSE)->save();
         }
     }
     return $this->assertEqual($value, $assert_value, "xmlsitemap_{$variable} is " . ($assert_value ? 'TRUE' : 'FALSE'));
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:13,代码来源:XmlSitemapTestBase.php

示例13: testMailTheme

 /**
  * Tests the mail theme.
  */
 public function testMailTheme()
 {
     // Mail System uses its own configuration for the used mail plugins.
     // Use the mail collector just like WebTestBase::initConfig().
     $this->config->set('defaults.sender', 'test_mail_collector')->set('defaults.formatter', 'test_mail_collector')->save();
     // Send an email with the default setting (should NOT use the test theme).
     $this->drupalGet('/mailsystem-test/theme');
     $mails = $this->drupalGetMails();
     // Check the configuration and if the correct theme was used in mails.
     $this->assertEqual($this->config->get('theme'), 'current');
     $this->assertTrue(strpos($mails[0]['body'], 'Anonymous (not verified)') !== FALSE);
     // Install the test theme and set it as the mail theme.
     \Drupal::service('theme_handler')->install(array('mailsystem_test_theme'));
     $this->config->set('theme', 'mailsystem_test_theme')->save();
     // Send another email (now it should use the test theme).
     $this->drupalGet('/mailsystem-test/theme');
     $mails = $this->drupalGetMails();
     // Check the new configuration and ensure that our test theme and its
     // implementation of the username template are used in mails.
     $this->assertEqual($this->config->get('theme'), 'mailsystem_test_theme');
     $this->assertTrue(strpos($mails[1]['body'], 'Mailsystem test theme') !== FALSE);
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:25,代码来源:MailsystemTestThemeTest.php

示例14: testSpecialChars

 /**
  * Issue https://www.drupal.org/node/2047021.
  */
 public function testSpecialChars()
 {
     $this->config->set('tags', 'code');
     $this->config->set('language.php.enabled', TRUE);
     $this->config->set('decode_entities', TRUE);
     $this->config->save();
     $source = '<code language="php"><?php echo("&lt;b&gt;Hi&lt;/b&gt;"); ?></code>';
     // Create a node.
     $node = array('title' => 'Test for Custom Filter', 'body' => array(array('value' => $source, 'format' => 'geshifilter_text_format')), 'type' => 'geshifilter_content_type');
     $this->drupalCreateNode($node);
     $this->drupalGet('node/1');
     // The same string must be on page, not double encoded.
     $this->assertRaw('&quot;&lt;b&gt;Hi&lt;/b&gt;&quot;', 'The code is not double encoded.');
 }
开发者ID:hugronaphor,项目名称:cornel,代码行数:17,代码来源:GeshiFilterTest.php

示例15: removeNodeFromList

 /**
  * {@inheritdoc}
  */
 public function removeNodeFromList($param)
 {
     if ($param instanceof NodeInterface) {
         $param = $param->id();
     }
     if (!is_numeric($param)) {
         return FALSE;
     }
     $exclude_list = $this->getExcludedNodes();
     if (($key = array_search($param, $exclude_list)) !== FALSE) {
         unset($exclude_list[$key]);
         $this->settingsConfig->set('nid_list', $exclude_list)->save();
     }
     return $this;
 }
开发者ID:seongbae,项目名称:AsianChamber-Web,代码行数:18,代码来源:ExcludeNodeTitleManager.php


注:本文中的Drupal\Core\Config\Config::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。