diff --git a/entityreference.module b/entityreference.module index bdcb562..e45d567 100644 --- a/entityreference.module +++ b/entityreference.module @@ -1082,6 +1082,15 @@ function entityreference_field_formatter_info() { 'link' => FALSE, ), ), + 'entityreference_path' => array( + 'label' => t('URL as plain text'), + 'description' => t('Display the URL of the referenced entities.'), + 'field types' => array('entityreference'), + 'settings' => array( + 'alias' => TRUE, + 'absolute' => FALSE + ), + ), 'entityreference_entity_id' => array( 'label' => t('Entity id'), 'description' => t('Display the id of the referenced entities.'), @@ -1105,6 +1114,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( @@ -1114,6 +1124,19 @@ function entityreference_field_formatter_settings_form($field, $instance, $view_ ); } + if ($display['type'] === 'entityreference_path') { + $element['alias'] = array( + '#type' => 'checkbox', + '#title' => t('Display the aliased path (if exists) instead of the system path'), + '#default_value' => $settings['alias'], + ); + $element['absolute'] = array( + '#type' => 'checkbox', + '#title' => t('Display an absolute URL'), + '#default_value' => $settings['absolute'], + ); + } + if ($display['type'] == 'entityreference_entity_view') { $entity_info = entity_get_info($field['settings']['target_type']); $options = array('default' => t('Default')); @@ -1248,6 +1271,21 @@ function entityreference_field_formatter_view($entity_type, $entity, $field, $in } break; + case 'entityreference_path': + foreach ($items as $delta => $item) { + // If the link is to be displayed and the entity has a uri, display a link. + // Note the assignment ($url = ) here is intended to be an assignment. + if ($uri = entity_uri($field['settings']['target_type'], $item['entity'])) { + $options = array( + 'absolute' => $settings['absolute'], + 'alias' => !$settings['alias'], + ); + $options += $uri['options']; + $result[$delta] = array('#markup' => url($uri['path'], $options)); + } + } + break; + case 'entityreference_entity_id': foreach ($items as $delta => $item) { $result[$delta] = array('#markup' => check_plain($item['target_id']));