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


PHP Drupal::config方法代码示例

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


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

示例1: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $view = $this->entity;
     $form['#prefix'] = '<div id="views-preview-wrapper" class="views-admin clearfix">';
     $form['#suffix'] = '</div>';
     $form['#id'] = 'views-ui-preview-form';
     $form_state->disableCache();
     $form['controls']['#attributes'] = array('class' => array('clearfix'));
     $form['controls']['title'] = array('#prefix' => '<h2 class="view-preview-form__title">', '#markup' => $this->t('Preview'), '#suffix' => '</h2>');
     // Add a checkbox controlling whether or not this display auto-previews.
     $form['controls']['live_preview'] = array('#type' => 'checkbox', '#id' => 'edit-displays-live-preview', '#title' => $this->t('Auto preview'), '#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'));
     // Add the arguments textfield
     $form['controls']['view_args'] = array('#type' => 'textfield', '#title' => $this->t('Preview with contextual filters:'), '#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')), '#id' => 'preview-args');
     $args = array();
     if (!$form_state->isValueEmpty('view_args')) {
         $args = explode('/', $form_state->getValue('view_args'));
     }
     $user_input = $form_state->getUserInput();
     if ($form_state->get('show_preview') || !empty($user_input['js'])) {
         $form['preview'] = array('#weight' => 110, '#theme_wrappers' => array('container'), '#attributes' => array('id' => 'views-live-preview'), 'preview' => $view->renderPreview($this->displayID, $args));
     }
     $uri = $view->urlInfo('preview-form');
     $uri->setRouteParameter('display_id', $this->displayID);
     $form['#action'] = $uri->toString();
     return $form;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:29,代码来源:ViewPreviewForm.php

示例2: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_menu_block:account');
     // Make test-page default.
     \Drupal::config('system.site')->set('page.front', 'test-page')->save();
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:10,代码来源:UserAccountLinksTests.php

示例3: dump

 /**
  * {@inheritdoc}
  *
  * The file name for the CSS or JS cache file is generated from the hash of
  * the aggregated contents of the files in $data. This forces proxies and
  * browsers to download new CSS when the CSS changes.
  */
 public function dump($data, $file_extension)
 {
     // Prefix filename to prevent blocking by firewalls which reject files
     // starting with "ad*".
     $filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension;
     // Create the css/ or js/ path within the files folder.
     $path = 'public://' . $file_extension;
     $uri = $path . '/' . $filename;
     // Create the CSS or JS file.
     file_prepare_directory($path, FILE_CREATE_DIRECTORY);
     if (!file_exists($uri) && !file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) {
         return FALSE;
     }
     // If CSS/JS gzip compression is enabled and the zlib extension is available
     // then create a gzipped version of this file. This file is served
     // conditionally to browsers that accept gzip using .htaccess rules.
     // It's possible that the rewrite rules in .htaccess aren't working on this
     // server, but there's no harm (other than the time spent generating the
     // file) in generating the file anyway. Sites on servers where rewrite rules
     // aren't working can set css.gzip to FALSE in order to skip
     // generating a file that won't be used.
     if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) {
         if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
             return FALSE;
         }
     }
     return $uri;
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:35,代码来源:AssetDumper.php

