uppdated modules
This commit is contained in:
@@ -220,13 +220,15 @@ function entityreference_field_validate($entity_type, $entity, $field, $instance
|
||||
if ($ids) {
|
||||
$valid_ids = entityreference_get_selection_handler($field, $instance, $entity_type, $entity)->validateReferencableEntities(array_keys($ids));
|
||||
|
||||
$invalid_entities = array_diff_key($ids, array_flip($valid_ids));
|
||||
if ($invalid_entities) {
|
||||
foreach ($invalid_entities as $id => $delta) {
|
||||
$errors[$field['field_name']][$langcode][$delta][] = array(
|
||||
'error' => 'entityreference_invalid_entity',
|
||||
'message' => t('The referenced entity (@type: @id) is invalid.', array('@type' => $field['settings']['target_type'], '@id' => $id)),
|
||||
);
|
||||
if (!empty($valid_ids)) {
|
||||
$invalid_entities = array_diff_key($ids, array_flip($valid_ids));
|
||||
if ($invalid_entities) {
|
||||
foreach ($invalid_entities as $id => $delta) {
|
||||
$errors[$field['field_name']][$langcode][$delta][] = array(
|
||||
'error' => 'entityreference_invalid_entity',
|
||||
'message' => t('The referenced entity (@type: @id) is invalid.', array('@type' => $field['settings']['target_type'], '@id' => $id)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1094,6 +1096,7 @@ function entityreference_field_formatter_info() {
|
||||
'settings' => array(
|
||||
'view_mode' => 'default',
|
||||
'links' => TRUE,
|
||||
'use_content_language' => TRUE,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1105,6 +1108,7 @@ function entityreference_field_formatter_info() {
|
||||
function entityreference_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
$element = array();
|
||||
|
||||
if ($display['type'] == 'entityreference_label') {
|
||||
$element['link'] = array(
|
||||
@@ -1136,6 +1140,12 @@ function entityreference_field_formatter_settings_form($field, $instance, $view_
|
||||
'#title' => t('Show links'),
|
||||
'#default_value' => $settings['links'],
|
||||
);
|
||||
|
||||
$element['use_content_language'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use current content language'),
|
||||
'#default_value' => $settings['use_content_language'],
|
||||
);
|
||||
}
|
||||
|
||||
return $element;
|
||||
@@ -1162,6 +1172,7 @@ function entityreference_field_formatter_settings_summary($field, $instance, $vi
|
||||
}
|
||||
$summary[] = t('Rendered as @mode', array('@mode' => $view_mode_label));
|
||||
$summary[] = !empty($settings['links']) ? t('Display links') : t('Do not display links');
|
||||
$summary[] = !empty($settings['use_content_language']) ? t('Use current content language') : t('Use field language');
|
||||
}
|
||||
|
||||
return implode('<br />', $summary);
|
||||
@@ -1195,7 +1206,7 @@ function entityreference_field_formatter_prepare_view($entity_type, $entities, $
|
||||
|
||||
foreach ($items[$id] as $delta => $item) {
|
||||
// Check whether the referenced entity could be loaded.
|
||||
if (isset($target_entities[$item['target_id']])) {
|
||||
if (isset($item['target_id']) && isset($target_entities[$item['target_id']])) {
|
||||
// Replace the instance value with the term data.
|
||||
$items[$id][$delta]['entity'] = $target_entities[$item['target_id']];
|
||||
// Check whether the user has access to the referenced entity.
|
||||
@@ -1255,6 +1266,11 @@ function entityreference_field_formatter_view($entity_type, $entity, $field, $in
|
||||
break;
|
||||
|
||||
case 'entityreference_entity_view':
|
||||
$target_langcode = $langcode;
|
||||
if (!empty($settings['use_content_language']) && !empty($GLOBALS['language_content']->language)) {
|
||||
$target_langcode = $GLOBALS['language_content']->language;
|
||||
}
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
// Protect ourselves from recursive rendering.
|
||||
static $depth = 0;
|
||||
@@ -1263,9 +1279,9 @@ function entityreference_field_formatter_view($entity_type, $entity, $field, $in
|
||||
throw new EntityReferenceRecursiveRenderingException(t('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array('@entity_type' => $entity_type, '@entity_id' => $item['target_id'])));
|
||||
}
|
||||
|
||||
$entity = clone $item['entity'];
|
||||
unset($entity->content);
|
||||
$result[$delta] = entity_view($field['settings']['target_type'], array($item['target_id'] => $entity), $settings['view_mode'], $langcode, FALSE);
|
||||
$target_entity = clone $item['entity'];
|
||||
unset($target_entity->content);
|
||||
$result[$delta] = entity_view($field['settings']['target_type'], array($item['target_id'] => $target_entity), $settings['view_mode'], $target_langcode, FALSE);
|
||||
|
||||
if (empty($settings['links']) && isset($result[$delta][$field['settings']['target_type']][$item['target_id']]['links'])) {
|
||||
$result[$delta][$field['settings']['target_type']][$item['target_id']]['links']['#access'] = FALSE;
|
||||
|
||||
Reference in New Issue
Block a user