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


PHP Config\Config类代码示例

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


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

示例1: 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

示例2: 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

示例3: testRename

 /**
  * @covers ::rename
  */
 public function testRename()
 {
     $old = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
     $new = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
     $this->storage->expects($this->exactly(2))->method('readMultiple')->willReturnMap([[[$old->getName()], $old->getRawData()], [[$new->getName()], $new->getRawData()]]);
     $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with($old->getCacheTags());
     $this->storage->expects($this->once())->method('rename')->with($old->getName(), $new->getName());
     $this->configFactory->rename($old->getName(), $new->getName());
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:ConfigFactoryTest.php

示例4: __construct

 /**
  * Constructs a ImageEffectsPluginBase object.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param mixed $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
  *   The configuration factory.
  * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
  *   The URL generator.
  * @param \Psr\Log\LoggerInterface $logger
  *   The image_effects logger.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, UrlGeneratorInterface $url_generator, LoggerInterface $logger)
 {
     $this->config = $config_factory->getEditable('image_effects.settings');
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->pluginType = $configuration['plugin_type'];
     $config = $this->config->get($this->pluginType . '.plugin_settings.' . $plugin_id);
     $this->setConfiguration(array_merge($this->defaultConfiguration(), is_array($config) ? $config : array()));
     $this->urlGenerator = $url_generator;
     $this->logger = $logger;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:26,代码来源:ImageEffectsPluginBase.php

示例5: importDelete

 /**
  * {@inheritdoc}
  */
 public function importDelete($name, Config $new_config, Config $old_config)
 {
     // If the field has been deleted in the same import, the instance will be
     // deleted by then, and there is nothing left to do. Just return TRUE so
     // that the file does not get written to active store.
     if (!$old_config->get()) {
         return TRUE;
     }
     return parent::importDelete($name, $new_config, $old_config);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:13,代码来源:FieldInstanceConfigStorage.php

示例6: filterOverride

 /**
  * Filters data in the override based on what is currently in configuration.
  *
  * @param \Drupal\Core\Config\Config $config
  *   Current configuration object.
  * @param \Drupal\Core\Config\StorableConfigBase $override
  *   Override object corresponding to the configuration to filter data in.
  */
 protected function filterOverride(Config $config, StorableConfigBase $override)
 {
     $override_data = $override->get();
     $this->filterNestedArray($config->get(), $override_data);
     if (empty($override_data)) {
         // If no override values are left that would apply, remove the override.
         $override->delete();
     } else {
         // Otherwise set the filtered override values back.
         $override->setData($override_data)->save();
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:20,代码来源:ConfigFactoryOverrideBase.php

示例7: forbiddenMessage

 /**
  * {@inheritdoc}
  */
 public function forbiddenMessage(EntityInterface $entity, $field_name)
 {
     if (!isset($this->authenticatedCanPostComments)) {
         // We only output a link if we are certain that users will get the
         // permission to post comments by logging in.
         $this->authenticatedCanPostComments = $this->entityManager->getStorage('user_role')->load(DRUPAL_AUTHENTICATED_RID)->hasPermission('post comments');
     }
     if ($this->authenticatedCanPostComments) {
         // We cannot use drupal_get_destination() because these links
         // sometimes appear on /node and taxonomy listing pages.
         if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == CommentItemInterface::FORM_SEPARATE_PAGE) {
             $destination = array('destination' => 'comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name . '#comment-form');
         } else {
             $destination = array('destination' => $entity->getSystemPath() . '#comment-form');
         }
         if ($this->userConfig->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
             // Users can register themselves.
             return $this->t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array('@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)), '@register' => $this->urlGenerator->generateFromRoute('user.register', array(), array('query' => $destination))));
         } else {
             // Only admins can add new users, no public registration.
             return $this->t('<a href="@login">Log in</a> to post comments', array('@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination))));
         }
     }
     return '';
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:CommentManager.php

示例8: config

 /**
  * Retrieves a configuration object.
  *
  * This is the main entry point to the configuration API. Calling
  * @code $this->config('book.admin') @endcode will return a configuration
  * object in which the book module can store its administrative settings.
  *
  * @param string $name
  *   The name of the configuration object to retrieve. The name corresponds to
  *   a configuration file. For @code \Drupal::config('book.admin') @endcode,
  *   the config object returned will contain the contents of book.admin
  *   configuration file.
  *
  * @return \Drupal\Core\Config\Config
  *   A configuration object.
  */
 protected function config($name)
 {
     if (!$this->configFactory) {
         $this->configFactory = $this->container()->get('config.factory');
     }
     return $this->configFactory->get($name);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:23,代码来源:ControllerBase.php

示例9: canRedirect

 /**
  * Determines if redirect may be performed.
  *
  * @param Request $request
  *   The current request object.
  * @param string $route_name
  *   The current route name.
  *
  * @return bool
  *   TRUE if redirect may be performed.
  */
 public function canRedirect(Request $request, $route_name = NULL)
 {
     $can_redirect = TRUE;
     if (isset($route_name)) {
         $route = $this->routeProvider->getRouteByName($route_name);
         if ($this->config->get('access_check')) {
             // Do not redirect if is a protected page.
             $can_redirect &= $this->accessManager->check($route, $request, $this->account);
         }
     } else {
         $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
     }
     if (strpos($request->getScriptName(), 'index.php') === FALSE) {
         // Do not redirect if the root script is not /index.php.
         $can_redirect = FALSE;
     } elseif (!($request->isMethod('GET') || $request->isMethod('HEAD'))) {
         // Do not redirect if this is other than GET request.
         $can_redirect = FALSE;
     } elseif ($this->state->get('system.maintenance_mode') || defined('MAINTENANCE_MODE')) {
         // Do not redirect in offline or maintenance mode.
         $can_redirect = FALSE;
     } elseif ($this->config->get('ignore_admin_path') && isset($route)) {
         // Do not redirect on admin paths.
         $can_redirect &= !(bool) $route->getOption('_admin_route');
     }
     return $can_redirect;
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:38,代码来源:RedirectChecker.php

示例10: build

 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>');
     $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary'));
     $breadcrumb[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
     return $breadcrumb;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:ForumBreadcrumbBuilderBase.php

示例11: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     if ($this->sharethisSettings->get('location') === 'block') {
         $st_js = $this->sharethisManager->sharethisIncludeJs();
         $markup = $this->sharethisManager->blockContents();
         return ['#theme' => 'sharethis_block', '#content' => $markup, '#attached' => array('library' => array('sharethis/sharethispickerexternalbuttonsws', 'sharethis/sharethispickerexternalbuttons', 'sharethis/sharethis'), 'drupalSettings' => array('sharethis' => $st_js))];
     }
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:11,代码来源:SharethisBlock.php

示例12: refresh

 /**
  * {@inheritdoc}
  */
 public function refresh(FeedInterface $feed)
 {
     // Store feed URL to track changes.
     $feed_url = $feed->getUrl();
     // Fetch the feed.
     try {
         $success = $this->fetcherManager->createInstance($this->config->get('fetcher'))->fetch($feed);
     } catch (PluginException $e) {
         $success = FALSE;
         watchdog_exception('aggregator', $e);
     }
     // Store instances in an array so we dont have to instantiate new objects.
     $processor_instances = array();
     foreach ($this->config->get('processors') as $processor) {
         try {
             $processor_instances[$processor] = $this->processorManager->createInstance($processor);
         } catch (PluginException $e) {
             watchdog_exception('aggregator', $e);
         }
     }
     // We store the hash of feed data in the database. When refreshing a
     // feed we compare stored hash and new hash calculated from downloaded
     // data. If both are equal we say that feed is not updated.
     $hash = hash('sha256', $feed->source_string);
     $has_new_content = $success && $feed->getHash() != $hash;
     if ($has_new_content) {
         // Parse the feed.
         try {
             if ($this->parserManager->createInstance($this->config->get('parser'))->parse($feed)) {
                 if (!$feed->getWebsiteUrl()) {
                     $feed->setWebsiteUrl($feed->getUrl());
                 }
                 $feed->setHash($hash);
                 // Update feed with parsed data.
                 $feed->save();
                 // Log if feed URL has changed.
                 if ($feed->getUrl() != $feed_url) {
                     $this->logger->notice('Updated URL for feed %title to %url.', array('%title' => $feed->label(), '%url' => $feed->getUrl()));
                 }
                 $this->logger->notice('There is new syndicated content from %site.', array('%site' => $feed->label()));
                 // If there are items on the feed, let enabled processors process them.
                 if (!empty($feed->items)) {
                     foreach ($processor_instances as $instance) {
                         $instance->process($feed);
                     }
                 }
             }
         } catch (PluginException $e) {
             watchdog_exception('aggregator', $e);
         }
     }
     // Processing is done, call postProcess on enabled processors.
     foreach ($processor_instances as $instance) {
         $instance->postProcess($feed);
     }
     return $has_new_content;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:60,代码来源:ItemsImporter.php

示例13: build

 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addCacheContexts(['route']);
     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary'));
     $breadcrumb->addCacheableDependency($vocabulary);
     $links[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
     return $breadcrumb->setLinks($links);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:ForumBreadcrumbBuilderBase.php

示例14: 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 TRUE;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:13,代码来源:Config.php

示例15: onTerminate

 /**
  * Run the automated cron if enabled.
  *
  * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event
  *   The Event to process.
  */
 public function onTerminate(PostResponseEvent $event)
 {
     $interval = $this->config->get('interval');
     if ($interval > 0) {
         $cron_next = $this->state->get('system.cron_last', 0) + $interval;
         if ((int) $event->getRequest()->server->get('REQUEST_TIME') > $cron_next) {
             $this->cron->run();
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:AutomatedCron.php


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