本文整理汇总了PHP中Drupal\Core\State\StateInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP StateInterface::get方法的具体用法?PHP StateInterface::get怎么用?PHP StateInterface::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\State\StateInterface
的用法示例。
在下文中一共展示了StateInterface::get方法的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);
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$config = $this->config('system.maintenance');
$form['maintenance_mode'] = array('#type' => 'checkbox', '#title' => t('Put site into maintenance mode'), '#default_value' => $this->state->get('system.maintenance_mode'), '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" <a href=":permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href=":user-login">user login</a> page.', array(':permissions-url' => $this->url('user.admin_permissions'), ':user-login' => $this->url('user.login'))));
$form['maintenance_mode_message'] = array('#type' => 'textarea', '#title' => t('Message to display when in maintenance mode'), '#default_value' => $config->get('message'));
return parent::buildForm($form, $form_state);
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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)]);
}
示例6: 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;
}
}
}
}
}
示例7: get
/**
* Gets the private key.
*
* @return string
* The private key.
*/
public function get()
{
if (!($key = $this->state->get('system.private_key'))) {
$key = $this->create();
$this->set($key);
}
return $key;
}
示例8: processInbound
/**
* {@inheritdoc}
*/
public function processInbound($path, Request $request)
{
if ($this->state->get('update_script_test_broken_inbound', FALSE)) {
throw new \RuntimeException();
} else {
return $path;
}
}
示例9: 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;
}
示例10: 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);
}
}
}
示例11: onRequest
/**
* Loads all non-admin routes right before the actual page is rendered.
*
* @param \Symfony\Component\HttpKernel\Event\KernelEvent $event
* The event to process.
*/
public function onRequest(KernelEvent $event)
{
// Only preload on normal HTML pages, as they will display menu links.
if ($this->routeProvider instanceof PreloadableRouteProviderInterface && $event->getRequest()->getRequestFormat() == 'html') {
if ($routes = $this->state->get('routing.non_admin_routes', [])) {
// Preload all the non-admin routes at once.
$this->routeProvider->preLoadRoutes($routes);
}
}
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}