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


PHP State\StateInterface类代码示例

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


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

示例1: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state) {
   $settings = $this->config('rest_api_doc.settings');
   $enabled_route_names = $settings->get('routes');
   $available_route_names = $this->state->get('rest_api_doc.rest_route_names');
   if (empty($available_route_names)) {
     return array(
       'no_routes' => array(
         '#markup' => $this->t('No REST enabled routes exist, please configure your REST end-points'),
       ),
     );
   }
   else {
     $routes = $this->routeProvider->getRoutesByNames($available_route_names);
     $descriptions = array();
     foreach ($routes as $route_name => $route) {
       $descriptions[$route_name] = $route_name . ' (' . $route->getPath() . ')';
     }
     $form['routes'] = array(
       '#type' => 'checkboxes',
       '#title' => $this->t('Enabled routes'),
       '#description' => $this->t('Provide documentation for the following route names'),
       '#options' => array_combine($available_route_names, $descriptions),
       '#default_value' => $enabled_route_names,
     );
     $form['overview'] = array(
       '#type' => 'textarea',
       '#default_value' => $settings->get('overview'),
       '#title' => $this->t('REST API overview'),
       '#description' => $this->t('Description to show on summary page. You may use site-wide tokens and some markup.'),
     );
   }
   return parent::buildForm($form, $form_state);
 }
开发者ID:ashzadeh,项目名称:afbs-ang,代码行数:36,代码来源:RestApiDocSettingsForm.php

示例2: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('system.cron');
     $form['description'] = array('#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>');
     $form['run'] = array('#type' => 'submit', '#value' => t('Run cron'), '#submit' => array(array($this, 'submitCron')));
     $status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => $this->dateFormatter->formatInterval(REQUEST_TIME - $this->state->get('system.cron_last')))) . '</p>';
     $form['status'] = array('#markup' => $status);
     $form['cron_url'] = array('#markup' => '<p>' . t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . $this->state->get('system.cron_key'), array('absolute' => TRUE)))) . '</p>');
     $form['cron'] = array('#title' => t('Cron settings'), '#type' => 'details', '#open' => TRUE);
     $options = array(3600, 10800, 21600, 43200, 86400, 604800);
     $form['cron']['cron_safe_threshold'] = array('#type' => 'select', '#title' => t('Run cron every'), '#description' => t('More information about setting up scheduled tasks can be found by <a href="@url">reading the cron tutorial on drupal.org</a>.', array('@url' => url('http://drupal.org/cron'))), '#default_value' => $config->get('threshold.autorun'), '#options' => array(0 => t('Never')) + array_map(array($this->dateFormatter, 'formatInterval'), array_combine($options, $options)));
     return parent::buildForm($form, $form_state);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:16,代码来源:CronForm.php

示例3: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['description'] = array('#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>');
     $form['run'] = array('#type' => 'submit', '#value' => t('Run cron'));
     $status = '<p>' . $this->t('Last run: %time ago.', array('%time' => $this->dateFormatter->formatTimeDiffSince($this->state->get('system.cron_last')))) . '</p>';
     $form['status'] = array('#markup' => $status);
     $cron_url = $this->url('system.cron', array('key' => $this->state->get('system.cron_key')), array('absolute' => TRUE));
     $form['cron_url'] = array('#markup' => '<p>' . t('To run cron from outside the site, go to <a href=":cron">@cron</a>', array(':cron' => $cron_url, '@cron' => $cron_url)) . '</p>');
     if (!$this->moduleHandler->moduleExists('automated_cron')) {
         $form['cron'] = array('#markup' => $this->t('Enable the <em>Automated Cron</em> module to allow cron execution at the end of a server response.'));
     }
     return $form;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:CronForm.php

