more module updates

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 18:02:17 +02:00
parent 37fbabab56
commit 7c85261e56
100 changed files with 6518 additions and 913 deletions

View File

@@ -218,6 +218,9 @@ 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.
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']));
@@ -487,8 +490,14 @@ 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;
}
}
// 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]);
}
}
@@ -584,6 +593,11 @@ function title_field_attach_form($entity_type, $entity, &$form, &$form_state, $l
if (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;
@@ -952,3 +966,38 @@ 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) {
$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))) {
$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);
}