本文整理汇总了PHP中Drupal\Core\State\StateInterface类的典型用法代码示例。如果您正苦于以下问题:PHP StateInterface类的具体用法?PHP StateInterface怎么用?PHP StateInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StateInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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']);
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:32,代码来源:SiteConfigureForm.php
示例6: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$this->moduleHandler->loadInclude('locale', 'fetch.inc');
$this->moduleHandler->loadInclude('locale', 'bulk.inc');
$langcodes = array_filter($form_state->getValue('langcodes'));
$projects = array_filter($form_state->getValue('projects_update'));
// Set the translation import options. This determines if existing
// translations will be overwritten by imported strings.
$options = _locale_translation_default_update_options();
// If the status was updated recently we can immediately start fetching the
// translation updates. If the status is expired we clear it an run a batch to
// update the status and then fetch the translation updates.
$last_checked = $this->state->get('locale.translation_last_checked');
if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
locale_translation_clear_status();
$batch = locale_translation_batch_update_build(array(), $langcodes, $options);
batch_set($batch);
} else {
// Set a batch to download and import translations.
$batch = locale_translation_batch_fetch_build($projects, $langcodes, $options);
batch_set($batch);
// Set a batch to update configuration as well.
if ($batch = locale_config_batch_update_components($options, $langcodes)) {
batch_set($batch);
}
}
}
开发者ID:komejo,项目名称:article-test,代码行数:30,代码来源:TranslationStatusForm.php
示例7: 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
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$key = $input->getArgument('key');
if ($key) {
$io->info($key);
$io->writeln(Yaml::encode($this->state->get($key)));
return 0;
}
$tableHeader = [$this->trans('commands.state.debug.messages.key')];
$keyStoreStates = array_keys($this->keyValue->get('state')->getAll());
$io->table($tableHeader, $keyStoreStates);
return 0;
}
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:17,代码来源:DebugCommand.php
示例19: dump
/**
* Dumps a set of routes to the router table in the database.
*
* Available options:
* - provider: The route grouping that is being dumped. All existing
* routes with this provider will be deleted on dump.
* - base_class: The base class name.
*
* @param array $options
* An array of options.
*/
public function dump(array $options = array())
{
// Convert all of the routes into database records.
// Accumulate the menu masks on top of any we found before.
$masks = array_flip($this->state->get('routing.menu_masks.' . $this->tableName, array()));
// Delete any old records first, then insert the new ones. That avoids
// stale data. The transaction makes it atomic to avoid unstable router
// states due to random failures.
$transaction = $this->connection->startTransaction();
try {
// We don't use truncate, because it is not guaranteed to be transaction
// safe.
try {
$this->connection->delete($this->tableName)->execute();
} catch (\Exception $e) {
$this->ensureTableExists();
}
// Split the routes into chunks to avoid big INSERT queries.
$route_chunks = array_chunk($this->routes->all(), 50, TRUE);
foreach ($route_chunks as $routes) {
$insert = $this->connection->insert($this->tableName)->fields(array('name', 'fit', 'path', 'pattern_outline', 'number_parts', 'route'));
$names = array();
foreach ($routes as $name => $route) {
/** @var \Symfony\Component\Routing\Route $route */
$route->setOption('compiler_class', '\\Drupal\\Core\\Routing\\RouteCompiler');
/** @var \Drupal\Core\Routing\CompiledRoute $compiled */
$compiled = $route->compile();
// The fit value is a binary number which has 1 at every fixed path
// position and 0 where there is a wildcard. We keep track of all such
// patterns that exist so that we can minimize the number of path
// patterns we need to check in the RouteProvider.
$masks[$compiled->getFit()] = 1;
$names[] = $name;
$values = array('name' => $name, 'fit' => $compiled->getFit(), 'path' => $route->getPath(), 'pattern_outline' => $compiled->getPatternOutline(), 'number_parts' => $compiled->getNumParts(), 'route' => serialize($route));
$insert->values($values);
}
// Insert all new routes.
$insert->execute();
}
} catch (\Exception $e) {
$transaction->rollback();
watchdog_exception('Routing', $e);
throw $e;
}
// Sort the masks so they are in order of descending fit.
$masks = array_keys($masks);
rsort($masks);
$this->state->set('routing.menu_masks.' . $this->tableName, $masks);
$this->routes = NULL;
}
开发者ID:318io,项目名称:318-io,代码行数:61,代码来源:MatcherDumper.php
示例20: 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());
}
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:18,代码来源:ThemeInfoTest.php
注:本文中的Drupal\Core\State\StateInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论