示例4: handleResetSession

 /**
  * Utility submit function to reset the demo.
  *
  * @param array $form
  *   FormAPI form.
  * @param FormStateInterface $form_state
  *   FormAPI form state.
  *
  * @todo Note this does NOT clear any managed file references in Drupal's DB.
  *       It might be a good idea to add this.
  */
 public function handleResetSession(array &$form, FormStateInterface $form_state)
 {
     $this->state->delete('file_example_default_file');
     $this->state->delete('file_example_default_directory');
     $this->clearStoredData();
     drupal_set_message('Session reset.');
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:18,代码来源:FileExampleReadWriteForm.php

示例5: alterLocalTasks

 /**
  * Alters base_route and parent_id into the views local tasks.
  */
 public function alterLocalTasks(&$local_tasks)
 {
     $view_route_names = $this->state->get('views.view_route_names');
     foreach ($this->getApplicableMenuViews() as $pair) {
         /** @var $executable \Drupal\views\ViewExecutable */
         list($executable, $display_id) = $pair;
         $executable->setDisplay($display_id);
         $menu = $executable->display_handler->getOption('menu');
         // We already have set the base_route for default tabs.
         if (in_array($menu['type'], array('tab'))) {
             $plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id;
             $view_route_name = $view_route_names[$executable->storage->id() . '.' . $display_id];
             // Don't add a local task for views which override existing routes.
             if ($view_route_name != $plugin_id) {
                 unset($local_tasks[$plugin_id]);
                 continue;
             }
             // Find out the parent route.
             // @todo Find out how to find both the root and parent tab.
             $path = $executable->display_handler->getPath();
             $split = explode('/', $path);
             array_pop($split);
             $path = implode('/', $split);
             $pattern = '/' . str_replace('%', '{}', $path);
             if ($routes = $this->routeProvider->getRoutesByPattern($pattern)) {
                 foreach ($routes->all() as $name => $route) {
                     $local_tasks['views_view:' . $plugin_id]['base_route'] = $name;
                     // Skip after the first found route.
                     break;
                 }
             }
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:37,代码来源:ViewsLocalTask.php

示例6: testSubscribing

  /**
   * Tests altering and finished event.
   *
   * @covers ::onRouteAlter
   * @covers ::onRouteFinished
   */
  public function testSubscribing() {

    // Ensure that onRouteFinished can be called without throwing notices
    // when no path roots got set.
    $this->pathRootsSubscriber->onRouteFinished();

    $route_collection = new RouteCollection();
    $route_collection->add('test_route1', new Route('/test/bar'));
    $route_collection->add('test_route2', new Route('/test/baz'));
    $route_collection->add('test_route3', new Route('/test2/bar/baz'));

    $event = new RouteBuildEvent($route_collection, 'provider');
    $this->pathRootsSubscriber->onRouteAlter($event);

    $route_collection = new RouteCollection();
    $route_collection->add('test_route4', new Route('/test1/bar'));
    $route_collection->add('test_route5', new Route('/test2/baz'));
    $route_collection->add('test_route6', new Route('/test2/bar/baz'));

    $event = new RouteBuildEvent($route_collection, 'provider');
    $this->pathRootsSubscriber->onRouteAlter($event);

    $this->state->expects($this->once())
      ->method('set')
      ->with('router.path_roots', array('test', 'test2', 'test1'));

    $this->pathRootsSubscriber->onRouteFinished();
  }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:34,代码来源:PathRootsSubscriberTest.php

示例7: reportWork

 /**
  * Simple reporter log and display information about the queue.
  *
  * @param int $worker
  *   Worker number.
  * @param object $item
  *   The $item which was stored in the cron queue.
  */
 protected function reportWork($worker, $item)
 {
     if ($this->state->get('cron_example_show_status_message')) {
         drupal_set_message($this->t('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)]));
     }
     $this->logger->get('cron_example')->info('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)]);
 }
开发者ID:dropdog,项目名称:play,代码行数:15,代码来源:ReportWorkerBase.php

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

示例9: addCollections

 /**
  * Reacts to the ConfigEvents::COLLECTION_NAMES event.
  *
  * @param \Drupal\Core\Config\ConfigCollectionInfo $collection_info
  *   The configuration collection names event.
  */
 public function addCollections(ConfigCollectionInfo $collection_info)
 {
     $collections = $this->state->get('config_collection_install_test.collection_names', array());
     foreach ($collections as $collection) {
         $collection_info->addCollection($collection);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:EventSubscriber.php

示例10: processInbound

 /**
  * {@inheritdoc}
  */
 public function processInbound($path, Request $request)
 {
     if ($this->state->get('update_script_test_broken_inbound', FALSE)) {
         throw new \RuntimeException();
     } else {
         return $path;
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:BrokenInboundPathProcessor.php

示例11: render

 /**
  * {@inheritdoc}
  */
 public function render(array $js_assets)
 {
     $elements = array();
     // A dummy query-string is added to filenames, to gain control over
     // browser-caching. The string changes on every update or full cache
     // flush, forcing browsers to load a new copy of the files, as the
     // URL changed. Files that should not be cached (see _drupal_add_js())
     // get REQUEST_TIME as query-string instead, to enforce reload on every
     // page request.
     $default_query_string = $this->state->get('system.css_js_query_string') ?: '0';
     // For inline JavaScript to validate as XHTML, all JavaScript containing
     // XHTML needs to be wrapped in CDATA. To make that backwards compatible
     // with HTML 4, we need to comment out the CDATA-tag.
     $embed_prefix = "\n<!--//--><![CDATA[//><!--\n";
     $embed_suffix = "\n//--><!]]>\n";
     // Defaults for each SCRIPT element.
     $element_defaults = array('#type' => 'html_tag', '#tag' => 'script', '#value' => '');
     // Loop through all JS assets.
     foreach ($js_assets as $js_asset) {
         // Element properties that do not depend on JS asset type.
         $element = $element_defaults;
         $element['#browsers'] = $js_asset['browsers'];
         // Element properties that depend on item type.
         switch ($js_asset['type']) {
             case 'setting':
                 $element['#value_prefix'] = $embed_prefix;
                 $element['#value'] = 'var drupalSettings = ' . Json::encode(drupal_merge_js_settings($js_asset['data'])) . ";";
                 $element['#value_suffix'] = $embed_suffix;
                 break;
             case 'inline':
                 $element['#value_prefix'] = $embed_prefix;
                 $element['#value'] = $js_asset['data'];
                 $element['#value_suffix'] = $embed_suffix;
                 break;
             case 'file':
                 $query_string = empty($js_asset['version']) ? $default_query_string : 'v=' . $js_asset['version'];
                 $query_string_separator = strpos($js_asset['data'], '?') !== FALSE ? '&' : '?';
                 $element['#attributes']['src'] = file_create_url($js_asset['data']);
                 // Only add the cache-busting query string if this isn't an aggregate
                 // file.
                 if (!isset($js_asset['preprocessed'])) {
                     $element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : REQUEST_TIME);
                 }
                 break;
             case 'external':
                 $element['#attributes']['src'] = $js_asset['data'];
                 break;
             default:
                 throw new \Exception('Invalid JS asset type.');
         }
         // Attributes may only be set if this script is output independently.
         if (!empty($element['#attributes']['src']) && !empty($js_asset['attributes'])) {
             $element['#attributes'] += $js_asset['attributes'];
         }
         $elements[] = $element;
     }
     return $elements;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:61,代码来源:JsCollectionRenderer.php

示例12: loadMenuPathRoots

 /**
  * Loads menu path roots to prepopulate cache.
  */
 protected function loadMenuPathRoots()
 {
     if ($roots = $this->state->get('router.path_roots')) {
         foreach ($roots as $root) {
             $this->storage[$root] = NULL;
             $this->persist($root);
         }
     }
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:12,代码来源:AliasWhitelist.php

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

示例14: applies

 /**
  * {@inheritdoc}
  */
 public function applies(RouteMatchInterface $route_match)
 {
     if (!$this->state->get('system.maintenance_mode')) {
         return FALSE;
     }
     if ($route = $route_match->getRouteObject()) {
         if ($route->getOption('_maintenance_access')) {
             return FALSE;
         }
     }
     return TRUE;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:15,代码来源:MaintenanceMode.php

示例15: getDatabase

 /**
  * Gets the database connection object.
  *
  * @return \Drupal\Core\Database\Connection
  *   The database connection.
  */
 public function getDatabase()
 {
     if (!isset($this->database)) {
         // See if the database info is in state - if not, fallback to
         // configuration.
         if (isset($this->configuration['database_state_key'])) {
             $this->database = $this->setUpDatabase($this->state->get($this->configuration['database_state_key']));
         } else {
             $this->database = $this->setUpDatabase($this->configuration);
         }
     }
     return $this->database;
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:19,代码来源:SqlBase.php


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