all contrib module security updates done
This commit is contained in:
@@ -37,6 +37,15 @@ function title_module_implements_alter(&$implementations, $hook) {
|
||||
$implementations['title'] = $group;
|
||||
break;
|
||||
|
||||
// The following hook implementations should be executed after
|
||||
// entity_translation.
|
||||
case 'entity_load':
|
||||
if (isset($implementations['entity_translation'])) {
|
||||
$length = array_search('entity_translation', array_keys($implementations)) + 1;
|
||||
$implementations = array_merge(array_slice($implementations, 0, $length, TRUE), array('title' => $group), array_slice($implementations, $length, count($implementations) - 1, TRUE));
|
||||
}
|
||||
break;
|
||||
|
||||
// Normally Title needs to act as first module to perform synchronization.
|
||||
default:
|
||||
$implementations = array('title' => $group) + $implementations;
|
||||
@@ -88,7 +97,7 @@ function title_entity_info_alter(&$info) {
|
||||
* @param $entity_type
|
||||
* The name of the entity type.
|
||||
* @param $legacy_field
|
||||
* (Otional) The legacy field name to be replaced.
|
||||
* (Optional) The legacy field name to be replaced.
|
||||
*/
|
||||
function title_field_replacement_info($entity_type, $legacy_field = NULL) {
|
||||
$info = entity_get_info($entity_type);
|
||||
@@ -99,23 +108,12 @@ function title_field_replacement_info($entity_type, $legacy_field = NULL) {
|
||||
if (isset($legacy_field)) {
|
||||
return isset($info['field replacement'][$legacy_field]) ? $info['field replacement'][$legacy_field] : FALSE;
|
||||
}
|
||||
else {
|
||||
return $info['field replacement'];
|
||||
}
|
||||
|
||||
return $info['field replacement'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an entity label value.
|
||||
*
|
||||
* @param $entity
|
||||
* The entity whose label has to be displayed.
|
||||
* @param $type
|
||||
* The name of the entity type.
|
||||
* @param $langcode
|
||||
* (Optional) The language the entity label has to be displayed in.
|
||||
*
|
||||
* @return
|
||||
* The entity label as a string value.
|
||||
* Implements callback_entity_info_label().
|
||||
*/
|
||||
function title_entity_label($entity, $type, $langcode = NULL) {
|
||||
$entity_info = entity_get_info($type);
|
||||
@@ -127,15 +125,15 @@ function title_entity_label($entity, $type, $langcode = NULL) {
|
||||
if (title_field_replacement_enabled($type, $bundle, $legacy_field)) {
|
||||
$langcode = field_language($type, $entity, $info['field']['field_name'], $langcode);
|
||||
$values = $info['callbacks']['sync_get']($type, $entity, $legacy_field, $info, $langcode);
|
||||
return $values[$legacy_field];
|
||||
return isset($values[$legacy_field]) ? $values[$legacy_field] : $entity->{$legacy_field};
|
||||
}
|
||||
|
||||
if (isset($entity_info['label fallback']['title']) && function_exists($entity_info['label fallback']['title'])) {
|
||||
$label = $entity_info['label fallback']['title']($entity, $type, $langcode);
|
||||
return isset($label) ? $label : $entity->{$legacy_field};
|
||||
}
|
||||
// Otherwise if we have a fallback defined we use the original label callback.
|
||||
elseif (isset($entity_info['label fallback']['title']) && function_exists($entity_info['label fallback']['title'])) {
|
||||
return $entity_info['label fallback']['title']($entity, $type, $langcode);
|
||||
}
|
||||
else {
|
||||
return (property_exists($entity, $legacy_field)) ? $entity->{$legacy_field} : NULL;
|
||||
}
|
||||
return property_exists($entity, $legacy_field) ? $entity->{$legacy_field} : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +183,7 @@ function title_field_attach_update($entity_type, $entity) {
|
||||
// Reset the field_attach_presave static cache so that subsequent saves work
|
||||
// correctly.
|
||||
$sync = &drupal_static('title_field_attach_presave', array());
|
||||
list($id, , ) = entity_extract_ids($entity_type, $entity);
|
||||
list($id, ,) = entity_extract_ids($entity_type, $entity);
|
||||
unset($sync[$entity_type][$id]);
|
||||
|
||||
// Immediately after saving the entity we need to ensure that the legacy field
|
||||
@@ -203,7 +201,10 @@ function title_field_attach_update($entity_type, $entity) {
|
||||
* @see title_entity_load()
|
||||
*/
|
||||
function title_field_attach_load($entity_type, $entities, $age, $options) {
|
||||
// @todo: Do we need to handle revisions here?
|
||||
// Allow values to re-sync when field_attach_load_revision() is called.
|
||||
if ($age == FIELD_LOAD_REVISION) {
|
||||
title_entity_sync_static_reset($entity_type, array_keys($entities));
|
||||
}
|
||||
title_entity_load($entities, $entity_type);
|
||||
}
|
||||
|
||||
@@ -215,9 +216,23 @@ function title_field_attach_load($entity_type, $entities, $age, $options) {
|
||||
* replaced fields.
|
||||
*/
|
||||
function title_entity_load($entities, $type) {
|
||||
// Load entity translations otherwise field language will not be computed
|
||||
// correctly.
|
||||
if (module_exists('entity_translation')) {
|
||||
module_invoke('entity_translation', 'entity_load', $entities, $type);
|
||||
}
|
||||
foreach ($entities as &$entity) {
|
||||
// Synchronize values from the regular field unless we are intializing it.
|
||||
title_entity_sync($type, $entity, NULL, !empty($GLOBALS['title_field_replacement_init']));
|
||||
// When the node is not being edited, the language must be set to current
|
||||
// entity language if set, otherwise NULL.
|
||||
$language = NULL;
|
||||
if ((preg_match('/node\/\d+\/edit/', current_path()) == 0)
|
||||
&& (preg_match('/node\/\d+$/', current_path()) == 0)) {
|
||||
if (!empty($entity->language)) {
|
||||
$language = $entity->language;
|
||||
}
|
||||
}
|
||||
title_entity_sync($type, $entity, $language, !empty($GLOBALS['title_field_replacement_init']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,20 +249,10 @@ function title_entitycache_load($entities, $type) {
|
||||
/**
|
||||
* Implements hook_entitycache_reset().
|
||||
*
|
||||
* If the entity cache is reseted the field sync has to be done again.
|
||||
* When the entity cache is reset the field sync has to be done again.
|
||||
*/
|
||||
function title_entitycache_reset($ids, $entity_type) {
|
||||
$sync = &drupal_static('title_entity_sync', array());
|
||||
if (!empty($ids)) {
|
||||
// Clear specific ids.
|
||||
foreach ($ids as $id) {
|
||||
unset($sync[$entity_type][$id]);
|
||||
}
|
||||
}
|
||||
elseif (!empty($sync[$entity_type])) {
|
||||
// Reset cache for an entity_type.
|
||||
$sync[$entity_type] = array();
|
||||
}
|
||||
title_entity_sync_static_reset($entity_type, $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,10 +321,9 @@ function title_field_replacement_toggle($entity_type, $bundle, $legacy_field) {
|
||||
field_create_instance($info['instance']);
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
field_delete_instance($instance);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
field_delete_instance($instance);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -450,6 +454,26 @@ function title_entity_sync($entity_type, &$entity, $langcode = NULL, $set = FALS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the list of entities whose fields have already been synchronized.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The name of the entity type.
|
||||
* @param $entity_ids
|
||||
* Either an array of entity IDs to reset or NULL to reset all.
|
||||
*/
|
||||
function title_entity_sync_static_reset($entity_type, $entity_ids = NULL) {
|
||||
$sync = &drupal_static('title_entity_sync', array());
|
||||
if (is_array($entity_ids)) {
|
||||
foreach ($entity_ids as $id) {
|
||||
unset($sync[$entity_type][$id]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
unset($sync[$entity_type]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronize a single legacy field with its regular field value.
|
||||
*
|
||||
@@ -459,8 +483,6 @@ function title_entity_sync($entity_type, &$entity, $langcode = NULL, $set = FALS
|
||||
* The entity to work with.
|
||||
* @param $legacy_field
|
||||
* The name of the legacy field to be replaced.
|
||||
* @param $field_name
|
||||
* The regular field to use as source value.
|
||||
* @param $info
|
||||
* Field replacement information for the given entity.
|
||||
* @param $langcode
|
||||
@@ -474,8 +496,16 @@ function title_field_sync_get($entity_type, $entity, $legacy_field, $info, $lang
|
||||
$langcode = field_language($entity_type, $entity, $info['field']['field_name'], $langcode);
|
||||
$values = $info['callbacks']['sync_get']($entity_type, $entity, $legacy_field, $info, $langcode);
|
||||
foreach ($values as $name => $value) {
|
||||
$entity->{$name} = $value;
|
||||
if ($value !== NULL) {
|
||||
$entity->{$name} = $value;
|
||||
}
|
||||
}
|
||||
// Save the actual language used to LEGACY_FIELD_NAME_language.
|
||||
$entity->{$legacy_field . '_language'} = $langcode;
|
||||
// Ensure we do not pollute field language static cache.
|
||||
$cache = &drupal_static('field_language');
|
||||
list($id, ,) = entity_extract_ids($entity_type, $entity);
|
||||
unset($cache[$entity_type][$id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,8 +518,6 @@ function title_field_sync_get($entity_type, $entity, $legacy_field, $info, $lang
|
||||
* The entity to work with.
|
||||
* @param $legacy_field
|
||||
* The name of the legacy field to be replaced.
|
||||
* @param $field_name
|
||||
* The regular field to use as source value.
|
||||
* @param $info
|
||||
* Field replacement information for the given entity.
|
||||
* @param $langcode
|
||||
@@ -564,13 +592,20 @@ function title_field_attach_form($entity_type, $entity, &$form, &$form_state, $l
|
||||
$fr_info = title_field_replacement_info($entity_type);
|
||||
|
||||
if (!empty($fr_info)) {
|
||||
foreach ($fr_info as $legacy_field => $info) {
|
||||
foreach ($fr_info as $legacy_field => $info) {
|
||||
if (isset($form[$legacy_field]) && title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {
|
||||
// Inherit the access from the title widget, so that other modules
|
||||
// restricting access to it keep working.
|
||||
if (isset($form[$legacy_field]['#access'])) {
|
||||
$replaced = isset($form[$legacy_field]['#field_replacement']) ?
|
||||
$form[$legacy_field]['#field_replacement'] : FALSE;
|
||||
if (!$replaced && isset($form[$legacy_field]['#access'])) {
|
||||
$form[$info['field']['field_name']]['#access'] = $form[$legacy_field]['#access'];
|
||||
}
|
||||
|
||||
// Add class from legacy field so behaviors can still be applied on
|
||||
// title widget.
|
||||
$form[$info['field']['field_name']]['#attributes']['class'] = array('form-item-' . $legacy_field);
|
||||
|
||||
// Restrict access to the legacy field form element and mark it as
|
||||
// replaced.
|
||||
$form[$legacy_field]['#access'] = FALSE;
|
||||
@@ -600,8 +635,6 @@ function title_field_attach_submit($entity_type, $entity, $form, &$form_state) {
|
||||
|
||||
foreach ($fr_info as $legacy_field => $info) {
|
||||
if (!empty($form[$legacy_field]['#field_replacement'])) {
|
||||
$field_name = $info['field']['field_name'];
|
||||
|
||||
// Give a chance to operate on submitted values either.
|
||||
if (!empty($info['callbacks']['submit'])) {
|
||||
$info['callbacks']['submit']($entity_type, $entity, $legacy_field, $info, $langcode, $values);
|
||||
@@ -617,7 +650,7 @@ function title_field_attach_submit($entity_type, $entity, $form, &$form_state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_menu().
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function title_menu() {
|
||||
$items = array();
|
||||
@@ -643,7 +676,7 @@ function title_menu() {
|
||||
);
|
||||
|
||||
$path = "$path/fields/replace/%";
|
||||
$field_arg = count(explode('/', $path)) - 1;
|
||||
$field_arg = substr_count($path, '/');
|
||||
$items[$path] = array(
|
||||
'load arguments' => array(),
|
||||
'title' => 'Replace fields',
|
||||
@@ -674,7 +707,7 @@ function title_menu() {
|
||||
function title_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/config/content/title':
|
||||
return '<p>' . t('The settings below allow to configure the <em>default</em> settings to be used when creating new replacing fields. It is even possibile to configure them so that the selected fields are created automatically when a new bundle is created.') . '</p>';
|
||||
return '<p>' . t('The settings below allow to configure the <em>default</em> settings to be used when creating new replacing fields. It is even possible to configure them so that the selected fields are created automatically when a new bundle is created.') . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,7 +722,7 @@ function title_field_extra_fields_alter(&$info) {
|
||||
foreach ($entity_info[$entity_type]['field replacement'] as $field_name => $field_replacement_info) {
|
||||
if (title_field_replacement_enabled($entity_type, $bundle_name, $field_name)) {
|
||||
// Remove the replaced legacy field.
|
||||
unset($info[$entity_type][$bundle_name]['form'][$field_name], $info[$entity_type][$bundle_name]['display'][$field_name]);
|
||||
unset($info[$entity_type][$bundle_name]['form'][$field_name], $info[$entity_type][$bundle_name]['display'][$field_name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -725,7 +758,7 @@ function title_tokens_alter(array &$replacements, array $context) {
|
||||
$fr_info = title_field_replacement_info($entity_type);
|
||||
if ($fr_info && !empty($context['data'][$context['type']])) {
|
||||
$entity = $context['data'][$context['type']];
|
||||
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
$options = $context['options'];
|
||||
|
||||
// Since Title tokens are mostly used in storage contexts we default to
|
||||
@@ -736,16 +769,17 @@ function title_tokens_alter(array &$replacements, array $context) {
|
||||
|
||||
if ($fr_info) {
|
||||
foreach ($fr_info as $legacy_field => $info) {
|
||||
if (title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {
|
||||
if (isset($context['tokens'][$legacy_field])) {
|
||||
$langcode = field_language($entity_type, $entity, $info['field']['field_name'], $langcode);
|
||||
$values = $info['callbacks']['sync_get']($entity_type, $entity, $legacy_field, $info, $langcode);
|
||||
$item = $values[$legacy_field];
|
||||
if (!empty($item)) {
|
||||
if (is_array($item)) {
|
||||
$item = reset($item);
|
||||
}
|
||||
$replacements[$context['tokens'][$legacy_field]] = $item;
|
||||
if (isset($context['tokens'][$legacy_field])
|
||||
&& title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {
|
||||
$langcode = field_language($entity_type, $entity, $info['field']['field_name'], $langcode);
|
||||
$item = $info['callbacks']['sync_get']($entity_type, $entity, $legacy_field, $info, $langcode);
|
||||
if (!empty($item)) {
|
||||
list($value, $format) = array_values($item);
|
||||
if (empty($format)) {
|
||||
$replacements[$context['tokens'][$legacy_field]] = check_plain($value);
|
||||
}
|
||||
else {
|
||||
$replacements[$context['tokens'][$legacy_field]] = check_markup($value, $format, $langcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -810,13 +844,13 @@ function title_field_replacement_is_label($entity_type, $field_name) {
|
||||
/**
|
||||
* Returns the legacy field replaced by the given field name.
|
||||
*
|
||||
* @param $entity_type
|
||||
* @param $entity_type
|
||||
* The name of the entity type.
|
||||
* @param $field_name
|
||||
* The replacing field name.
|
||||
*
|
||||
* @return
|
||||
* The replaced legacy field name or FALSE if none available.
|
||||
* @return
|
||||
* The replaced legacy field name or FALSE if none available.
|
||||
*/
|
||||
function title_field_replacement_get_legacy_field($entity_type, $field_name) {
|
||||
$result = FALSE;
|
||||
@@ -842,7 +876,7 @@ function title_field_replacement_get_legacy_field($entity_type, $field_name) {
|
||||
* @param $bundle
|
||||
* The name of the bundle the instance is attached to.
|
||||
*
|
||||
* @return
|
||||
* @return
|
||||
* The field instance replacing the label or FALSE if none available.
|
||||
*/
|
||||
function title_field_replacement_get_label_field($entity_type, $bundle) {
|
||||
@@ -939,3 +973,65 @@ function title_field_attach_create_bundle($entity_type, $bundle) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_info_alter().
|
||||
*/
|
||||
function title_field_info_alter(&$info) {
|
||||
$supported_types = array('taxonomy_term_reference' => TRUE);
|
||||
foreach ($info as $field_type => &$field_type_info) {
|
||||
if (isset($supported_types[$field_type])) {
|
||||
if (!isset($field_type_info['settings'])) {
|
||||
$field_type_info['settings'] = array();
|
||||
}
|
||||
$field_type_info['settings'] += array('options_list_callback' => 'title_taxonomy_allowed_values');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return taxonomy term values for taxonomy reference fields.
|
||||
*/
|
||||
function title_taxonomy_allowed_values($field) {
|
||||
// Since we call taxonomy_get_tree() with $load_entities = TRUE, there is a
|
||||
// chance that this will trigger theme functions. For this case, we need to
|
||||
// ensure that we are not in the process of theme registry rebuilding.
|
||||
$theme_registry_cache = drupal_static('theme_get_registry');
|
||||
/* @see theme_get_registry() */
|
||||
$theme_registry_is_rebuilding = is_array($theme_registry_cache) &&
|
||||
empty($theme_registry_cache);
|
||||
|
||||
$bundle = !empty($field['settings']['allowed_values'][0]['vocabulary']) ?
|
||||
$field['settings']['allowed_values'][0]['vocabulary'] : NULL;
|
||||
if ($bundle && ($label = title_field_replacement_get_label_field('taxonomy_term', $bundle)) && !$theme_registry_is_rebuilding) {
|
||||
$options = array();
|
||||
foreach ($field['settings']['allowed_values'] as $tree) {
|
||||
$vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary']);
|
||||
if ($vocabulary && ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'], NULL, TRUE))) {
|
||||
foreach ($terms as $term) {
|
||||
$options[$term->tid] = str_repeat('-', $term->depth) . entity_label('taxonomy_term', $term);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
return taxonomy_allowed_values($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_context_converter_alter().
|
||||
*/
|
||||
function title_ctools_context_converter_alter($context, $converter, &$value, &$converter_options) {
|
||||
// This is a temporary fix for https://www.drupal.org/node/2505311.
|
||||
// It fixes a language issue for the pane title containing entity
|
||||
// related keywords.
|
||||
if (isset($context->type[0]) && 0 === strpos($context->type[0], 'entity:') && empty($converter_options['language'])) {
|
||||
$plugin = ctools_get_context($context->plugin);
|
||||
if ($function = ctools_plugin_get_function($plugin, 'convert')) {
|
||||
// Provide "language" option for converter and perform the conversion
|
||||
// again.
|
||||
$converter_options['language'] = $GLOBALS[LANGUAGE_TYPE_CONTENT];
|
||||
$value = $function($context, $converter, $converter_options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user