本文整理汇总了PHP中Drupal::hasService方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::hasService方法的具体用法?PHP Drupal::hasService怎么用?PHP Drupal::hasService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal
的用法示例。
在下文中一共展示了Drupal::hasService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSubscribedEvents
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
// Register this listener for every event that is used by a reaction rule.
$events = [];
$callback = ['onRulesEvent', 100];
// If there is no state service there is nothing we can do here. This static
// method could be called early when the container is built, so the state
// service might no always be available.
if (!\Drupal::hasService('state')) {
return [];
}
// Since we cannot access the reaction rule config storage here we have to
// use the state system to provide registered Rules events. The Reaction
// Rule storage is responsible for keeping the registered events up to date
// in the state system.
// @see \Drupal\rules\Entity\ReactionRuleStorage
$state = \Drupal::state();
$registered_event_names = $state->get('rules.registered_events');
if (!empty($registered_event_names)) {
foreach ($registered_event_names as $event_name) {
$events[$event_name][] = $callback;
}
}
return $events;
}
示例2: testMultiple
/**
* Tests with multiple modules enabled.
*/
public function testMultiple()
{
$this->assertTrue(\Drupal::hasService('service_container_symfony_test_yolo'));
$this->assertFalse(\Drupal::hasService('service_container_symfony_test_yolo1'));
$this->assertTrue(\Drupal::hasService('service_container_symfony_subtest_yolo'));
$this->assertFalse(\Drupal::hasService('service_container_symfony_subtest_yolo1'));
}
示例3: getNumberOfPlurals
/**
* Returns the number of plurals supported by a given language.
*
* See the \Drupal\locale\PluralFormulaInterface::getNumberOfPlurals()
* documentation for details.
*
* @see \Drupal\locale\PluralFormulaInterface::getNumberOfPlurals()
*/
protected function getNumberOfPlurals($langcode = NULL)
{
if (\Drupal::hasService('locale.plural.formula')) {
return \Drupal::service('locale.plural.formula')->getNumberOfPlurals($langcode);
}
// We assume 2 plurals if Locale's services are not available.
return 2;
}
示例4: testServiceProviderRegistrationIntegration
/**
* Tests that module service providers get registered to the DIC.
*
* Also tests that services provided by module service providers get
* registered to the DIC.
*/
public function testServiceProviderRegistrationIntegration()
{
$this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC');
// The event subscriber method in the test class calls drupal_set_message()
// with a message saying it has fired. This will fire on every page request
// so it should show up on the front page.
$this->drupalGet('');
$this->assertText(t('The service_provider_test event subscriber fired!'), 'The service_provider_test event subscriber fired');
}
示例5: testServiceProviderRegistrationDynamic
/**
* Tests that the DIC keeps up with module enable/disable in the same request.
*/
function testServiceProviderRegistrationDynamic()
{
// Uninstall the module and ensure the service provider's service is not registered.
\Drupal::service('module_installer')->uninstall(array('service_provider_test'));
$this->assertFalse(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.');
// Install the module and ensure the service provider's service is registered.
\Drupal::service('module_installer')->install(array('service_provider_test'));
$this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.');
}
示例6: basePath
/**
* Returns the base path for public://.
*
* If we have a setting for the public:// scheme's path, we use that.
* Otherwise we build a reasonable default based on the site.path service if
* it's available, or a default behavior based on the request.
*
* The site path is injectable from the site.path service:
* @code
* $base_path = PublicStream::basePath(\Drupal::service('site.path'));
* @endcode
*
* @param \SplString $site_path
* (optional) The site.path service parameter, which is typically the path
* to sites/ in a Drupal installation. This allows you to inject the site
* path using services from the caller. If omitted, this method will use the
* global service container or the kernel's default behavior to determine
* the site path.
*
* @return string
* The base path for public:// typically sites/default/files.
*/
public static function basePath(\SplString $site_path = NULL)
{
if ($site_path === NULL) {
// Find the site path. Kernel service is not always available at this
// point, but is preferred, when available.
if (\Drupal::hasService('kernel')) {
$site_path = \Drupal::service('site.path');
} else {
// If there is no kernel available yet, we call the static
// findSitePath().
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
}
}
return Settings::get('file_public_path', $site_path . '/files');
}
示例7: testRequestStack
public function testRequestStack()
{
$container = $this->getDrupalContainer();
$this->assertTrue($container->has('request_stack'));
$this->assertTrue(\Drupal::hasService('request_stack'));
/* @var $requestFromThis RequestStack */
$requestFromThis = $container->get('request_stack');
$requestFromThat = \Drupal::service('request_stack');
$requestFromWhat = \Drupal::getContainer()->get('request_stack');
$this->assertSame($requestFromThat, $requestFromThis);
$this->assertSame($requestFromThat, $requestFromWhat);
$current = $requestFromThis->getCurrentRequest();
$master = $requestFromThis->getMasterRequest();
// We are NOT in a subrequest
$this->assertSame($current, $master);
}
示例8: conf_path
function conf_path($require_settings = TRUE, $reset = FALSE, Request $request = NULL)
{
if (!isset($request)) {
if (\Drupal::hasRequest()) {
$request = \Drupal::request();
} else {
$request = Request::createFromGlobals();
}
}
if (\Drupal::hasService('kernel')) {
$site_path = \Drupal::service('kernel')->getSitePath();
}
if (!isset($site_path) || empty($site_path)) {
$site_path = DrupalKernel::findSitePath($request, $require_settings);
}
return $site_path;
}
示例9: createNodeType
/**
* Creates node type with several text fields with different cardinality.
*
* Internally it calls TMGMTEntityTestCaseUtility::attachFields() to create
* and attach fields to newly created bundle. You can than use
* $this->field_names['node']['YOUR_BUNDLE_NAME'] to access them.
*
* @param string $machine_name
* Machine name of the node type.
* @param string $human_name
* Human readable name of the node type.
* @param bool $translation
* TRUE if translation for this enitty type should be enabled.
* pparam bool $attach_fields
* (optional) If fields with the same translatability should automatically
* be attached to the node type.
*/
function createNodeType($machine_name, $human_name, $translation = FALSE, $attach_fields = TRUE)
{
$type = $this->drupalCreateContentType(array('type' => $machine_name, 'name' => $human_name));
// Push in also the body field.
$this->field_names['node'][$machine_name][] = 'body';
if (\Drupal::hasService('content_translation.manager') && $translation) {
$content_translation_manager = \Drupal::service('content_translation.manager');
$content_translation_manager->setEnabled('node', $machine_name, TRUE);
}
$this->applySchemaUpdates();
if ($attach_fields) {
$this->attachFields('node', $machine_name, $translation);
} else {
// Change body field to be translatable.
$body = FieldConfig::loadByName('node', $machine_name, 'body');
$body->setTranslatable(TRUE);
$body->save();
}
}
示例10: testDrupalGetFilename
/**
* Tests that drupal_get_filename() works when the file is not in database.
*/
function testDrupalGetFilename()
{
// drupal_get_profile() is using obtaining the profile from state if the
// install_state global is not set.
global $install_state;
$install_state['parameters']['profile'] = 'testing';
// Assert that the test is meaningful by making sure the keyvalue service
// does not exist.
$this->assertFalse(\Drupal::hasService('keyvalue'), 'The container has no keyvalue service.');
// Retrieving the location of a module.
$this->assertIdentical(drupal_get_filename('module', 'system'), 'core/modules/system/system.info.yml');
// Retrieving the location of a theme.
$this->assertIdentical(drupal_get_filename('theme', 'stark'), 'core/themes/stark/stark.info.yml');
// Retrieving the location of a theme engine.
$this->assertIdentical(drupal_get_filename('theme_engine', 'phptemplate'), 'core/themes/engines/phptemplate/phptemplate.info.yml');
// Retrieving the location of a profile. Profiles are a special case with
// a fixed location and naming.
$this->assertIdentical(drupal_get_filename('profile', 'standard'), 'core/profiles/standard/standard.info.yml');
// Searching for an item that does not exist returns NULL.
$this->assertNull(drupal_get_filename('module', uniqid("", TRUE)), 'Searching for an item that does not exist returns NULL.');
}
示例11: scan
/**
* Discovers available extensions of a given type.
*
* Finds all extensions (modules, themes, etc) that exist on the site. It
* searches in several locations. For instance, to discover all available
* modules:
* @code
* $listing = new ExtensionDiscovery(\Drupal::root());
* $modules = $listing->scan('module');
* @endcode
*
* The following directories will be searched (in the order stated):
* - the core directory; i.e., /core
* - the installation profile directory; e.g., /core/profiles/standard
* - the legacy site-wide directory; i.e., /sites/all
* - the site-wide directory; i.e., /
* - the site-specific directory; e.g., /sites/example.com
*
* The information is returned in an associative array, keyed by the extension
* name (without .info.yml extension). Extensions found later in the search
* will take precedence over extensions found earlier - unless they are not
* compatible with the current version of Drupal core.
*
* @param string $type
* The extension type to search for. One of 'profile', 'module', 'theme', or
* 'theme_engine'.
* @param bool $include_tests
* (optional) Whether to explicitly include or exclude test extensions. By
* default, test extensions are only discovered when in a test environment.
*
* @return \Drupal\Core\Extension\Extension[]
* An associative array of Extension objects, keyed by extension name.
*/
public function scan($type, $include_tests = NULL)
{
// Determine the installation profile directories to scan for extensions,
// unless explicit profile directories have been set. Exclude profiles as we
// cannot have profiles within profiles.
if (!isset($this->profileDirectories) && $type != 'profile') {
$this->setProfileDirectoriesFromSettings();
}
// Search the core directory.
$searchdirs[static::ORIGIN_CORE] = 'core';
// Search the legacy sites/all directory.
$searchdirs[static::ORIGIN_SITES_ALL] = 'sites/all';
// Search for contributed and custom extensions in top-level directories.
// The scan uses a whitelist to limit recursion to the expected extension
// type specific directory names only.
$searchdirs[static::ORIGIN_ROOT] = '';
// Simpletest uses the regular built-in multi-site functionality of Drupal
// for running web tests. As a consequence, extensions of the parent site
// located in a different site-specific directory are not discovered in a
// test site environment, because the site directories are not the same.
// Therefore, add the site directory of the parent site to the search paths,
// so that contained extensions are still discovered.
// @see \Drupal\simpletest\WebTestBase::setUp()
if ($parent_site = Settings::get('test_parent_site')) {
$searchdirs[static::ORIGIN_PARENT_SITE] = $parent_site;
}
// Find the site-specific directory to search. Since we are using this
// method to discover extensions including profiles, we might be doing this
// at install time. Therefore Kernel service is not always available, but is
// preferred.
if (\Drupal::hasService('kernel')) {
$searchdirs[static::ORIGIN_SITE] = \Drupal::service('site.path');
} else {
$searchdirs[static::ORIGIN_SITE] = $this->sitePath ?: DrupalKernel::findSitePath(Request::createFromGlobals());
}
// Unless an explicit value has been passed, manually check whether we are
// in a test environment, in which case test extensions must be included.
// Test extensions can also be included for debugging purposes by setting a
// variable in settings.php.
if (!isset($include_tests)) {
$include_tests = Settings::get('extension_discovery_scan_tests') || drupal_valid_test_ua();
}
$files = array();
foreach ($searchdirs as $dir) {
// Discover all extensions in the directory, unless we did already.
if (!isset(static::$files[$dir][$include_tests])) {
static::$files[$dir][$include_tests] = $this->scanDirectory($dir, $include_tests);
}
// Only return extensions of the requested type.
if (isset(static::$files[$dir][$include_tests][$type])) {
$files += static::$files[$dir][$include_tests][$type];
}
}
// If applicable, filter out extensions that do not belong to the current
// installation profiles.
$files = $this->filterByProfileDirectories($files);
// Sort the discovered extensions by their originating directories.
$origin_weights = array_flip($searchdirs);
$files = $this->sort($files, $origin_weights);
// Process and return the list of extensions keyed by extension name.
return $this->process($files);
}
示例12: testExistence
/**
* Tests that classes, interfaces, functions, etc. still exist.
*
* At the time of the first release of this book, Drupal 8 was still in
* flux. This tests for the existence of Drupal 8 classes, interfaces,
* functions, etc. mentioned in the book. If their names change or they
* vanish, this test will fail and the book can be corrected.
*/
function testExistence()
{
$interfaces = array('\\Drupal\\Core\\Ajax\\CommandInterface', '\\Drupal\\Core\\Block\\BlockPluginInterface', '\\Drupal\\Core\\Cache\\CacheBackendInterface', '\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface', '\\Drupal\\Core\\Datetime\\DateFormatInterface', '\\Drupal\\Core\\DependencyInjection\\ServiceModifierInterface', '\\Drupal\\Core\\Entity\\ContentEntityInterface', '\\Drupal\\Core\\Entity\\EntityInterface', '\\Drupal\\Core\\Entity\\EntityManagerInterface', '\\Drupal\\Core\\Entity\\EntityStorageInterface', '\\Drupal\\Core\\Entity\\EntityTypeInterface', '\\Drupal\\Core\\Entity\\Query\\QueryInterface', '\\Drupal\\Core\\Entity\\Query\\QueryAggregateInterface', '\\Drupal\\Core\\Entity\\EntityStorageInterface', '\\Drupal\\Core\\Extension\\ModuleHandlerInterface', '\\Drupal\\Core\\Field\\FieldItemInterface', '\\Drupal\\Core\\Field\\FieldItemListInterface', '\\Drupal\\Core\\Field\\FieldStorageDefinitionInterface', '\\Drupal\\Core\\Field\\FormatterInterface', '\\Drupal\\Core\\Field\\WidgetInterface', '\\Drupal\\Core\\Form\\FormStateInterface', '\\Drupal\\Core\\Language\\LanguageInterface', '\\Drupal\\Core\\Render\\Element\\FormElementInterface', '\\Drupal\\Core\\Render\\Element\\ElementInterface', '\\Drupal\\Core\\Routing\\RouteMatchInterface', '\\Drupal\\Core\\Session\\AccountInterface', '\\Drupal\\Core\\Session\\AccountProxyInterface', '\\Drupal\\Core\\State\\StateInterface', '\\Symfony\\Component\\DependencyInjection\\ContainerInterface', '\\Symfony\\Component\\EventDispatcher\\EventSubscriberInterface');
foreach ($interfaces as $interface) {
$this->assertTrue(interface_exists($interface), "Interface {$interface} exists");
}
$classes = array('\\Drupal', '\\Drupal\\Component\\Datetime\\DateTimePlus', '\\Drupal\\Component\\Utility\\Unicode', '\\Drupal\\Core\\Access\\AccessResult', '\\Drupal\\Core\\Ajax\\AjaxResponse', '\\Drupal\\Core\\Annotation\\Translation', '\\Drupal\\Core\\Block\\Annotation\\Block', '\\Drupal\\Core\\Block\\BlockBase', '\\Drupal\\Core\\Block\\BlockManager', '\\Drupal\\Core\\Cache\\Cache', '\\Drupal\\Core\\Config\\Config', '\\Drupal\\Core\\Entity\\Annotation\\ConfigEntityType', '\\Drupal\\Core\\Entity\\EntityForm', '\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase', '\\Drupal\\Core\\Config\\Entity\\ConfigEntityListBuilder', '\\Drupal\\Core\\Controller\\ControllerBase', '\\Drupal\\Core\\Database\\Connection', '\\Drupal\\Core\\Database\\Query\\PagerSelectExtender', '\\Drupal\\Core\\Datetime\\Entity\\DateFormat', '\\Drupal\\Core\\Entity\\Annotation\\ContentEntityType', '\\Drupal\\Core\\Entity\\ContentEntityBase', '\\Drupal\\Core\\Entity\\ContentEntityConfirmFormBase', '\\Drupal\\Core\\Entity\\ContentEntityForm', '\\Drupal\\Core\\Field\\FieldItemBase', '\\Drupal\\Core\\Field\\FormatterBase', '\\Drupal\\Core\\Field\\WidgetBase', '\\Drupal\\Core\\Field\\Annotation\\FieldType', '\\Drupal\\Core\\Field\\Annotation\\FieldFormatter', '\\Drupal\\Core\\Field\\Annotation\\FieldWidget', '\\Drupal\\Core\\Form\\ConfigFormBase', '\\Drupal\\Core\\Form\\FormBase', '\\Drupal\\Core\\Language\\Language', '\\Drupal\\Core\\Path\\AliasManager', '\\Drupal\\Core\\Plugin\\DefaultPluginManager', '\\Drupal\\Core\\Render\\Annotation\\FormElement', '\\Drupal\\Core\\Render\\Annotation\\RenderElement', '\\Drupal\\Core\\Render\\Element', '\\Drupal\\Core\\Routing\\RouteSubscriberBase', '\\Drupal\\Core\\Url', '\\Drupal\\Component\\Utility\\SafeMarkup', '\\Drupal\\Tests\\UnitTestCase', '\\Drupal\\block_content\\Plugin\\Block\\BlockContentBlock', '\\Drupal\\migrate\\MigrateExecutable', '\\Drupal\\node\\Form\\NodeTypeDeleteConfirm', '\\Drupal\\simpletest\\WebTestBase', '\\Drupal\\simpletest\\KernelTestBase', '\\Drupal\\system\\DateFormatListBuilder', '\\Drupal\\system\\Form\\DateFormatEditForm', '\\Drupal\\system\\Form\\DateFormatDeleteForm', '\\Drupal\\block\\Controller\\CategoryAutocompleteController', '\\Drupal\\views\\Plugin\\views\\field\\FieldPluginBase', '\\Drupal\\views\\Annotation\\ViewsArgument', '\\Drupal\\views\\Annotation\\ViewsField', '\\Drupal\\views\\Annotation\\ViewsRow', '\\Drupal\\views\\Annotation\\ViewsStyle', '\\Drupal\\views\\Plugin\\views\\field\\FieldPluginBase', '\\Drupal\\views\\Plugin\\views\\row\\RowPluginBase', '\\Drupal\\views\\Plugin\\views\\style\\StylePluginBase', '\\Drupal\\views\\ViewExecutable', '\\Drupal\\views\\Views', '\\Symfony\\Component\\DependencyInjection\\Container', '\\Symfony\\Component\\EventDispatcher\\Event', '\\Symfony\\Component\\HttpFoundation\\Request', '\\Symfony\\Component\\HttpFoundation\\Response', '\\Symfony\\Component\\Routing\\Route', '\\Symfony\\Component\\Routing\\RouteCollection', '\\Symfony\\Component\\Validator\\Constraint');
foreach ($classes as $class) {
$this->assertTrue(class_exists($class), "Class {$class} exists");
}
$traits = array('\\Drupal\\Core\\StringTranslation\\StringTranslationTrait');
foreach ($traits as $trait) {
$this->assertTrue(trait_exists($trait), "Trait {$trait} exists");
}
$methods = array('\\Drupal' => array('config', 'currentUser', 'formBuilder', 'getContainer', 'service', 'l'), '\\Drupal\\Core\\Ajax\\AjaxResponse' => 'addCommand', '\\Drupal\\Core\\Block\\BlockBase' => array('access', 'build'), '\\Drupal\\Core\\Block\\BlockManager' => array('clearCachedDefinitions', 'getSortedDefinitions'), '\\Drupal\\Core\\Cache\\CacheBackendInterface' => array('get', 'invalidate', 'set'), '\\Drupal\\Core\\Config\\Config' => array('get', 'save', 'set'), '\\Drupal\\Core\\Database\\Connection' => 'select', '\\Drupal\\Core\\DependencyInjection\\ServiceModifierInterface' => 'alter', '\\Drupal\\Core\\DrupalKernel' => 'discoverServiceProviders', '\\Drupal\\Core\\Entity\\ContentEntityForm' => array('buildEntity', 'form', 'save', 'validateForm'), '\\Drupal\\Core\\Entity\\ContentEntityInterface' => 'baseFieldDefinitions', '\\Drupal\\Core\\Entity\\Entity' => 'access', '\\Drupal\\Core\\Entity\\EntityForm' => array('form', 'save', 'validateForm'), '\\Drupal\\Core\\Entity\\Query\\QueryInterface' => 'condition', '\\Drupal\\Core\\Field\\FieldItemInterface' => array('propertyDefinitions', 'schema'), '\\Drupal\\Core\\Field\\FormatterInterface' => 'viewElements', '\\Drupal\\Core\\Field\\WidgetInterface' => 'formElement', '\\Drupal\\Core\\Form\\FormBase' => 't', '\\Drupal\\Core\\Form\\FormBuilderInterface' => 'getForm', '\\Drupal\\Core\\Form\\FormStateInterface' => array('get', 'getValues', 'set', 'setErrorByName', 'setRebuild'), '\\Drupal\\Core\\Render\\Element\\ElementInterface' => 'getInfo', '\\Drupal\\Core\\Session\\AccountProxyInterface' => 'hasPermission', '\\Drupal\\block\\BlockListBuilder' => array('buildForm', 'createInstance'), '\\Drupal\\block\\BlockViewBuilder' => 'viewMultiple', '\\Drupal\\block\\Controller\\CategoryAutocompleteController' => 'autocomplete', '\\Symfony\\Component\\DependencyInjection\\ContainerInterface' => 'get', '\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface' => 'dispatch', '\\Symfony\\Component\\EventDispatcher\\EventSubscriberInterface' => 'getSubscribedEvents');
foreach ($methods as $class => $methods) {
if (!is_array($methods)) {
$methods = array($methods);
}
foreach ($methods as $method) {
$this->assertTrue(method_exists($class, $method), "Method {$class}::{$method} exists");
}
}
$functions = array('check_markup', 'check_url', 'db_add_field', 'db_change_field', 'db_create_table', 'db_query', 'db_select', 'drupal_flush_all_caches', 'drupal_render', 't');
foreach ($functions as $function) {
$this->assertTrue(function_exists($function), "Function {$function}() exists");
}
$services = array('cache.default', 'current_user', 'database', 'entity.query', 'entity.manager', 'event_dispatcher', 'path.alias_manager', 'plugin.manager.block', 'string_translation');
foreach ($services as $service) {
$this->assertTrue(\Drupal::hasService($service), "Service {$service} exists");
}
$files = array('core/config/schema/core.data_types.schema.yml', 'core/core.services.yml', 'core/includes/database.inc', 'core/lib/Drupal/Component/Datetime/DateTimePlus.php', 'core/lib/Drupal/Core/Ajax', 'core/modules', 'core/modules/block/block.services.yml', 'core/modules/block/block.routing.yml', 'core/modules/block/block.links.contextual.yml', 'core/modules/filter/filter.permissions.yml', 'core/modules/filter/src/FilterPermissions.php', 'core/modules/system/system.routing.yml', 'core/modules/system/config/schema/system.schema.yml', 'core/modules/taxonomy/taxonomy.routing.yml', 'core/modules/user/user.routing.yml', 'core/modules/user/user.links.action.yml', 'core/modules/user/user.links.task.yml', 'core/modules/views/src/Plugin/views', 'core/modules/views/src/Plugin/views/argument', 'core/modules/views/src/Plugin/views/field', 'core/modules/views/src/Plugin/views/row', 'core/modules/views/src/Plugin/views/style', 'vendor/symfony/dependency-injection/Container.php');
foreach ($files as $file) {
$this->assertTrue(file_exists(DRUPAL_ROOT . '/' . $file), "File {$file} exists");
}
}
示例13: currentUser
/**
* Gets the current active user.
*
* @return \Drupal\Core\Session\AccountInterface
*/
protected function currentUser()
{
if (!$this->currentUser && \Drupal::hasService('current_user')) {
$this->currentUser = \Drupal::currentUser();
}
return $this->currentUser;
}
示例14: currentUser
/**
* Gets the current active user.
*
* @return \Drupal\Core\Session\AccountInterface
*/
protected function currentUser()
{
if (!$this->currentUser) {
if (\Drupal::hasService('current_user')) {
$this->currentUser = \Drupal::currentUser();
} else {
global $user;
$this->currentUser = $user;
}
}
return $this->currentUser;
}
示例15: getPluralIndex
/**
* Gets the plural index through the gettext formula.
*
* @return int
*/
protected function getPluralIndex()
{
// We have to test both if the function and the service exist since in
// certain situations it is possible that locale code might be loaded but
// the service does not exist. For example, where the parent test site has
// locale installed but the child site does not.
// @todo Refactor in https://www.drupal.org/node/2660338 so this code does
// not depend on knowing that the Locale module exists.
if (function_exists('locale_get_plural') && \Drupal::hasService('locale.plural.formula')) {
return locale_get_plural($this->count, $this->getOption('langcode'));
}
return -1;
}