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


PHP Drupal::getContainer方法代码示例

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


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

示例1: jireRest

 public function jireRest(Request $request)
 {
     try {
         //$jira_rest = \Drupal::service('jira_rest.jira_rest_service');
         $container = \Drupal::getContainer();
         $jira = JiraRestController::create($container);
         $author_name = $jira->config('jira_rest.settings')->get('jira_rest.username');
         $interval = "-2d";
         $res = $jira->jira_rest_searchissue("updated >= " . $interval . " AND assignee in (" . $author_name . ")");
     } catch (JiraRestException $e) {
         $responce['messages'][] = $e->getMessage();
     }
     $responce = array();
     $interval = abs(intval($interval));
     $sub_days = "{$interval} days";
     $date = date_create();
     $toDate = date_format($date, 'Y-m-d');
     date_sub($date, date_interval_create_from_date_string($sub_days));
     $fromDate = date_format($date, 'Y-m-d');
     foreach ($res->issues as $issue) {
         $worklog = $jira->jira_rest_get_worklog($issue->key);
         foreach ($worklog->worklogs as $entry) {
             $shortDate = substr($entry->started, 0, 10);
             # keep a worklog entry on $key item,
             # iff within the search time period
             if ($entry->author->name == $author_name && $shortDate >= $fromDate && $shortDate <= $toDate) {
                 $responce[$issue->key] += $entry->timeSpentSeconds;
             }
         }
     }
 }
开发者ID:lokeoke,项目名称:d8intranet,代码行数:31,代码来源:JiraRestWorkLogController.php