示例4: __construct

 /**
  * Constructs a CheckoutPaneManager object.
  *
  * @param \Traversable $namespaces
  *   An object that implements \Traversable which contains the root paths
  *   keyed by the corresponding namespace to look for plugin implementations,
  * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
  *   Cache backend instance to use.
  * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  *   The module handler.
  */
 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler)
 {
     parent::__construct('Plugin/Ubercart/CheckoutPane', $namespaces, $module_handler, CheckoutPanePluginInterface::class, CheckoutPane::class);
     $this->alterInfo('payment_method');
     $this->setCacheBackend($cache_backend, 'uc_checkout_panes');
     $this->paneConfig = \Drupal::config('uc_cart.settings')->get('panes');
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:18,代码来源:CheckoutPaneManager.php

示例5: purgeTags

 /**
  * Purges cache tags on CloudFlare.
  *
  * @todo Once https://github.com/d8-contrib-modules/cloudflare/issues/16 is
  *   done, this should disappear.
  *
  * @param string[] $tags
  *   The list of tags for which to invalidate cache items.
  */
 public function purgeTags(array $tags)
 {
     $config = \Drupal::config('cloudflare.settings');
     $api_key = $config->get('apikey');
     $email = $config->get('email');
     $zone = $config->get('zone');
     // If the module is not yet configured, don't attempt to purge.
     // @todo Improve the rest of the architecture of this module so this check
     //   is not necessary anymore.
     if (!isset($api_key)) {
         return;
     }
     try {
         $this->zoneApi = new ZoneApi($api_key, $email);
         // @todo rethink how to handle cloudflare zones in Drupal.
         if (is_null($zone)) {
             $zones = $this->zoneApi->listZones();
             $zone = $zones[0]->getZoneId();
         }
         $this->zoneApi->purgeTags($zone, $tags);
     } catch (CloudFlareHttpException $e) {
         drupal_set_message("Unable to clear zone cache. " . $e->getMessage(), 'error');
         \Drupal::logger('cloudflare')->error($e->getMessage());
         return;
     } catch (CloudFlareApiException $e) {
         drupal_set_message("Unable to clear zone cache. " . $e->getMessage(), 'error');
         \Drupal::logger('cloudflare')->error($e->getMessage());
         return;
     }
     // If no exceptions have been thrown then the request has been successful.
 }
开发者ID:victorcpereira,项目名称:cloudflare,代码行数:40,代码来源:CacheTagsInvalidator.php

示例6: testDatabaseLoaded

 /**
  * Tests that the database was properly loaded.
  */
 public function testDatabaseLoaded()
 {
     foreach (['user', 'node', 'system', 'update_test_schema'] as $module) {
         $this->assertEqual(drupal_get_installed_schema_version($module), 8000, SafeMarkup::format('Module @module schema is 8000', ['@module' => $module]));
     }
     // Ensure that all {router} entries can be unserialized. If they cannot be
     // unserialized a notice will be thrown by PHP.
     $result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1);
     // For the purpose of fetching the notices and displaying more helpful error
     // messages, let's override the error handler temporarily.
     set_error_handler(function ($severity, $message, $filename, $lineno) {
         throw new \ErrorException($message, 0, $severity, $filename, $lineno);
     });
     foreach ($result as $route_name => $route) {
         try {
             unserialize($route);
         } catch (\Exception $e) {
             $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
         }
     }
     restore_error_handler();
     // Before accessing the site we need to run updates first or the site might
     // be broken.
     $this->runUpdates();
     $this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
     $this->drupalGet('<front>');
     $this->assertText('Site-Install');
     // Ensure that the database tasks have been run during set up. Neither MySQL
     // nor SQLite make changes that are testable.
     $database = $this->container->get('database');
     if ($database->driver() == 'pgsql') {
         $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
         $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
     }
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:38,代码来源:UpdatePathTestBaseTest.php

示例7: get

 /**
  * Responds to GET requests.
  *
  * Returns a menu tree for the specified menu name.
  *
  * @param int $menu_name
  *   The machine name of the Drupal menu.
  *
  * @return \Drupal\rest\ResourceResponse
  *   The response containing the menu tree.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function get($menu_name = NULL)
 {
     if ($menu_name) {
         // Get menu tree resource config, set at /admin/config/services/menutree.
         $config = \Drupal::config('menutree_resource.services_settings');
         $services_menus = $config->get('services_menus');
         // Only allow a response if the menu is in config
         if (in_array($menu_name, array_filter(array_values($services_menus)))) {
             $menu_tree = \Drupal::menuTree();
             $parameters = new MenuTreeParameters();
             $parameters->onlyEnabledLinks();
             $tree = $menu_tree->load($menu_name, $parameters);
             if (!empty($tree)) {
                 $manipulators = array(array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'));
                 $tree = $menu_tree->transform($tree, $manipulators);
                 $build = $menu_tree->build($tree);
                 // Clean the menu tree so it's ready for serialisation in a resource response.
                 $items = $this->clean_tree($build['#items']);
                 return new ResourceResponse($items);
             }
             throw new NotFoundHttpException(t('Menu with name @menu_name was not found', array('@menu_name' => $menu_name)));
         }
         throw new NotFoundHttpException(t('Menu tree @menu_name not allowed.', array('@menu_name' => $menu_name)));
     }
     throw new HttpException(t('No menu name was provided'));
 }
开发者ID:joesb,项目名称:wunderhub,代码行数:39,代码来源:MenuTreeResourceMenuResource.php

示例8: testBlockExampleBasic

 /**
  * Tests block_example functionality.
  */
 public function testBlockExampleBasic()
 {
     // Login the admin user.
     $this->drupalLogin($this->webUser);
     $theme_name = \Drupal::config('system.theme')->get('default');
     // Verify the blocks are listed to be added.
     $this->drupalGet('admin/structure/block/list/' . $theme_name);
     $this->assertRaw(t('Title of first block (example_configurable_text)'), 'Block configurable-string found.');
     $this->assertRaw(t('Example: empty block'), 'Block empty-block found.');
     $this->assertRaw(t('Example: uppercase this please'), 'Block uppercase found.');
     // Define and place blocks.
     $settings_configurable = array('label' => t('Title of first block (example_configurable_text)'), 'id' => 'block_example_example_configurable_text', 'theme' => $theme_name);
     $this->drupalPlaceBlock('example_configurable_text', $settings_configurable);
     $settings_uppercase = array('label' => t('Configurable block to be uppercased'), 'id' => 'block_example_example_uppercased', 'theme' => $theme_name);
     $this->drupalPlaceBlock('example_uppercase', $settings_uppercase);
     $settings_empty = array('label' => t('Example: empty block'), 'id' => 'block_example_example_empty', 'theme' => $theme_name);
     $this->drupalPlaceBlock('example_empty', $settings_empty);
     // Verify that blocks are there. Empty block will not be shown, because it
     // is empty.
     $this->drupalGet('/');
     $this->assertRaw($settings_configurable['label'], 'Block configurable test not found.');
     $this->assertNoRaw($settings_uppercase['label'], 'Block uppercase with normal label not found.');
     $this->assertRaw(Unicode::strtoupper($settings_uppercase['label']), 'Block uppercase with uppercased label found.');
     $this->assertNoRaw($settings_empty['label'], 'Block empty not found.');
     // Change content of configurable text block.
     $edit = array('settings[block_example_string_text]' => $this->randomMachineName());
     $this->drupalPostForm('admin/structure/block/manage/' . $settings_configurable['id'], $edit, t('Save block'));
     // Verify that new content is shown.
     $this->drupalGet('/');
     $this->assertRaw($edit['settings[block_example_string_text]'], 'Content of configurable text block successfully verified.');
 }
开发者ID:njcameron,项目名称:ncmd,代码行数:34,代码来源:BlockExampleTest.php

示例9: content

 public function content()
 {
     $config = \Drupal::config('tweets.settings');
     $username = '<a href="http://www.twitter.com/' . $config->get('twitter_username') . '">@' . $config->get('twitter_username') . '</a>';
     return array('#theme' => 'tweets_block', '#username' => $username, '#tweets' => $this->tweets, '#attached' => array('library' => array('tweets/base')));
     return array('#type' => 'markup', '#markup' => $this->t('Hello, Systemick World!'));
 }
开发者ID:systemick3,项目名称:systemick.co.uk,代码行数:7,代码来源:TweetsController.php

示例10: buildForm

 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $system_roles = user_roles($membersonly = TRUE);
     $config = \Drupal::config('registration_role_with_approval.settings');
     $site_config = \Drupal::configFactory()->get('system.mail');
     $mailing_list = $config->get('mailing_list');
     if ($mailing_list == "") {
         $mailing_list .= $site_config->get('mail');
     }
     $email_subject = $config->get('email_subject');
     $email_body = $config->get('email_body');
     $profile_roles = $config->get('profile_roles');
     $form['roles'] = array('#type' => 'fieldset', '#title' => t('Avaliable Roles on registration form'), '#collapsible' => TRUE);
     foreach ($system_roles as $system_role) {
         $role_id = $system_role->id();
         if ($role_id != '0' && $role_id != 'authenticated') {
             $form['roles'][$system_role->id()] = array('#type' => 'checkbox', '#title' => t($system_role->label()), '#default_value' => $profile_roles[$system_role->id()]['default']);
             $form['roles'][$system_role->id() . "needs_approval"] = array('#type' => 'checkbox', '#title' => t('needs approval'), '#states' => array('invisible' => array(":input[name='{$role_id}']" => array('checked' => FALSE))), '#attributes' => array('style' => 'margin-left: 2em'), '#default_value' => $profile_roles[$system_role->id()]['needs_approval']);
         }
     }
     $form['custom_mail'] = array('#type' => 'fieldset', '#title' => t('Custom registration email configuration'), '#collapsible' => TRUE);
     $form['custom_mail']['new_email'] = array("#type" => "textfield", "#title" => "Enter valid email");
     $form['custom_mail']['add_email'] = array("#type" => "button", "#value" => "Add email", "#ajax" => array('callback' => 'Drupal\\registration_role_with_approval\\Form\\RegistrationRoleWithApprovalSettingsForm::addEmailCallback', 'event' => 'click', 'effect' => 'fade', 'progress' => array('type' => 'throbber')));
     $form['custom_mail']['mailing_list'] = array("#type" => "textarea", "#title" => "Mailing list", "#default_value" => $mailing_list);
     $form['custom_mail']['email_subject'] = array("#type" => "textfield", "#title" => "Email subject", "#default_value" => $email_subject);
     $form['custom_mail']['email_body'] = array("#type" => "textarea", "#title" => "Email body", "#default_value" => $email_body);
     return parent::buildForm($form, $form_state);
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:28,代码来源:RegistrationRoleWithApprovalSettingsForm.php

示例11: testUserName

 public function testUserName()
 {
     $this->drupalLogin($this->drupalCreateUser(array('access user profiles')));
     $view = Views::getView('test_views_handler_field_user_name');
     $this->executeView($view);
     $view->field['name']->options['link_to_user'] = TRUE;
     $username = $view->result[0]->users_field_data_name = $this->randomMachineName();
     $view->result[0]->users_field_data_uid = 1;
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
     $this->assertTrue(strpos($render, 'user/1') !== FALSE, 'If link to user is checked the link to the user should appear as well.');
     $view->field['name']->options['link_to_user'] = FALSE;
     $username = $view->result[0]->users_field_data_name = $this->randomMachineName();
     $view->result[0]->users_field_data_uid = 1;
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertIdentical($render, $username, 'If the user is not linked the username should be printed out for a normal user.');
     $view->result[0]->users_field_data_uid = 0;
     $anon_name = \Drupal::config('user.settings')->get('anonymous');
     $view->result[0]->users_field_data_name = '';
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertIdentical($render, $anon_name, 'For user0 it should use the default anonymous name by default.');
     $view->field['name']->options['overwrite_anonymous'] = TRUE;
     $anon_name = $view->field['name']->options['anonymous_text'] = $this->randomMachineName();
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertIdentical($render, $anon_name, 'For user0 it should use the configured anonymous text if overwrite_anonymous is checked.');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:26,代码来源:HandlerFieldUserNameTest.php

示例12: access

 /**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, NodeInterface $node = NULL)
 {
     if ($node->bundle() && \Drupal::config('webform.settings')->get('node_' . $node->bundle())) {
         return AccessResult::allowed();
     }
     return AccessResult::forbidden();
 }
开发者ID:Progressable,项目名称:openway8,代码行数:10,代码来源:WebformNodeAccessCheck.php

示例13: create

 /**
  * Creates an indexing batch for a given search index.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The search index for which items should be indexed.
  * @param int|null $batch_size
  *   (optional) Number of items to index per batch. Defaults to the cron limit
  *   set for the index.
  * @param int $limit
  *   (optional) Maximum number of items to index. Defaults to indexing all
  *   remaining items.
  *
  * @throws \Drupal\search_api\SearchApiException
  *   Thrown if the batch could not be created.
  */
 public static function create(IndexInterface $index, $batch_size = NULL, $limit = -1) {
   // Check if the size should be determined by the index cron limit option.
   if ($batch_size === NULL) {
     // Use the size set by the index.
     $batch_size = $index->getOption('cron_limit', \Drupal::config('search_api.settings')->get('default_cron_limit'));
   }
   // Check if indexing items is allowed.
   if ($index->status() && !$index->isReadOnly() && $batch_size !== 0 && $limit !== 0) {
     // Define the search index batch definition.
     $batch_definition = array(
       'operations' => array(
         array(array(__CLASS__, 'process'), array($index, $batch_size, $limit)),
       ),
       'finished' => array(__CLASS__, 'finish'),
       'progress_message' => static::t('Completed about @percentage% of the indexing operation (@current of @total).'),
     );
     // Schedule the batch.
     batch_set($batch_definition);
   }
   else {
     $args = array(
       '%size' => $batch_size,
       '%limit' => $limit,
       '%name' => $index->label(),
     );
     throw new SearchApiException(new FormattableMarkup('Failed to create a batch with batch size %size and limit %limit for index %name', $args));
   }
 }
开发者ID:jkyto,项目名称:agolf,代码行数:43,代码来源:IndexBatchHelper.php

示例14: cosign_login

 public function cosign_login(Request $request)
 {
     $request_uri = $request->getRequestUri();
     global $base_path;
     if (!CosignSharedFunctions::cosign_is_https()) {
         return new TrustedRedirectResponse('https://' . $_SERVER['HTTP_HOST'] . $request_uri);
     } else {
         if ($request_uri == $base_path) {
             //The front page is set to /user. we have to login here to avoid a redirect loop
             $username = CosignSharedFunctions::cosign_retrieve_remote_user();
             $user = CosignSharedFunctions::cosign_user_status($username);
             if (empty($user) || $user->id() == 0) {
                 $response = array('#type' => 'markup', '#title' => 'Auto creation of user accounts is disabled.', '#markup' => t('<p>This site does not auto create users from cosign. Please contact the <a href="mailto:' . \Drupal::config("system.site")->get("mail") . '">site administrator</a> to have an account created.</p>'));
                 return $response;
             } else {
                 if (in_array('administrator', $user->getRoles())) {
                     drupal_set_message('When the homepage is set to /user (Drupal default), anonymous browsing will not always work', 'warning');
                 }
                 $referrer = $base_path . 'user';
             }
         } elseif (isset($_SERVER['HTTP_REFERER'])) {
             $referrer = $_SERVER['HTTP_REFERER'];
         } else {
             $referrer = $base_path;
         }
         return new TrustedRedirectResponse($referrer);
     }
 }
开发者ID:bertrama,项目名称:cosign-drupal8,代码行数:28,代码来源:CosignController.php

示例15: create

 /**
  * {@inheritdoc}
  */
 public function create(array $values = array())
 {
     $store_config = \Drupal::config('uc_store.settings');
     // Set the primary email address.
     if (empty($values['primary_email']) && !empty($values['uid'])) {
         if ($account = User::load($values['uid'])) {
             $values['primary_email'] = $account->mail;
         }
     }
     // Set the default order status.
     if (empty($values['order_status'])) {
         $values['order_status'] = uc_order_state_default('in_checkout');
     }
     // Set the default currency.
     if (empty($values['currency'])) {
         $values['currency'] = $store_config->get('currency.code');
     }
     // Set the default country codes.
     if (empty($values['billing_country'])) {
         $values['billing_country'] = $store_config->get('address.country');
     }
     if (empty($values['delivery_country'])) {
         $values['delivery_country'] = $store_config->get('address.country');
     }
     // Set the created time to now.
     if (empty($values['created'])) {
         $values['created'] = REQUEST_TIME;
     }
     return parent::create($values);
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:33,代码来源:OrderStorage.php


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