本文整理汇总了PHP中drupal_static函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_static函数的具体用法?PHP drupal_static怎么用?PHP drupal_static使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_static函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addMessage
/**
* Adds a log entry to a global log (per-request).
*
* The Mollom client may perform multiple requests, and the client is able to
* recover from certain errors. The details of each request are important for
* support and debugging, but individual log messages for each request are too
* much and would confuse users, especially when (false-)errors appear in
* between.
*
* Therefore, the Mollom module collects all messages generated by the module
* integration code as well as by the Mollom client class within a single
* request, and only logs a single message when the request ends.
*
* This collection expects that at least one entry is logged that contains the
* primary log message and its severity.
*
* @param array $entry
* (optional) An associative array describing the entry to add to the log.
* If supplied, the special keys 'message' and 'arguments' are taken over as
* primary log message. All other key/value pairs will be appended to the
* resulting log message, whereas the key denotes a label/heading and the
* value is var_export()ed afterwards, unless NULL.
* @param int $severity
* (optional) The severity of the primary log message, as per RFC 3164.
* Possible values are WATCHDOG_ERROR, WATCHDOG_WARNING, etc. See watchdog()
* for details. Defaults to WATCHDOG_NOTICE when a 'message' is passed.
* @param bool $reset
* (optional) Whether to empty the log and return its contents.
*
* @return array
* An associative array containing the log:
* - message: The primary log message.
* - arguments: An array of placeholder token replacement values for
* _mollom_format_string().
* - severity: The severity of the primary log message.
* - entries: A list of all $entry items that have been passed in.
*
* @see mollom_exit()
*/
public static function addMessage(array $entry = NULL, $severity = NULL, $reset = FALSE)
{
// Start with debug severity level.
$log =& drupal_static(__FUNCTION__, array());
if ($reset) {
$return = $log;
$log = array();
return $return;
}
if (!isset($entry)) {
return $log;
}
// Take over the primary message.
// Only the module integration code sets a message.
if (isset($entry['message'])) {
$log['message'] = $entry['message'];
$log['arguments'] = isset($entry['arguments']) ? $entry['arguments'] : array();
// Default to notice severity for module messages.
if (!isset($severity)) {
$severity = RfcLogLevel::NOTICE;
}
}
if (!isset($log['severity'])) {
$log['severity'] = RfcLogLevel::DEBUG;
}
// Update severity, if the entry is more severe than existing.
// Fail-over handling for requests is encapsulated in the Mollom class, which
// only passes the final severity already.
if (isset($severity) && $severity < $log['severity']) {
$log['severity'] = $severity;
}
$log['entries'][] = $entry;
return $log;
}
示例2: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$view = $this->entity;
$form['#prefix'] = '<div id="views-preview-wrapper" class="views-admin clearfix">';
$form['#suffix'] = '</div>';
$form['#id'] = 'views-ui-preview-form';
// Reset the cache of IDs. Drupal rather aggressively prevents ID
// duplication but this causes it to remember IDs that are no longer even
// being used.
$seen_ids_init =& drupal_static('drupal_html_id:init');
$seen_ids_init = array();
$form_state['no_cache'] = TRUE;
$form['controls']['#attributes'] = array('class' => array('clearfix'));
// Add a checkbox controlling whether or not this display auto-previews.
$form['controls']['live_preview'] = array('#type' => 'checkbox', '#id' => 'edit-displays-live-preview', '#title' => $this->t('Auto preview'), '#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'));
// Add the arguments textfield
$form['controls']['view_args'] = array('#type' => 'textfield', '#title' => $this->t('Preview with contextual filters:'), '#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')), '#id' => 'preview-args');
$args = array();
if (!empty($form_state['values']['view_args'])) {
$args = explode('/', $form_state['values']['view_args']);
}
if (!empty($form_state['show_preview']) || !empty($form_state['input']['js'])) {
$form['preview'] = array('#weight' => 110, '#theme_wrappers' => array('container'), '#attributes' => array('id' => 'views-live-preview'), '#markup' => $view->renderPreview($this->displayID, $args));
}
$uri = $view->urlInfo('preview-form');
$uri->setRouteParameter('display_id', $this->displayID);
$form['#action'] = $uri->toString();
return $form;
}
示例3: getDataTypeInfo
/**
* Retrieves Solr-specific data for available data types.
*
* Returns the data type information for both the default Search API data types
* and custom data types defined by hook_search_api_data_type_info(). Names for
* default data types are not included, since they are not relevant to the Solr
* service class.
*
* We're adding some extra Solr field information for the default search api
* data types (as well as on behalf of a couple contrib field types). The
* extra information we're adding is documented in
* search_api_solr_hook_search_api_data_type_info(). You can use the same
* additional keys in hook_search_api_data_type_info() to support custom
* dynamic fields in your indexes with Solr.
*
* @param string|null $type
* (optional) A specific type for which the information should be returned.
* Defaults to returning all information.
*
* @return array|null
* If $type was given, information about that type or NULL if it is unknown.
* Otherwise, an array of all types. The format in both cases is the same as
* for search_api_get_data_type_info().
*
* @see search_api_get_data_type_info()
* @see search_api_solr_hook_search_api_data_type_info()
*/
public static function getDataTypeInfo($type = NULL)
{
$types =& drupal_static(__FUNCTION__);
if (!isset($types)) {
// Grab the stock search_api data types.
/** @var \Drupal\search_api\DataType\DataTypePluginManager $data_type_service */
$data_type_service = \Drupal::service('plugin.manager.search_api.data_type');
$types = $data_type_service->getDefinitions();
// Add our extras for the default search api fields.
$types = NestedArray::mergeDeep($types, array('text' => array('prefix' => 't'), 'string' => array('prefix' => 's'), 'integer' => array('prefix' => 'i'), 'decimal' => array('prefix' => 'f'), 'date' => array('prefix' => 'd'), 'duration' => array('prefix' => 'i'), 'boolean' => array('prefix' => 'b'), 'uri' => array('prefix' => 's'), 'tokens' => array('prefix' => 't')));
// Extra data type info.
$extra_types_info = array('location' => array('prefix' => 'loc'), 'geohash' => array('prefix' => 'geo'));
// For the extra types, only add our extra info if it's already been defined.
foreach ($extra_types_info as $key => $info) {
if (array_key_exists($key, $types)) {
// Merge our extras into the data type info
$types[$key] += $info;
}
}
}
// Return the info.
if (isset($type)) {
return isset($types[$type]) ? $types[$type] : NULL;
}
return $types;
}
示例4: isSimple
/**
* Determines if a string of text is considered "simple".
*
* @param string $string
* The string of text to check "simple" criteria on.
* @param int|FALSE $length
* The length of characters used to determine whether or not $string is
* considered "simple". Set explicitly to FALSE to disable this criteria.
* @param array|FALSE $allowed_tags
* An array of allowed tag elements. Set explicitly to FALSE to disable this
* criteria.
* @param bool $html
* A variable, passed by reference, that indicates whether or not the
* string contains HTML.
*
* @return bool
* Returns TRUE if the $string is considered "simple", FALSE otherwise.
*/
public static function isSimple($string, $length = 250, $allowed_tags = NULL, &$html = FALSE)
{
// Typecast to a string (if an object).
$string_clone = (string) $string;
// Use the advanced drupal_static() pattern.
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['strings'] =& drupal_static(__METHOD__);
}
$strings =& $drupal_static_fast['strings'];
if (!isset($strings[$string_clone])) {
$plain_string = strip_tags($string_clone);
$simple = TRUE;
if ($allowed_tags !== FALSE) {
$filtered_string = Xss::filter($string_clone, $allowed_tags);
$html = $filtered_string !== $plain_string;
$simple = $simple && $string_clone === $filtered_string;
}
if ($length !== FALSE) {
$simple = $simple && strlen($plain_string) <= intval($length);
}
$strings[$string_clone] = $simple;
}
return $strings[$string_clone];
}
示例5: userProfile
/**
* Returns imce configuration profile for a user.
*/
public static function userProfile(AccountProxyInterface $user = NULL, $scheme = NULL)
{
$profiles =& drupal_static(__METHOD__, array());
$user = $user ?: \Drupal::currentUser();
$scheme = isset($scheme) ? $scheme : file_default_scheme();
$profile =& $profiles[$user->id()][$scheme];
if (!isset($profile)) {
// Check stream wrapper
if ($wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme)) {
$imce_settings = \Drupal::config('imce.settings');
$roles_profiles = $imce_settings->get('roles_profiles', array());
$user_roles = array_flip($user->getRoles());
$storage = \Drupal::entityTypeManager()->getStorage('imce_profile');
foreach ($roles_profiles as $rid => $profiles) {
if (isset($user_roles[$rid]) && !empty($profiles[$scheme])) {
if ($profile = $storage->load($profiles[$scheme])) {
return $profile;
}
}
}
}
$profile = FALSE;
}
return $profile;
}
示例6: grantPermission
/**
* Grant permissions to a specific role, if it exists.
*
* @param string $role
* Role machine name.
* @param string $permission
* Permission machine name.
* @param string $module
* Module name.
*
* @return bool
* TRUE if operation was successful, FALSE otherwise.
*/
public function grantPermission($role, $permission, $module = NULL)
{
$permission_rebuilt =& drupal_static(__CLASS__ . ':' . __FUNCTION__);
if (!$permission_rebuilt) {
// Make sure the list of available node types is up to date.
node_types_rebuild();
// Reset hook_permission() cached information.
module_implements('permission', FALSE, TRUE);
$permission_rebuilt = TRUE;
}
$permissions = is_array($permission) ? $permission : array($permission);
$role_object = user_role_load_by_name($role);
if ($role_object) {
// Use code from user_role_grant_permissions() in order to be able
// to force medule field in special cases.
$modules = user_permission_get_modules();
// Grant new permissions for the role.
foreach ($permissions as $name) {
$modules[$name] = isset($modules[$name]) ? $modules[$name] : $module;
db_merge('role_permission')->key(array('rid' => $role_object->rid, 'permission' => $name))->fields(array('module' => $modules[$name]))->execute();
}
// Clear the user access cache.
drupal_static_reset('user_access');
drupal_static_reset('user_role_permissions');
return TRUE;
} else {
return FALSE;
}
}
示例7: user
/**
* User object.
*
* @return \Drupal\moodle\Sql\User
*/
public function user()
{
// Static cache of already retrieved user data.
$data =& drupal_static(__METHOD__, array());
$user_cid = "moodle-user:{$this->user->id()}";
// If we do not have this user id in the static cache, check {cache_data}.
if (!isset($data[$user_cid])) {
$cache = $this->cacheBackend->get($user_cid);
if ($cache && $cache->data && isset($cache->data[$user_cid])) {
$data[$user_cid] = $cache->data[$user_cid];
}
}
// If nothing in the cache then retrieve it from the database.
if (!isset($data[$user_cid])) {
$user = new User();
$this->query();
$this->addFields();
$statement = $this->query->execute();
$statement->setFetchMode(\PDO::FETCH_INTO, $user);
$data[$user_cid] = $statement->fetch();
// Store the results for a day.
$this->cacheBackend->set($user_cid, $data, REQUEST_TIME + 86400);
}
return $data[$user_cid];
}
示例8: marketplace_reset_settings
function marketplace_reset_settings()
{
global $theme_key;
variable_del('theme_' . $theme_key . '_settings');
variable_del('theme_settings');
$cache =& drupal_static('theme_get_setting', array());
$cache[$theme_key] = NULL;
}
示例9: getInstance
/**
* @static
* @return EnvironmentMetaModelFactory
*/
public static function getInstance() {
$instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__);
if (!isset($instance)) {
$instance = new EnvironmentMetaModelFactory();
}
return $instance;
}
示例10: getInstance
/**
* @static
* @return DatasetSourceTypeFactory
*/
public static function getInstance() {
$instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__);
if (!isset($instance)) {
$instance = new DefaultDatasetSourceTypeFactory();
}
return $instance;
}
示例11: getInstance
/**
* @static
* @return DataQueryController
*/
public static function getInstance() {
$instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__);
if (!isset($instance)) {
$instance = new DataQueryControllerProxy();
}
return $instance;
}
示例12: getInstance
/**
* @static
* @return RequestChainFactory
*/
public static function getInstance() {
$instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__);
if (!isset($instance)) {
$instance = new DefaultRequestChainFactory();
}
return $instance;
}
示例13: getInstance
/**
* @static
* @return LogHelper
*/
protected static function getInstance() {
$instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__);
if (!isset($instance)) {
$instance = new LogHelper();
}
return $instance;
}
示例14: getInstance
/**
* @static
* @return DataSourceStructureFactory
*/
public static function getInstance() {
$instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__);
if (!isset($instance)) {
$instance = new DataSourceManipulationFactory();
}
return $instance;
}
示例15: getInstance
/**
* @static
* @return FormulaExpressionLanguageFactory
*/
public static function getInstance() {
$instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__);
if (!isset($instance)) {
$instance = new DefaultFormulaExpressionLanguageFactory();
}
return $instance;
}
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:12,代码来源:FormulaExpressionLanguageFactory.php