示例2: testPathHooks

 /**
  * Test system_path_*() correctly clears caches.
  */
 public function testPathHooks()
 {
     $source = '/' . $this->randomMachineName();
     $alias = '/' . $this->randomMachineName();
     // Check system_path_insert();
     $alias_manager = $this->prophesize(AliasManagerInterface::class);
     $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
     $alias_manager->cacheClear($source)->shouldBeCalledTimes(1);
     \Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
     $alias_storage = \Drupal::service('path.alias_storage');
     $alias_storage->save($source, $alias);
     $new_source = '/' . $this->randomMachineName();
     $path = $alias_storage->load(['source' => $source]);
     // Check system_path_update();
     $alias_manager = $this->prophesize(AliasManagerInterface::class);
     $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(2);
     $alias_manager->cacheClear($source)->shouldBeCalledTimes(1);
     $alias_manager->cacheClear($new_source)->shouldBeCalledTimes(1);
     \Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
     $alias_storage->save($new_source, $alias, LanguageInterface::LANGCODE_NOT_SPECIFIED, $path['pid']);
     // Check system_path_delete();
     $alias_manager = $this->prophesize(AliasManagerInterface::class);
     $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
     $alias_manager->cacheClear($new_source)->shouldBeCalledTimes(1);
     \Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
     $alias_storage->delete(['pid' => $path['pid']]);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:PathHooksTest.php

示例3: assertPageRenderHookExceptions

 /**
  * Asserts whether expected exceptions are thrown for invalid hook implementations.
  *
  * @param string $module
  *   The module whose invalid logic in its hooks to enable.
  * @param string $hook
  *   The page render hook to assert expected exceptions for.
  */
 function assertPageRenderHookExceptions($module, $hook)
 {
     $html_renderer = \Drupal::getContainer()->get('main_content_renderer.html');
     // Assert a valid hook implementation doesn't trigger an exception.
     $page = [];
     $html_renderer->invokePageAttachmentHooks($page);
     // Assert that hooks can set cache tags.
     $this->assertEqual($page['#cache']['tags'], ['example']);
     $this->assertEqual($page['#cache']['contexts'], ['user.permissions']);
     // Assert an invalid hook implementation doesn't trigger an exception.
     \Drupal::state()->set($module . '.' . $hook . '.descendant_attached', TRUE);
     $assertion = $hook . '() implementation that sets #attached on a descendant triggers an exception';
     $page = [];
     try {
         $html_renderer->invokePageAttachmentHooks($page);
         $this->error($assertion);
     } catch (\LogicException $e) {
         $this->pass($assertion);
         $this->assertEqual($e->getMessage(), 'Only #attached, #post_render_cache and #cache may be set in ' . $hook . '().');
     }
     \Drupal::state()->set('bc_test.' . $hook . '.descendant_attached', FALSE);
     // Assert an invalid hook implementation doesn't trigger an exception.
     \Drupal::state()->set('bc_test.' . $hook . '.render_array', TRUE);
     $assertion = $hook . '() implementation that sets a child render array triggers an exception';
     $page = [];
     try {
         $html_renderer->invokePageAttachmentHooks($page);
         $this->error($assertion);
     } catch (\LogicException $e) {
         $this->pass($assertion);
         $this->assertEqual($e->getMessage(), 'Only #attached, #post_render_cache and #cache may be set in ' . $hook . '().');
     }
     \Drupal::state()->set($module . '.' . $hook . '.render_array', FALSE);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:42,代码来源:PageRenderTest.php

示例4: route_alter_variants

 /**
  * @implement route_alter_variants
  * @fast
  */
 static function route_alter_variants()
 {
     $alters = [];
     static::$container = \Drupal::getContainer();
     foreach (static::getFiles('/^.+\\.routing\\.yml/i') as $file) {
         $info = static::yamlDecode($file)['alter_variants'] ?? [];
         $alters = NestedArray::mergeDeep($alters, $info);
     }
     foreach ($alters as $name => $variants) {
         foreach ($variants as $k => $variant) {
             if (isset($variant['cache'])) {
                 $variant['controller'] = new CacheController($variant['cache'], $variant['controller']);
                 unset($variant['cache']);
             }
             if (isset($variant['redirect'])) {
                 $variant['controller'] = new RedirectController($variant['redirect']);
                 unset($variant['redirect']);
             }
             if (isset($variant['error'])) {
                 $variant['controller'] = new ErrorController($variant['error']);
                 unset($variant['error']);
             }
             if (is_string($variant)) {
                 $variant = ['controller' => $variant];
             }
             if (isset($variant['controller']) && is_string($variant['controller']) && strpos($variant['controller'], '::') !== FALSE) {
                 $variant['controller'] = explode('::', $variant['controller']);
             }
             static::appliesRuleDetect($variant);
             $variants[$k] = $variant;
         }
         $alters[$name] = static::sortByPriority($variants);
     }
     return $alters;
 }
开发者ID:d-f-d,项目名称:d_submodules,代码行数:39,代码来源:RouteAlterLoader.php

示例5: testTableSortInit

 /**
  * Tests tablesort_init().
  */
 function testTableSortInit()
 {
     // Test simple table headers.
     $headers = array('foo', 'bar', 'baz');
     // Reset $request->query to prevent parameters from Simpletest and Batch API
     // ending up in $ts['query'].
     $expected_ts = array('name' => 'foo', 'sql' => '', 'sort' => 'asc', 'query' => array());
     $request = Request::createFromGlobals();
     $request->query->replace(array());
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers sorted correctly.');
     // Test with simple table headers plus $_GET parameters that should _not_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => 'bar'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.');
     // Test with simple table headers plus $_GET parameters that _should_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('sort' => 'DESC', 'alpha' => 'beta'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $expected_ts['sort'] = 'desc';
     $expected_ts['query'] = array('alpha' => 'beta');
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Simple table headers plus $_GET parameters sorted correctly.');
     // Test complex table headers.
     $headers = array('foo', array('data' => '1', 'field' => 'one', 'sort' => 'asc', 'colspan' => 1), array('data' => '2', 'field' => 'two', 'sort' => 'desc'));
     // Reset $_GET from previous assertion.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => '2'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $expected_ts = array('name' => '2', 'sql' => 'two', 'sort' => 'desc', 'query' => array());
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers sorted correctly.');
     // Test complex table headers plus $_GET parameters that should _not_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => 'bar'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $ts = tablesort_init($headers);
     $expected_ts = array('name' => '1', 'sql' => 'one', 'sort' => 'asc', 'query' => array());
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers plus non-overriding $_GET parameters sorted correctly.');
     // Test complex table headers plus $_GET parameters that _should_
     // override the default.
     $request = Request::createFromGlobals();
     $request->query->replace(array('order' => '1', 'sort' => 'ASC', 'alpha' => 'beta'));
     \Drupal::getContainer()->get('request_stack')->push($request);
     $expected_ts = array('name' => '1', 'sql' => 'one', 'sort' => 'asc', 'query' => array('alpha' => 'beta'));
     $ts = tablesort_init($headers);
     $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => Html::escape(var_export($ts, TRUE)))));
     $this->assertEqual($ts, $expected_ts, 'Complex table headers plus $_GET parameters sorted correctly.');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:63,代码来源:TableSortExtenderUnitTest.php

