/** * 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; }
/** * {@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; }
/** * 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; }
/** * 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]; }
/** * 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; }
/** * 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; } }
/** * 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]; }
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; }
/** * @static * @return EnvironmentMetaModelFactory */ public static function getInstance() { $instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (!isset($instance)) { $instance = new EnvironmentMetaModelFactory(); } return $instance; }
/** * @static * @return DatasetSourceTypeFactory */ public static function getInstance() { $instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (!isset($instance)) { $instance = new DefaultDatasetSourceTypeFactory(); } return $instance; }
/** * @static * @return DataQueryController */ public static function getInstance() { $instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (!isset($instance)) { $instance = new DataQueryControllerProxy(); } return $instance; }
/** * @static * @return RequestChainFactory */ public static function getInstance() { $instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (!isset($instance)) { $instance = new DefaultRequestChainFactory(); } return $instance; }
/** * @static * @return LogHelper */ protected static function getInstance() { $instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (!isset($instance)) { $instance = new LogHelper(); } return $instance; }
/** * @static * @return DataSourceStructureFactory */ public static function getInstance() { $instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (!isset($instance)) { $instance = new DataSourceManipulationFactory(); } return $instance; }
/** * @static * @return FormulaExpressionLanguageFactory */ public static function getInstance() { $instance = &drupal_static(__CLASS__ . '::' . __FUNCTION__); if (!isset($instance)) { $instance = new DefaultFormulaExpressionLanguageFactory(); } return $instance; }
/** * Implements FacetapiQueryTypeInterface::build(). * * Unlike normal facets, we provide a static list of options. */ public function build() { $facet = $this->adapter->getFacet($this->facet); $search_ids = drupal_static('search_api_facetapi_active_facets', array()); if (empty($search_ids[$facet['name']]) || !search_api_current_search($search_ids[$facet['name']])) { return array(); } $search_id = $search_ids[$facet['name']]; $build = array(); $search = search_api_current_search($search_id); $results = $search[1]; if (!$results['result count']) { return array(); } // Executes query, iterates over results. if (isset($results['search_api_facets']) && isset($results['search_api_facets'][$this->facet['field']])) { $values = $results['search_api_facets'][$this->facet['field']]; $build = date_facets_get_ranges(); $now = $_SERVER['REQUEST_TIME']; // Calculate values by facet. foreach ($values as $value) { $value['filter'] = str_replace('"', '', $value['filter']); $diff = $now - $value['filter']; foreach ($build as $key => $item) { if ($diff < $item['#time_interval']) { $build[$key]['#count'] += $value['count']; } } } } // Unset empty items. foreach ($build as $key => $item) { if ($item['#count'] === NULL) { unset($build[$key]); } } // Gets total number of documents matched in search. $total = $results['result count']; $keys_of_active_facets = array(); // Gets active facets, starts building hierarchy. foreach ($this->adapter->getActiveItems($this->facet) as $key => $item) { // If the item is active, the count is the result set count. $build[$key]['#count'] = $total; $keys_of_active_facets[] = $key; } // If we have active item, unset other items. $settings = $facet->getSettings()->settings; if (isset($settings['operator']) && $settings['operator'] !== FACETAPI_OPERATOR_OR) { if (!empty($keys_of_active_facets)) { foreach ($build as $key => $item) { if (!in_array($key, $keys_of_active_facets)) { unset($build[$key]); } } } } return $build; }
protected function getRequestId() { $requestId = &drupal_static(__CLASS__ . '::requestId'); if (!isset($requestId)) { $sequenceName = NameSpaceHelper::addNameSpace(get_class($this), 'requestId'); $requestId = Sequence::getNextSequenceValue($sequenceName); } return $requestId; }
/** * Returns the parsed HTTP Authorization request header as an array. * * @see DrupalClient::getServerAuthentication(). * @return array * The authentication header */ public function getRestOAuthHeader() { $header =& drupal_static(__FUNCTION__); if (isset($header)) { return $header; } $header = DrupalClient::getServerAuthentication(); return $header; }
/** * @param int $id * * @return bool */ public static function entityIdExists($id) { $cache =& drupal_static(__METHOD__, []); if (!isset($cache[static::ENTITY_TYPE][$id])) { $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', static::ENTITY_TYPE)->propertyCondition('id', $id)->execute(); $cache[static::ENTITY_TYPE][$id] = !empty($result[static::ENTITY_TYPE]); } return $cache[static::ENTITY_TYPE][$id]; }
/** * {@inheritdoc} */ public function build() { $id = $this->getDerivativeId(); $data = drupal_static('ds_block_region'); if (!empty($data[$id])) { return array('#markup' => drupal_render_children($data[$id])); } else { return array(); } }
/** * Returns a list of supported widgets. */ public static function supportedWidgets() { $widgets =& drupal_static(__FUNCTION__); if (!isset($widgets)) { $widgets = array('file_generic', 'image_image'); \Drupal::moduleHandler()->alter('imce_supported_widgets', $widgets); $widgets = array_unique($widgets); } return $widgets; }
/** * {@inheritdoc} * * Allows per bundle load by title. */ public static function loadMultipleByTitle($title) { $cache =& drupal_static(self::CACHE_KEY_TITLE, []); if (!isset($cache[static::BUNDLE][$title])) { $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', static::ENTITY_TYPE)->entityCondition('bundle', static::BUNDLE)->propertyCondition('title', $title)->execute(); $cache[static::BUNDLE][$title] = !empty($result[static::ENTITY_TYPE]) ? array_keys($result[static::ENTITY_TYPE]) : []; } return static::getWrappers($cache[static::BUNDLE][$title]); }
/** * @param string $name * * @return static[] */ public static function loadMultipleByName($name) { $cache =& drupal_static(static::CACHE_KEY_NAME, []); if (!isset($cache[static::ENTITY_TYPE][$name])) { $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', static::ENTITY_TYPE)->propertyCondition(static::PROPERTY_NAME, $name)->execute(); $cache[static::ENTITY_TYPE][$name] = !empty($result[static::ENTITY_TYPE]) ? array_keys($result[static::ENTITY_TYPE]) : []; } return static::getWrappers($cache[static::ENTITY_TYPE][$name]); }
/** * Displays a node revision. * * @param int $node_revision * The node revision ID. * * @return array * An array suitable for drupal_render(). */ public function revisionShow($node_revision) { /** @var NodeInterface $node */ $node = $this->entityTypeManager()->getStorage('node')->loadRevision($node_revision); // Determine view mode. $view_mode = \Drupal::config('ds_extras.settings')->get('override_node_revision_view_mode'); drupal_static('ds_view_mode', $view_mode); $page = node_view($node, $view_mode); unset($page['nodes'][$node->id()]['#cache']); return $page; }
/** * Returns available entity types. * * @return array * A list of entity types keyed by machine name => label. */ public function getEntityTypeOptions() { $entity_type_options =& drupal_static(__METHOD__); if (empty($entity_type_options)) { $info = entity_get_info(); foreach ($info as $entity_type => $entity_type_info) { $entity_type_options[$entity_type] = $entity_type_info['label']; } } return $entity_type_options; }
/** * Quick function to dpm only one call from a loop etc. */ function dpm_once($input, $name = NULL, $type = 'status') { $backtrace = debug_backtrace(); $caller = array_shift($backtrace); $executed =& drupal_static(__FUNCTION__ . $caller['file'] . $caller['line'], FALSE); if (!$executed) { $executed = TRUE; if (function_exists('dpm')) { dpm($input, $name, $type); } } }
/** * Load all custom menu data. * * @return * Array of custom menu data. */ function menu_load_all() { $custom_menus =& drupal_static(__FUNCTION__); if (!isset($custom_menus)) { if ($cached = cache_get('menu_custom', 'cache_menu')) { $custom_menus = $cached->data; } else { $custom_menus = db_query('SELECT * FROM {menu_custom}')->fetchAllAssoc('menu_name', PDO::FETCH_ASSOC); cache_set('menu_custom', $custom_menus, 'cache_menu'); } } return $custom_menus; }
public function log($level, &$message) { if ($message instanceof StatementLogMessage) { $statementLogMessage = $message; $statements = &drupal_static(__CLASS__ . '::statements'); if (is_array($statementLogMessage->statement)) { ArrayHelper::merge($statements, $statementLogMessage->statement); } else { $statements[$statementLogMessage->type][] = $statementLogMessage->statement; } } }
/** * Implements hook_users_export_row_alter(). * * Modify the contents of an exported row * * @param array &$row * @param int $uid * * @return NULL */ function hook_core_users_export_row_alter(&$row, $uid) { $names =& drupal_static(__FUNCTION__, array()); if (empty($names)) { // Add in the first and last name of the user $query = db_select('field_data_field_first_name', 'f'); $names['first'] = $query->fields('f', array('entity_id', 'field_first_name_value'))->execute()->fetchAllAssoc('entity_id'); $query = db_select('field_data_field_last_name', 'l'); $names['last'] = $query->fields('l', array('entity_id', 'field_last_name_value'))->execute()->fetchAllAssoc('entity_id'); } $row['first_name'] = empty($names['first'][$uid]->field_first_name_value) ? '' : $names['first'][$uid]->field_first_name_value; $row['last_name'] = empty($names['last'][$uid]->field_last_name_value) ? '' : $names['last'][$uid]->field_last_name_value; }
/** * Get the path of the vsite which the vocab belong. * * @param $tid * The term ID. * * @return * The path of the vsite. */ function os_taxonomy_vsite_path($tid) { $term = taxonomy_term_load($tid); $purls =& drupal_static(__FUNCTION__, array()); if (in_array($term->vid, $purls)) { // We already found purl for this vocab. Return the purl from the static // cache. return $purls[$term->vid]; } $relation = og_vocab_relation_get($term->vid); $vsite = vsite_get_vsite($relation->gid); $purls[$term->vid] = $vsite->group->purl; return $vsite->group->purl; }