本文整理汇总了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;
}
}
}
}
示例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']]);
}
示例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);
}
示例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;
}
示例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.');
}
示例6: urlGenerator
protected function urlGenerator()
{
if (!$this->urlGenerator) {
$this->urlGenerator = \Drupal::getContainer()->get('purl.url_generator');
}
return $this->urlGenerator;
}
示例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;
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
}