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


PHP Drupal::request方法代码示例

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


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

示例1: testEmbedDialog

 /**
  * Test the WYSIWYG embed modal.
  */
 public function testEmbedDialog()
 {
     // Use the modal to embed into a page.
     $this->drupalGet('node/add/page');
     $this->find('.cke_button__video_embed')->click();
     $this->assertSession()->assertWaitOnAjaxRequest();
     // Assert all the form fields appear on the modal.
     $this->assertSession()->pageTextContains('Autoplay');
     $this->assertSession()->pageTextContains('Responsive Video');
     $this->assertSession()->pageTextContains('Width');
     $this->assertSession()->pageTextContains('Height');
     $this->assertSession()->pageTextContains('Video URL');
     // Attempt to submit the modal with no values.
     $this->find('input[name="video_url"]')->setValue('');
     $this->find('button.form-submit')->click();
     $this->assertSession()->assertWaitOnAjaxRequest();
     $this->assertSession()->pageTextContains('Video URL field is required.');
     // Submit the form with an invalid video URL.
     $this->find('input[name="video_url"]')->setValue('http://example.com/');
     $this->find('button.form-submit')->click();
     $this->assertSession()->assertWaitOnAjaxRequest();
     $this->assertSession()->pageTextContains('Could not find a video provider to handle the given URL.');
     $this->assertContains('http://example.com/', $this->getSession()->getPage()->getHtml());
     // Submit a valid URL.
     $this->find('input[name="video_url"]')->setValue('https://www.youtube.com/watch?v=iaf3Sl2r3jE&t=1553s');
     $this->find('button.form-submit')->click();
     $this->assertSession()->assertWaitOnAjaxRequest();
     // View the source of the ckeditor and find the output.
     $this->find('.cke_button__source_label')->click();
     $base_path = \Drupal::request()->getBasePath();
     $this->assertEquals('<p>{"preview_thumbnail":"' . rtrim($base_path, '/') . '/' . $this->publicFilesDirectory . '/styles/video_embed_wysiwyg_preview/public/video_thumbnails/iaf3Sl2r3jE.jpg","video_url":"https://www.youtube.com/watch?v=iaf3Sl2r3jE&amp;t=1553s","settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"settings_summary":["Embedded Video (Responsive, autoplaying)."]}</p>', trim($this->getSession()->getPage()->find('css', '.cke_source')->getValue()));
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:35,代码来源:EmbedDialogTest.php

示例2: access

 /**
  * Access callback for json() callback.
  */
 public function access()
 {
     $request = \Drupal::request();
     $nonce = $request->get('nonce', FALSE);
     $connector_config = $this->config('acquia_connector.settings');
     // If we don't have all the query params, leave now.
     if (!$nonce) {
         return AccessResultForbidden::forbidden();
     }
     $sub_data = $connector_config->get('subscription_data');
     $sub_uuid = $this->getIdFromSub($sub_data);
     if (!empty($sub_uuid)) {
         $expected_hash = hash('sha1', "{$sub_uuid}:{$nonce}");
         // If the generated hash matches the hash from $_GET['key'], we're good.
         if ($request->get('key', FALSE) === $expected_hash) {
             return AccessResultAllowed::allowed();
         }
     }
     // Log the request if validation failed and debug is enabled.
     if ($connector_config->get('debug')) {
         $info = array('sub_data' => $sub_data, 'sub_uuid_from_data' => $sub_uuid, 'expected_hash' => $expected_hash, 'get' => $request->query->all(), 'server' => $request->server->all(), 'request' => $request->request->all());
         \Drupal::logger('acquia_agent')->notice('Site status request: @data', array('@data' => var_export($info, TRUE)));
     }
     return AccessResultForbidden::forbidden();
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:28,代码来源:StatusController.php

示例3: installIntegration

 public function installIntegration($forumDirectoryPath)
 {
     try {
         //Using SMF native functions
         $smfSSI = DRUPAL_ROOT . '/' . $forumDirectoryPath . '/SSI.php';
         if (file_exists($smfSSI)) {
             require_once $smfSSI;
             add_integration_function('integrate_pre_include', DRUPAL_ROOT . '/' . drupal_get_path('module', 'smfbridge') . '/src/Smf/Hooks.php');
             add_integration_function('integrate_actions', 'Drupal\\smfbridge\\Smf\\Hooks::actions', TRUE);
             add_integration_function('integrate_menu_buttons', 'Drupal\\smfbridge\\Smf\\Hooks::smfMenuButtons', TRUE);
             //Use database driven sessions - on
             $this->updateSmfSettingsValues('databaseSession_enable', '1');
             /**
              * @var \Drupal\Core\Session\SessionConfiguration $sessionConfiguration
              */
             $sessionConfiguration = \Drupal::service('session_configuration');
             $options = $sessionConfiguration->getOptions(\Drupal::request());
             $this->updateSmfSettingsValues('databaseSession_lifetime', $options['gc_maxlifetime']);
         } else {
             throw new \Exception(t('Can\'t forum/SSI.php. Please, place SMF sources into DRUPAL_ROOT/forum folder.'));
         }
         return TRUE;
     } catch (\Exception $e) {
         $errorMsg = t('Error while enabling smfbridge. @message', ['@message' => $e->getMessage()]);
         \Drupal::logger('smfbridge')->error($errorMsg);
         drupal_set_message($errorMsg, 'error');
         return FALSE;
     }
 }
开发者ID:DimDev,项目名称:smfbridge,代码行数:29,代码来源:Settings.php

示例4: prepareComponent

 /**
  * {inheritdoc}
  */
 protected function prepareComponent($node, $component)
 {
     /** @var \Drupal\webform\ComponentInterface $loaded_component */
     $loaded_component = $this->componentManager->createInstance($component);
     $loaded_component->setConfiguration(['type' => \Drupal::request()->query->get('type'), 'pid' => \Drupal::request()->query->get('pid'), 'weight' => \Drupal::request()->query->get('weight'), 'required' => \Drupal::request()->query->get('required'), 'name' => \Drupal::request()->query->get('name')]);
     return $loaded_component;
 }
开发者ID:Progressable,项目名称:openway8,代码行数:10,代码来源:WebformComponentAddForm.php

示例5: preprocessVariables

 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables)
 {
     $breadcrumb =& $variables['breadcrumb'];
     // Determine if breadcrumbs should be displayed.
     $breadcrumb_visibility = $this->theme->getSetting('breadcrumb');
     if ($breadcrumb_visibility == 0 || $breadcrumb_visibility == 2 && \Drupal::service('router.admin_context')->isAdminRoute() || empty($breadcrumb)) {
         $breadcrumb = [];
         return;
     }
     // Optionally get rid of the homepage link.
     $show_breadcrumb_home = $this->theme->getSetting('breadcrumb_home');
     if (!$show_breadcrumb_home) {
         array_shift($breadcrumb);
     }
     if ($this->theme->getSetting('breadcrumb_title') && !empty($breadcrumb)) {
         $request = \Drupal::request();
         $route_match = \Drupal::routeMatch();
         $page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
         if (!empty($page_title)) {
             $breadcrumb[] = ['text' => $page_title, 'attributes' => new Attribute(['class' => ['active']])];
             // Add cache context based on url.
             $variables->addCacheContexts(['url']);
         }
     }
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:28,代码来源:Breadcrumb.php

示例6: actions

  /**
   * {@inheritdoc}
   */
  public function actions(array $form, FormStateInterface $form_state) {
    $actions = parent::actions($form, $form_state);

    if ($this->entity->isNew()) {
      $actions['submit']['#value'] = $this->t('Create Flagging');
    }
    else {
      $actions['submit']['#value'] = $this->t('Update Flagging');
    }

    // Customize the delete link.
    if (isset($actions['delete'])) {
      // @todo Why does the access call always fail?
      unset($actions['delete']['#access']);

      $actions['delete']['#title'] = $this->t('Delete Flagging');

      // Build the delete url from route. We need to build this manually
      // otherwise Drupal will try to build the flagging entity's delete-form
      // link. Since that route doesn't use the flagging ID, Drupal can't build
      // the link for us.
      $route_params = [
        'flag' => $this->entity->getFlagId(),
        'entity_id' => $this->entity->getFlaggableId(),
        'destination' => \Drupal::request()->get('destination'),
      ];
      $url = Url::fromRoute('flag.confirm_unflag', $route_params);

      $actions['delete']['#url'] = $url;
    }

    return $actions;
  }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:36,代码来源:FlaggingForm.php

示例7: __construct

 /**
  * Overrides MollomDrupalTest::__construct().
  */
 public function __construct(ConfigFactory $config_factory, ClientInterface $http_client)
 {
     // Replace server/endpoint with our local fake server.
     $server = \Drupal::request()->getHttpHost() . '/mollom-test/rest';
     $this->server = $server;
     parent::__construct($config_factory, $http_client);
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:10,代码来源:DrupalTestLocalClient.php

示例8: checkAccess

 /**
  * {@inheritdoc}
  *
  * When the $operation is 'add' then the $entity is of type 'profile_type',
  * otherwise $entity is of type 'profile'.
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     $account = $this->prepareUser($account);
     $user_page = \Drupal::request()->attributes->get('user');
     // Some times, operation edit is called update.
     // Use edit in any case.
     if ($operation == 'update') {
         $operation = 'edit';
     }
     // Check that if profile type has require roles, the user the profile is
     // being added to has any of the required roles.
     if ($entity->getEntityTypeId() == 'profile') {
         $profile_roles = ProfileType::load($entity->bundle())->getRoles();
         $user_roles = $entity->getOwner()->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     } elseif ($entity->getEntityTypeId() == 'profile_type') {
         $profile_roles = $entity->getRoles();
         $user_roles = User::load($user_page->id())->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     }
     if ($account->hasPermission('bypass profile access')) {
         return AccessResult::allowed()->cachePerPermissions();
     } elseif ($operation == 'add' && ($user_page->id() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->id() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->id() . ' profile')) || $operation != 'add' && ($entity->getOwnerId() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->getType() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->getType() . ' profile'))) {
         return AccessResult::allowed()->cachePerPermissions();
     } else {
         return AccessResult::forbidden()->cachePerPermissions();
     }
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:38,代码来源:ProfileAccessControlHandler.php

示例9: content

 public function content()
 {
     $lat = \Drupal::request()->get("lat");
     $lon = \Drupal::request()->get("lon");
     $json = $this->get_weather($lat, $lon);
     return new JsonResponse($json);
 }
开发者ID:pdostal,项目名称:drupal-course,代码行数:7,代码来源:Html5weatherController.php

示例10: testRaceCondition

 /**
  * Tests the behavior of the theme registry class.
  */
 function testRaceCondition()
 {
     // The theme registry is not marked as persistable in case we don't have a
     // proper request.
     \Drupal::request()->setMethod('GET');
     $cid = 'test_theme_registry';
     // Directly instantiate the theme registry, this will cause a base cache
     // entry to be written in __construct().
     $cache = \Drupal::cache();
     $lock_backend = \Drupal::lock();
     $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded());
     $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.');
     // Trigger a cache miss for an offset.
     $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry.');
     // This will cause the ThemeRegistry class to write an updated version of
     // the cache entry when it is destroyed, usually at the end of the request.
     // Before that happens, manually delete the cache entry we created earlier
     // so that the new entry is written from scratch.
     \Drupal::cache()->delete($cid);
     // Destroy the class so that it triggers a cache write for the offset.
     $registry->destruct();
     $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.');
     // Create a new instance of the class. Confirm that both the offset
     // requested previously, and one that has not yet been requested are both
     // available.
     $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded());
     $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry');
     $this->assertTrue($registry->get('theme_test_template_test_2'), 'Offset was returned correctly from the theme registry');
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:32,代码来源:RegistryTest.php

示例11: testHttpsConnection

 /**
  * Returns success only if this page is being accessed by HTTPS.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  *
  * @return \Symfony\Component\HttpFoundation\Response|array
  *   A \Symfony\Component\HttpFoundation\Response object or render array.
  */
 public function testHttpsConnection(Request $request)
 {
     if (\Drupal::request()->isSecure()) {
         return new Response($this->t('HTTPS works!'), 200);
     }
     return new Response($this->t('HTTPS doesn\'t work'), 404);
 }
开发者ID:badjava,项目名称:securepages,代码行数:16,代码来源:SecurePagesController.php

示例12: __construct

 /**
  * Constructs a ThemeRegistry object.
  *
  * @param string $cid
  *   The cid for the array being cached.
  * @param \Drupal\Core\Cache\CacheBackendInterface $cache
  *   The cache backend.
  * @param \Drupal\Core\Lock\LockBackendInterface $lock
  *   The lock backend.
  * @param array $tags
  *   (optional) The tags to specify for the cache item.
  * @param bool $modules_loaded
  *   Whether all modules have already been loaded.
  */
 function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, $tags = array(), $modules_loaded = FALSE)
 {
     $this->cid = $cid;
     $this->cache = $cache;
     $this->lock = $lock;
     $this->tags = $tags;
     $this->persistable = $modules_loaded && \Drupal::hasRequest() && \Drupal::request()->isMethod('GET');
     // @todo: Implement lazyload.
     $this->cacheLoaded = TRUE;
     if ($this->persistable && ($cached = $this->cache->get($this->cid))) {
         $this->storage = $cached->data;
     } else {
         // If there is no runtime cache stored, fetch the full theme registry,
         // but then initialize each value to NULL. This allows offsetExists()
         // to function correctly on non-registered theme hooks without triggering
         // a call to resolveCacheMiss().
         $this->storage = $this->initializeRegistry();
         foreach (array_keys($this->storage) as $key) {
             $this->persist($key);
         }
         // RegistryTest::testRaceCondition() ensures that the cache entry is
         // written on the initial construction of the theme registry.
         $this->updateCache();
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:39,代码来源:ThemeRegistry.php

示例13: checkForUserPasswordExpiration

 /**
  * Event callback to look for users expired password
  */
 public function checkForUserPasswordExpiration(GetResponseEvent $event)
 {
     $account = \Drupal::currentUser();
     // There needs to be an explicit check for non-anonymous or else
     // this will be tripped and a forced redirect will occur.
     if ($account->id() > 0) {
         /** @var $user \Drupal\user\UserInterface */
         $user = entity_load('user', $account->id());
         $route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
         ///system/ajax
         $ignored_routes = array('entity.user.edit_form', 'system.ajax', 'user.logout');
         $user_expired = FALSE;
         if ($user->get('field_password_expiration')->get(0)) {
             $user_expired = $user->get('field_password_expiration')->get(0)->getValue();
             $user_expired = $user_expired['value'];
         }
         //TODO - Consider excluding admins here
         if ($user_expired and !in_array($route_name, $ignored_routes)) {
             $url = new Url('entity.user.edit_form', array('user' => $user->id()));
             $url = $url->toString();
             $event->setResponse(new RedirectResponse($url));
             drupal_set_message('Your password has expired, please update it', 'error');
         }
     }
 }
开发者ID:nerdstein,项目名称:password_policy,代码行数:28,代码来源:PasswordPolicyEventSubscriber.php

示例14: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $context = NULL)
 {
     if ($context == 'form') {
         $this->mode = \Drupal::request()->get('form_mode_name');
     } else {
         $this->mode = \Drupal::request()->get('view_mode_name');
     }
     if (empty($this->mode)) {
         $this->mode = 'default';
     }
     if (!$form_state->get('context')) {
         $form_state->set('context', $context);
     }
     if (!$form_state->get('entity_type_id')) {
         $form_state->set('entity_type_id', $entity_type_id);
     }
     if (!$form_state->get('bundle')) {
         $form_state->set('bundle', $bundle);
     }
     if (!$form_state->get('step')) {
         $form_state->set('step', 'formatter');
     }
     $this->entityTypeId = $form_state->get('entity_type_id');
     $this->bundle = $form_state->get('bundle');
     $this->context = $form_state->get('context');
     $this->currentStep = $form_state->get('step');
     if ($this->currentStep == 'formatter') {
         $this->buildFormatterSelectionForm($form, $form_state);
     } else {
         $this->buildConfigurationForm($form, $form_state);
     }
     return $form;
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:36,代码来源:FieldGroupAddForm.php

示例15: getRulesUiHandler

 /**
  * Gets the rules UI handler of the current route.
  *
  * @return \Drupal\rules\Ui\RulesUiHandlerInterface|null
  *   The handler, or NULL if this is no rules_ui enabled route.
  */
 public function getRulesUiHandler()
 {
     if (!isset($this->rulesUiHandler)) {
         $this->rulesUiHandler = \Drupal::request()->attributes->get('rules_ui_handler');
     }
     return $this->rulesUiHandler;
 }
开发者ID:Progressable,项目名称:openway8,代码行数:13,代码来源:RulesUiHandlerTrait.php


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