Revision 56aebcb7
Added by Assos Assos about 8 years ago
drupal7/sites/all/modules/entityreference/entityreference.module | ||
---|---|---|
220 | 220 |
if ($ids) { |
221 | 221 |
$valid_ids = entityreference_get_selection_handler($field, $instance, $entity_type, $entity)->validateReferencableEntities(array_keys($ids)); |
222 | 222 |
|
223 |
$invalid_entities = array_diff_key($ids, array_flip($valid_ids)); |
|
224 |
if ($invalid_entities) { |
|
225 |
foreach ($invalid_entities as $id => $delta) { |
|
226 |
$errors[$field['field_name']][$langcode][$delta][] = array( |
|
227 |
'error' => 'entityreference_invalid_entity', |
|
228 |
'message' => t('The referenced entity (@type: @id) is invalid.', array('@type' => $field['settings']['target_type'], '@id' => $id)), |
|
229 |
); |
|
223 |
if (!empty($valid_ids)) { |
|
224 |
$invalid_entities = array_diff_key($ids, array_flip($valid_ids)); |
|
225 |
if ($invalid_entities) { |
|
226 |
foreach ($invalid_entities as $id => $delta) { |
|
227 |
$errors[$field['field_name']][$langcode][$delta][] = array( |
|
228 |
'error' => 'entityreference_invalid_entity', |
|
229 |
'message' => t('The referenced entity (@type: @id) is invalid.', array('@type' => $field['settings']['target_type'], '@id' => $id)), |
|
230 |
); |
|
231 |
} |
|
230 | 232 |
} |
231 | 233 |
} |
232 | 234 |
} |
... | ... | |
1094 | 1096 |
'settings' => array( |
1095 | 1097 |
'view_mode' => 'default', |
1096 | 1098 |
'links' => TRUE, |
1099 |
'use_content_language' => TRUE, |
|
1097 | 1100 |
), |
1098 | 1101 |
), |
1099 | 1102 |
); |
... | ... | |
1105 | 1108 |
function entityreference_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { |
1106 | 1109 |
$display = $instance['display'][$view_mode]; |
1107 | 1110 |
$settings = $display['settings']; |
1111 |
$element = array(); |
|
1108 | 1112 |
|
1109 | 1113 |
if ($display['type'] == 'entityreference_label') { |
1110 | 1114 |
$element['link'] = array( |
... | ... | |
1136 | 1140 |
'#title' => t('Show links'), |
1137 | 1141 |
'#default_value' => $settings['links'], |
1138 | 1142 |
); |
1143 |
|
|
1144 |
$element['use_content_language'] = array( |
|
1145 |
'#type' => 'checkbox', |
|
1146 |
'#title' => t('Use current content language'), |
|
1147 |
'#default_value' => $settings['use_content_language'], |
|
1148 |
); |
|
1139 | 1149 |
} |
1140 | 1150 |
|
1141 | 1151 |
return $element; |
... | ... | |
1162 | 1172 |
} |
1163 | 1173 |
$summary[] = t('Rendered as @mode', array('@mode' => $view_mode_label)); |
1164 | 1174 |
$summary[] = !empty($settings['links']) ? t('Display links') : t('Do not display links'); |
1175 |
$summary[] = !empty($settings['use_content_language']) ? t('Use current content language') : t('Use field language'); |
|
1165 | 1176 |
} |
1166 | 1177 |
|
1167 | 1178 |
return implode('<br />', $summary); |
... | ... | |
1195 | 1206 |
|
1196 | 1207 |
foreach ($items[$id] as $delta => $item) { |
1197 | 1208 |
// Check whether the referenced entity could be loaded. |
1198 |
if (isset($target_entities[$item['target_id']])) { |
|
1209 |
if (isset($item['target_id']) && isset($target_entities[$item['target_id']])) {
|
|
1199 | 1210 |
// Replace the instance value with the term data. |
1200 | 1211 |
$items[$id][$delta]['entity'] = $target_entities[$item['target_id']]; |
1201 | 1212 |
// Check whether the user has access to the referenced entity. |
... | ... | |
1255 | 1266 |
break; |
1256 | 1267 |
|
1257 | 1268 |
case 'entityreference_entity_view': |
1269 |
$target_langcode = $langcode; |
|
1270 |
if (!empty($settings['use_content_language']) && !empty($GLOBALS['language_content']->language)) { |
|
1271 |
$target_langcode = $GLOBALS['language_content']->language; |
|
1272 |
} |
|
1273 |
|
|
1258 | 1274 |
foreach ($items as $delta => $item) { |
1259 | 1275 |
// Protect ourselves from recursive rendering. |
1260 | 1276 |
static $depth = 0; |
... | ... | |
1263 | 1279 |
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']))); |
1264 | 1280 |
} |
1265 | 1281 |
|
1266 |
$entity = clone $item['entity']; |
|
1267 |
unset($entity->content); |
|
1268 |
$result[$delta] = entity_view($field['settings']['target_type'], array($item['target_id'] => $entity), $settings['view_mode'], $langcode, FALSE);
|
|
1282 |
$target_entity = clone $item['entity'];
|
|
1283 |
unset($target_entity->content);
|
|
1284 |
$result[$delta] = entity_view($field['settings']['target_type'], array($item['target_id'] => $target_entity), $settings['view_mode'], $target_langcode, FALSE);
|
|
1269 | 1285 |
|
1270 | 1286 |
if (empty($settings['links']) && isset($result[$delta][$field['settings']['target_type']][$item['target_id']]['links'])) { |
1271 | 1287 |
$result[$delta][$field['settings']['target_type']][$item['target_id']]['links']['#access'] = FALSE; |
Also available in: Unified diff
Weekly update of contrib modules