示例6: urlGenerator

 protected function urlGenerator()
 {
     if (!$this->urlGenerator) {
         $this->urlGenerator = \Drupal::getContainer()->get('purl.url_generator');
     }
     return $this->urlGenerator;
 }
开发者ID:activelamp,项目名称:purl-d8,代码行数:7,代码来源:Url.php

示例7: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $contactForms = \Drupal::getContainer()->get('entity.query')->get('contact_form')->execute();
     $element = [];
     $element['value'] = array('#type' => 'select', '#title' => t('Contact Form that should be rendered'), '#options' => $contactForms, '#description' => t('Select the Contact Form that should be rendered.'), '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL);
     return $element;
 }
开发者ID:WondrousLLC,项目名称:contact_form_field,代码行数:10,代码来源:ContactFormFieldWidget.php

示例8: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $modules[] = 'service_container_annotation_discovery_test';
     $modules[] = 'service_container_annotation_discovery_subtest';
     parent::setUp($modules);
     $this->container = \Drupal::getContainer();
 }
开发者ID:ps-intelegencia-analytics,项目名称:testRepo,代码行数:10,代码来源:ServiceContainerAnnotationDiscoveryIntegrationTest.php

示例9: add_logger

 function add_logger()
 {
     // If we're running on Drupal 8 or later, we provide a logger which will send
     // output to drush_log(). This should catch every message logged through every
     // channel.
     \Drupal::getContainer()->get('logger.factory')->addLogger(new \Drush\Log\DrushLog());
 }
开发者ID:nuwud,项目名称:drush,代码行数:7,代码来源:DrupalBoot8.php

示例10: replaceValues

 /**
  * @param $values
  * @return string
  */
 private function replaceValues($values)
 {
     /** TODO inject renderer service */
     $renderer = \Drupal::getContainer()->get('renderer');
     $elements = ['#theme' => 'gist_embed_filter', '#gist_data' => $values];
     return $renderer->render($elements);
 }
开发者ID:jmolivas,项目名称:gist_embed,代码行数:11,代码来源:GistEmbedFilter.php

示例11: serializeRdfEntity

 /**
  * Converts an rdf entity id into its serialized rdf form.
  */
 protected function serializeRdfEntity($entity_id, $format = 'turtle')
 {
     $query = "DESCRIBE <{$entity_id}>";
     $sparql = \Drupal::getContainer()->get('sparql_endpoint');
     /** @var \EasyRdf\Graph $graph */
     $graph = $sparql->query($query);
     return $graph->serialise($format);
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:11,代码来源:RdfExportController.php

示例12: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = [];
     $build['password_forgotten_block'] = \Drupal::getContainer()->get('form_builder')->getForm('Drupal\\user\\Form\\UserPasswordForm');
     $build['WTF'] = ['#markup' => '<div class="js-wtf"></div>'];
     $build['WTF']['#attached']['library'][] = 'user_blocks/userpopups_lapompa';
     return $build;
 }
开发者ID:hacktm15,项目名称:lapompa,代码行数:11,代码来源:PasswordForgottenBlock.php

示例13: __wakeup

 /**
  * {@inheritdoc}
  */
 public function __wakeup()
 {
     $container = \Drupal::getContainer();
     foreach ($this->_serviceIds as $key => $service_id) {
         $this->{$key} = $container->get($service_id);
     }
     $this->_serviceIds = array();
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:11,代码来源:DependencySerializationTrait.php

示例14: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->setUpExampleStructure();
     \Drupal::getContainer()->get('search_api.index_task_manager')->addItemsAll(Index::load($this->indexId));
     $this->insertExampleContent();
     $this->indexItems($this->indexId);
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:11,代码来源:ViewsTest.php

示例15: getTempStoreCarburant

 /**
  * @return Drupal\taxonomy\Entity\Term|null
  */
 private static function getTempStoreCarburant()
 {
     $temp_store = \Drupal::getContainer()->get('user.private_tempstore')->get();
     $id = $temp_store->get('tip_carburant');
     if ($id) {
         return Term::load($id);
     }
 }
开发者ID:hacktm15,项目名称:lapompa,代码行数:11,代码来源:TipCarburant.php


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