diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 643a59f..dd6921a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -63,10 +63,11 @@ settings" will lose the currently selected view if it doesn't have a when displaying referenced nodes. #1183300 by Pasqualle: Remove maxlength from noderef autocomplete widget. #1236096 by Dave Reid: fix fatal error on prepare_view (followup to #1094406) -#1275096 by Scyther, dereine, and jenlampton: Fix column not found error for nid. +#1275096 by Scyther, dereine, and jenlampton: Fix column not found error for +nid. #1275096 by jboese, dereine: Fix column not found error for nid (take 2). -#1341148 by plach: Fix Check views_access() when using Views to get the potential - references. +#1341148 by plach: Fix Check views_access() when using Views to get the +potential references. #1085576 by henrrrik, stamina, yched: Added "raw ID" and "raw path" formatters. #1051624 by Stalski: Added "rendered user in a given view mode" formatter for user_reference fields. @@ -74,8 +75,8 @@ settings" will lose the currently selected view if it doesn't have a for node_reference and user_reference fields. #1219224 by kunago, michaelfavia, yched: Added support for optgroups in select widget (for referenceable nodes/users provided by a view). -#1194086 by Dave Reid, mariagwyn, yched: Display entity labels through entity_label() - (formatters only for now) +#1194086 by Dave Reid, mariagwyn, yched: Display entity labels through +entity_label() (formatters only for now) #1288852 by yched: Fixed "Trying to get property of non-object" with fatal error on user_reference fields using a view (when the view does not include the user name as a field). diff --git a/README.md b/README.md index db4ae9d..9a55765 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ This module is based on the Drupal module References-7.x-2.x Project page: http://drupal.org/project/references. -Drupal Maintainers: +Drupal Maintainers: - Alex Andrascu (https://www.drupal.org/u/alex-andrascu) - Yves Chedemois (https://www.drupal.org/u/yched) - Karen Stevenson (https://www.drupal.org/u/karens) diff --git a/README.txt b/README.txt deleted file mode 100644 index f1fc8cd..0000000 --- a/README.txt +++ /dev/null @@ -1,36 +0,0 @@ - --- SUMMARY -- - -The References project contains straight ports of the node_reference and -user_reference modules to the Drupal 7 API. - -For a full description of the module, visit the project page: - http://drupal.org/project/references - --- REQUIREMENTS -- - -None. - -CCK for Drupal 7 is /not/ a requirement for these modules. - --- GOALS AND LIMITATIONS -- - -It is not envisioned as a final solution, but as a way to actually deploy -Drupal 7 from release day on sites using node and user references much as on -Drupal 6, until a native entity relationships Drupal 7 module becomes a usable -alternative. - -As of 2010-11-30, is looks like a candidate for that usable alternative might -someday be project Relation: - http://drupal.org/project/relation - -In short: use these modules now, but be ready to migrate to a different entity -referencing solution during the D7 life cycle. - --- CONTACT -- - -Current maintainers: - -* References: Frederic G. MARAND (fgm) - http://drupal.org/user/27985 -* CCK D7: Yves CHEDEMOIS (yched) - http://drupal.org/user/39567 - diff --git a/js/references.admin.js b/js/references.admin.js new file mode 100644 index 0000000..1262234 --- /dev/null +++ b/js/references.admin.js @@ -0,0 +1,22 @@ +/** + * @file + * JavaScript for References Admin Pages. + */ + +(function ($) { + + 'use strict'; + + Backdrop.behaviors.referencesAdmin = { + attach: function (context, settings) { + + var config_check_uncheck_all_roles = jQuery('input:checkbox[value=user_reference_config_select_all_roles]', context); + + var role_options = jQuery('#edit-field-settings-referenceable-roles', context).find('input[type=checkbox]', context); + + jQuery(config_check_uncheck_all_roles).on('click', function () { + role_options.not(this).prop('checked', this.checked); + }); + } + }; +})(jQuery); diff --git a/node_reference/node_reference.devel_generate.inc b/node_reference/node_reference.devel_generate.inc index 46c2cac..75e1b26 100644 --- a/node_reference/node_reference.devel_generate.inc +++ b/node_reference/node_reference.devel_generate.inc @@ -1,6 +1,16 @@ array(), ), ), - // It probably make more sense to have the referenceable types be per-field than per-instance + // It probably make more sense to have the referenceable types be + // per-field than per-instance // 'instance settings' => array('referenceable_types' => array()), - 'default_widget' => 'options_select', // node_reference_autocomplete', + // node_reference_autocomplete', + 'default_widget' => 'options_select', 'default_formatter' => 'node_reference_default', // Support hook_entity_property_info() from contrib "Entity API". 'property_type' => 'node', @@ -69,7 +71,7 @@ function node_reference_field_settings_form($field, $instance, $has_data) { // Special note for legacy fields migrated from D6. if (!empty($view_settings['view_name']) && $view_settings['display_name'] == 'default') { - $description .= '
'. t("Important D6 migration note:") . ''; + $description .= '
' . t("Important D6 migration note:") . '';
$description .= '
' . t("The field is currently configured to use the 'Master' display of the view %view_name.", array('%view_name' => $view_settings['view_name']));
$description .= '
' . t("It is highly recommended that you:
- edit this view and create a new display using the 'References' display type,
- update the field settings to explicitly select the correct view and display.");
$description .= '
' . t("The field will work correctly until then, but submitting this form might inadvertently change the field settings.") . '
' . t('Choose the view and display that select the nodes that can be referenced.
Only views with a display of type "References" are eligible.') . '
' . t('No eligible view was found.') .'
', + '#markup' => '' . t('No eligible view was found.') . '
', ); } } @@ -142,7 +144,11 @@ function _node_reference_view_settings_validate($element, &$form_state, $form) { $args_string = trim($element['args']['#value']); $args = ($args_string === '') ? array() : array_map('trim', explode(',', $args_string)); - $value = array('view_name' => $view, 'display_name' => $display, 'args' => $args); + $value = array( + 'view_name' => $view, + 'display_name' => $display, + 'args' => $args, + ); form_set_value($element, $value, $form_state); } @@ -150,7 +156,8 @@ function _node_reference_view_settings_validate($element, &$form_state, $form) { * Implements hook_field_validate(). * * Possible error codes: - * - 'invalid_nid': nid is not valid for the field (not a valid node id, or the node is not referenceable). + * - 'invalid_nid': nid is not valid for the field (not a valid node id, or the + * node is not referenceable). */ function node_reference_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { // Extract nids to check. @@ -199,16 +206,17 @@ function node_reference_field_prepare_view($entity_type, $entities, $field, $ins // Set an 'access' property on each item (TRUE if the node exists and is // accessible by the current user). - // Extract ids to check. $ids = array(); - foreach ($items as $id => $entity_items) { - foreach ($entity_items as $delta => $item) { - if (is_array($item)) { - // Default to 'not accessible'. - $items[$id][$delta]['access'] = FALSE; - if (!empty($item['nid']) && is_numeric($item['nid'])) { - $ids[$item['nid']] = $item['nid']; + if (is_array($items)) { + foreach ($items as $id => $entity_items) { + foreach ($entity_items as $delta => $item) { + if (is_array($item)) { + // Default to 'not accessible'. + $items[$id][$delta]['access'] = FALSE; + if (!empty($item['nid']) && is_numeric($item['nid'])) { + $ids[$item['nid']] = $item['nid']; + } } } } @@ -228,10 +236,11 @@ function node_reference_field_prepare_view($entity_type, $entities, $field, $ins ->condition('n.nid', $ids_to_check, 'IN'); // Unless the user has the right permissions, restrict on the node status. - // (note: the 'view any unpublished content' permission is provided by the - // 'view_unpublished' contrib module.) - if (!user_access('bypass node access') && !user_access('view any unpublished content')) { - // ... AND n.status = 1 + // 'view_unpublished' contrib module and the + // 'view all unpublished content' + // permission is provided by the 'workbench_moderation' contrib module.) + if (!user_access('bypass node access') && !user_access('view any unpublished content') && !user_access('view all unpublished content')) { + // ... AND n.status = 1. $status_condition = db_or() ->condition('n.status', NODE_PUBLISHED); @@ -240,7 +249,11 @@ function node_reference_field_prepare_view($entity_type, $entities, $field, $ins // only need the items in $ids_to_check because those are the only // entries that we are interested in. Any other nodes created by the // user are simply ignored so lets only retrieve that subset. - if (user_access('view own unpublished content') && ($own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status AND nid IN (:nodes)', array(':uid' => $GLOBALS['user']->uid, ':status' => NODE_NOT_PUBLISHED, ':nodes' => $ids_to_check))->fetchCol())) { + if (user_access('view own unpublished content') && ($own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status AND nid IN (:nodes)', array( + ':uid' => $GLOBALS['user']->uid, + ':status' => NODE_NOT_PUBLISHED, + ':nodes' => $ids_to_check, + ))->fetchCol())) { // ... AND (n.status = 1 OR n.nid IN (own unpublished)) $status_condition ->condition('n.nid', $own_unpublished, 'IN'); @@ -271,7 +284,7 @@ function node_reference_field_prepare_view($entity_type, $entities, $field, $ins * Implements hook_field_is_empty(). */ function node_reference_field_is_empty($item, $field) { - // nid = 0 is empty too, which is exactly what we want. + // Nid = 0 is empty too, which is exactly what we want. return empty($item['nid']); } @@ -307,7 +320,7 @@ function node_reference_field_formatter_info() { 'field types' => array('node_reference'), 'settings' => array( 'alias' => TRUE, - 'absolute' => FALSE + 'absolute' => FALSE, ), ), ); @@ -336,7 +349,7 @@ function node_reference_field_formatter_settings_form($field, $instance, $view_m '#type' => 'select', '#options' => $options, '#default_value' => $settings['node_reference_view_mode'], - // Never empty, so no #empty_option + // Never empty, so no #empty_option. ); break; @@ -388,15 +401,16 @@ function node_reference_field_formatter_settings_summary($field, $instance, $vie * Preload all nodes referenced by items using 'full entity' formatters. */ function node_reference_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) { + // Load the referenced nodes, except for the 'node_reference_nid' which does // not need full objects. - // Collect ids to load. $ids = array(); foreach ($displays as $id => $display) { if ($display['type'] != 'node_reference_nid') { foreach ($items[$id] as $delta => $item) { - if ($item['access']) { + // Checking item 'access' before the use. + if (!empty($item['access'])) { $ids[$item['nid']] = $item['nid']; } } @@ -408,7 +422,8 @@ function node_reference_field_formatter_prepare_view($entity_type, $entities, $f foreach ($displays as $id => $display) { if ($display['type'] != 'node_reference_nid') { foreach ($items[$id] as $delta => $item) { - if ($item['access']) { + // Checking item 'access' before the use. + if (!empty($item['access'])) { $items[$id][$delta]['node'] = $entities[$item['nid']]; } } @@ -427,8 +442,16 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins case 'node_reference_default': case 'node_reference_plain': foreach ($items as $delta => $item) { - if ($item['access']) { - $node = $item['node']; + if (!empty($item['access'])) { + + // Checking if exists the node. If not exists use node_load to load. + if (!empty($item['node'])) { + $node = $item['node']; + } + else { + $node = node_load($item['nid']); + } + $label = entity_label('node', $node); if ($display['type'] == 'node_reference_default') { $uri = entity_uri('node', $node); @@ -459,8 +482,9 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins // If no 'referencing entity' is set, we are starting a new 'reference // thread' and need to reset the queue. - // @todo Bug: $entity->referencing_entity on nodes referenced in a different - // thread on the page. E.g: 1 references 1+2 / 2 references 1+2 / visit homepage. + // @todo Bug: $entity->referencing_entity on nodes referenced in a + // different thread on the page. E.g: 1 references 1+2 / 2 references 1+2 + // visit homepage. // We'd need a more accurate way... if (!isset($entity->referencing_entity)) { $recursion_queue = array(); @@ -476,8 +500,13 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins // displayed, and which nodes will only be displayed as a title. $nodes_display = array(); foreach ($items as $delta => $item) { - if ($item['access'] && !isset($recursion_queue[$item['nid']])) { - $nodes_display[$item['nid']] = $item['node']; + if (!empty($item['access']) && !isset($recursion_queue[$item['nid']])) { + if (!empty($item['node'])) { + $nodes_display[$item['nid']] = $item['node']; + } + else { + $nodes_display[$item['nid']] = node_load($item['nid']); + } } } @@ -492,7 +521,7 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins // Assemble the render array. foreach ($items as $delta => $item) { - if ($item['access']) { + if (!empty($item['access'])) { if (isset($nodes_display[$item['nid']])) { $result[$delta] = $nodes_built['nodes'][$item['nid']]; } @@ -517,7 +546,7 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins case 'node_reference_nid': foreach ($items as $delta => $item) { - if ($item['access']) { + if (!empty($item['access'])) { $result[$delta] = array( '#markup' => $item['nid'], ); @@ -527,7 +556,7 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins case 'node_reference_path': foreach ($items as $delta => $item) { - if ($item['access']) { + if (!empty($item['access'])) { $uri = entity_uri('node', $item['node']); $options = array( 'absolute' => $settings['absolute'], @@ -557,6 +586,7 @@ function node_reference_field_widget_info() { 'field types' => array('node_reference'), 'settings' => array( 'autocomplete_match' => 'contains', + 'limit' => 10, 'size' => 60, 'autocomplete_path' => 'node_reference/autocomplete', ), @@ -593,6 +623,25 @@ function node_reference_field_widget_settings_form($field, $instance) { ), '#description' => t('Select the method used to collect autocomplete suggestions. Note that Contains can cause performance issues on sites with thousands of nodes.'), ); + $form['limit'] = array( + '#type' => 'select', + '#title' => t('Dropdown limit'), + '#options' => backdrop_map_assoc(array( + 5, + 10, + 15, + 20, + 25, + 30, + 35, + 40, + 45, + 50, + )), + '#default_value' => $settings['limit'], + '#required' => TRUE, + '#description' => t('Maximum number of matched dropdown items displayed on the form. Overrides limit setting of the view if used.'), + ); $form['size'] = array( '#type' => 'textfield', '#title' => t('Size of textfield'), @@ -629,15 +678,21 @@ function node_reference_field_widget_form(&$form, &$form_state, $field, $instanc * Value callback for a node_reference autocomplete element. * * Replace the node nid with a node title. + * + * @codingStandardsIgnoreStart */ -function node_reference_autocomplete_value($element, $input = FALSE, $form_state) { +function node_reference_autocomplete_value($element, $input, $form_state) { + if (!isset($input)) { + $input = FALSE; + } + // @codingStandardsIgnoreEnd if ($input === FALSE) { // We're building the displayed 'default value': expand the raw nid into // "node title [nid:n]". $nid = $element['#default_value']; if (!empty($nid)) { $q = db_select('node', 'n'); - $node_title_alias = $q->addField('n', 'title'); + $q->addField('n', 'title'); $q->addTag('node_access') ->condition('n.nid', $nid) ->range(0, 1); @@ -666,7 +721,7 @@ function node_reference_autocomplete_validate($element, &$form_state, $form) { if (!empty($matches)) { // Explicit nid. Check that the 'title' part matches the actual title for // the nid. - list(, $title, $nid) = $matches; + list(, , $nid) = $matches; if (!empty($nid)) { $real_title = db_select('node', 'n') ->fields('n', array('title')) @@ -713,22 +768,28 @@ function node_reference_field_widget_error($element, $error, $form, &$form_state } /** - * Builds a list of referenceable nodes suitable for the '#option' FAPI property. + * Node Reference Options. + * + * Builds a list of referenceable nodes suitable for the '#option' FAPI + * property. * * Warning: the function does NOT take care of encoding or escaping the node * titles. Proper massaging needs to be performed by the caller, according to * the destination FAPI '#type' (radios / checkboxes / select). * - * @param $field + * @param array $field * The field definition. - * @param $flat + * @param bool $flat * Whether optgroups are allowed. * - * @return + * @return array * An array of referenceable node titles, keyed by node id. If the $flat * parameter is TRUE, the list might be nested by optgroup first. + * + * @codingStandardsIgnoreStart */ function _node_reference_options($field, $flat = TRUE) { + // @codingStandardsIgnoreEnd $references = node_reference_potential_references($field); $options = array(); @@ -762,9 +823,9 @@ function _node_reference_options($field, $flat = TRUE) { * The array we return contains all the potentially needed information, * and lets consumers use the parts they actually need. * - * @param $field + * @param array $field * The field definition. - * @param $options + * @param array $options * An array of options to limit the scope of the returned list. The following * key/value pairs are accepted: * - string: string to filter titles on (used by autocomplete). @@ -773,7 +834,7 @@ function _node_reference_options($field, $flat = TRUE) { * - ids: array of specific node ids to lookup. * - limit: maximum size of the the result set. Defaults to 0 (no limit). * - * @return + * @return array * An array of valid nodes in the form: * array( * nid => array( @@ -782,14 +843,17 @@ function _node_reference_options($field, $flat = TRUE) { * ), * ... * ) + * + * @codingStandardsIgnoreStart */ function node_reference_potential_references($field, $options = array()) { + // @codingStandardsIgnoreEnd // Fill in default options. $options += array( 'string' => '', 'match' => 'contains', 'ids' => array(), - 'limit' => 0, + 'limit' => 25, ); $results = &backdrop_static(__FUNCTION__, array()); @@ -832,7 +896,7 @@ function _node_reference_potential_references_views($field, $options) { * List of referenceable nodes defined by content types. */ function _node_reference_potential_references_standard($field, $options) { - // Avoid useless work + // Avoid useless work. if (!count($field['settings']['referenceable_types'])) { return array(); } @@ -845,8 +909,8 @@ function _node_reference_potential_references_standard($field, $options) { // some unpublished nodes to view before adding the condition. if (user_access('view own unpublished content') && $own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => NODE_NOT_PUBLISHED))->fetchCol()) { $query->condition(db_or() - ->condition('n.status', NODE_PUBLISHED) - ->condition('n.nid', $own_unpublished, 'IN') + ->condition('n.status', NODE_PUBLISHED) + ->condition('n.nid', $own_unpublished, 'IN') ); } else { @@ -857,9 +921,9 @@ function _node_reference_potential_references_standard($field, $options) { $query->addTag('node_access'); } - $node_nid_alias = $query->addField('n', 'nid'); + $query->addField('n', 'nid'); $node_title_alias = $query->addField('n', 'title', 'node_title'); - $node_type_alias = $query->addField('n', 'type', 'node_type'); + $node_type_alias = $query->addField('n', 'type', 'node_type'); $query->addMetaData('id', ' _node_reference_potential_references_standard') ->addMetaData('field', $field) ->addMetaData('options', $options); @@ -886,7 +950,8 @@ function _node_reference_potential_references_standard($field, $options) { break; case 'equals': - default: // no match type or incorrect match type: use "=" + // No match type or incorrect match type: use "=". + default: $query->condition('n.title', $options['string']); break; } @@ -925,7 +990,7 @@ function node_reference_autocomplete($entity_type, $bundle, $field_name, $string $options = array( 'string' => $string, 'match' => $instance['widget']['settings']['autocomplete_match'], - 'limit' => 10, + 'limit' => $instance['widget']['settings']['limit'], ); $references = node_reference_potential_references($field, $options); @@ -952,7 +1017,7 @@ function node_reference_autocomplete($entity_type, $bundle, $field_name, $string function node_reference_node_type_update($info) { if (!empty($info->old_type) && $info->old_type != $info->type) { $fields = field_info_fields(); - foreach ($fields as $field_name => $field) { + foreach ($fields as $field) { if ($field['type'] == 'node_reference' && isset($field['settings']['referenceable_types'][$info->old_type])) { $field['settings']['referenceable_types'][$info->type] = empty($field['settings']['referenceable_types'][$info->old_type]) ? 0 : $info->type; unset($field['settings']['referenceable_types'][$info->old_type]); @@ -1001,20 +1066,23 @@ function node_reference_field_prepare_translation($entity_type, $entity, $field, /** * Find a translation for a specific node reference, if it exists. * - * @param $reference_node + * @param object $reference_node * The untranslated node reference. - * @param $langcode + * @param string $langcode + * String with lang code. * - * @return + * @return int * A nid for the translation of the node reference, * otherwise the original untranslated nid if no translation exists. */ function node_reference_find_translation($reference_node, $langcode) { - // Check if the source node translation is set and if translations are supported. + // Check if the source node translation is set and if translations are + // supported. if (isset($reference_node->tnid) && translation_supported_type($reference_node->type)) { // Determine whether an alternative language is being used. if (!empty($reference_node->language) && $reference_node->language != $langcode) { - // Return a corresponding translation nid for the reference (if it exists). + // Return a corresponding translation nid for the reference + // (if it exists). $translations = translation_node_get_translations($reference_node->tnid); if (isset($translations[$langcode])) { return $translations[$langcode]->nid; @@ -1078,7 +1146,7 @@ function node_reference_content_migrate_instance_alter(&$instance_value, $field_ switch ($field_value['type']) { case 'nodereference': // Massage formatters. - foreach ($instance_value['display'] as $context => &$display) { + foreach ($instance_value['display'] as &$display) { switch ($display['type']) { case 'full': case 'teaser': @@ -1101,10 +1169,12 @@ function node_reference_content_migrate_instance_alter(&$instance_value, $field_ $instance_value['widget']['type'] = 'node_reference_autocomplete'; $instance_value['widget']['module'] = 'node_reference'; break; + case 'nodereference_select': $instance_value['widget']['type'] = 'options_select'; $instance_value['widget']['module'] = 'options'; break; + case 'nodereference_buttons': $instance_value['widget']['type'] = 'options_buttons'; $instance_value['widget']['module'] = 'options'; @@ -1123,10 +1193,13 @@ function node_reference_field_views_data($field) { // No module_load_include(): this hook is invoked from // views/modules/field.views.inc, which is where that function is defined. $data = field_views_field_default_views_data($field); + $storage = array(); - $storage = $field['storage']['details']['sql']; + if (isset($field['storage']['details']['sql'])) { + $storage = $field['storage']['details']['sql']; + } - foreach ($storage as $age => $table_data) { + foreach ($storage as $table_data) { $table = key($table_data); $columns = current($table_data); $id_column = $columns['nid']; @@ -1176,7 +1249,7 @@ function node_reference_field_views_data_views_data_alter(&$data, $field) { $entity_info = entity_get_info($entity_type); $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; - list($label, $all_labels) = field_views_field_label($field['field_name']); + list($label) = field_views_field_label($field['field_name']); $entity = $entity_info['label']; if ($entity == t('Node')) { $entity = t('Content'); @@ -1184,10 +1257,18 @@ function node_reference_field_views_data_views_data_alter(&$data, $field) { // Only specify target entity type if the field is used in more than one. if (count($field['bundles']) > 1) { - $title = t('@field (@field_name) - reverse (to @entity)', array('@entity' => $entity, '@field' => $label, '@field_name' => $field['field_name'])); + $title = t('@field (@field_name) - reverse (to @entity)', array( + '@entity' => $entity, + '@field' => $label, + '@field_name' => $field['field_name'], + )); } else { - $title = t('@field (@field_name) - reverse', array('@entity' => $entity, '@field' => $label, '@field_name' => $field['field_name'])); + $title = t('@field (@field_name) - reverse', array( + '@entity' => $entity, + '@field' => $label, + '@field_name' => $field['field_name'], + )); } $data['node'][$pseudo_field_name]['relationship'] = array( 'title' => $title, @@ -1199,14 +1280,25 @@ function node_reference_field_views_data_views_data_alter(&$data, $field) { 'base' => $entity_info['base table'], 'base field' => $entity_info['entity keys']['id'], 'label' => t('!field_name', array('!field_name' => $field['field_name'])), + 'join_extra' => array( + 0 => array( + 'field' => 'entity_type', + 'value' => $entity_type, + ), + 1 => array( + 'field' => 'deleted', + 'value' => 0, + 'numeric' => TRUE, + ), + ), ); } } /** - * 'options callback' for the views_handler_filter_in_operator filter. + * Options: 'options callback' for the views_handler_filter_in_operator filter. * - * @param $field_name + * @param string $field_name * The field name. */ function node_reference_views_filter_options($field_name) { @@ -1227,3 +1319,39 @@ function node_reference_views_filter_options($field_name) { return $options; } + +/** + * Returns nodes of the given type(s) that are referred to in a given node. + * + * @param object $node + * The node object from which the references should be retrieved. + * @param array $types + * An array listing the desired content types. If omitted all referenced nodes + * are returned, regardless of type. + * + * @return array + * An associative array of nodes of the given types that are referred to in + * the given node, keyed by nid. + */ +function node_reference_get_referred_nodes($node, array $types = array()) { + + $nodes = array(); + + if (!isset($node->type)) { + return $nodes; + } + + foreach (field_info_fields() as $field_name => $field_info) { + if ($field_info['type'] == 'node_reference' && (empty($types) || array_intersect($types, $field_info['settings']['referenceable_types'])) && array_intersect(array($node->type), $field_info['bundles']['node'])) { + $field_items = field_get_items('node', $node, $field_name); + if (is_array($field_items) && !empty($field_items)) { + foreach ($field_items as $field_item) { + if (($referred_node = node_load($field_item['nid'])) && (empty($types) || in_array($referred_node->type, $types))) { + $nodes[$field_item['nid']] = $referred_node; + } + } + } + } + } + return $nodes; +} diff --git a/node_reference/tests/node_reference.test b/node_reference/tests/node_reference.test index 6eb3dcb..4399cb1 100644 --- a/node_reference/tests/node_reference.test +++ b/node_reference/tests/node_reference.test @@ -2,7 +2,7 @@ /** * @file - * Initial node_reference tests + * Initial node_reference tests. */ /** @@ -11,6 +11,10 @@ require_once BACKDROP_ROOT . '/core/modules/field/tests/field.test'; class NodeReferenceFormTest extends FieldTestCase { + + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Node reference', @@ -19,7 +23,10 @@ class NodeReferenceFormTest extends FieldTestCase { ); } - function setUp() { + /** + * Setup. + */ + public function setUp() { parent::setUp(array('node_reference', 'field_test')); $this->langcode = LANGUAGE_NONE; @@ -58,7 +65,10 @@ class NodeReferenceFormTest extends FieldTestCase { } } - function runReferenceableNodeTest($allowed, $group) { + /** + * Function to run Referenceable Node Test. + */ + public function runReferenceableNodeTest($allowed, $group) { field_update_field(array( 'field_name' => $this->field_name, 'settings' => array('referenceable_types' => array_keys($allowed)), @@ -71,13 +81,13 @@ class NodeReferenceFormTest extends FieldTestCase { foreach ($this->nodes as $node) { if (isset($allowed[$node->type])) { $this->assertTrue(isset($options[$node->nid]), - t('Node of type @type is referenceable', array('@type' => $node->type)), - $group); + t('Node of type @type is referenceable', array('@type' => $node->type)), + $group); } else { $this->assertFalse(isset($options[$node->nid]), - t('Node of type @type is not referenceable', array('@type' => $node->type)), - $group); + t('Node of type @type is not referenceable', array('@type' => $node->type)), + $group); } unset($options[$node->nid]); } @@ -85,26 +95,25 @@ class NodeReferenceFormTest extends FieldTestCase { } /** - * Test unlimited referencing + * Test unlimited referencing. */ - function testReferenceableNodeTypesAll() { + public function testReferenceableNodeTypesAll() { $allowed = node_type_get_names(); $this->runReferenceableNodeTest($allowed, t('Unimited referencing')); } /** - * Test referencing a limited list of node types + * Test referencing a limited list of node types. */ - function testReferenceableNodeTypesOne() { + public function testReferenceableNodeTypesOne() { $allowed = array_slice(node_type_get_names(), 0, 1, TRUE); $this->runReferenceableNodeTest($allowed, t('Limited referencing')); } - /** * Test autocomplete widget. */ - function testLongNodeReferenceWidget() { + public function testLongNodeReferenceWidget() { // Create regular test user. $web_user = $this->backdropCreateUser(array('create post content', 'access content')); $this->backdropLogin($web_user); @@ -154,4 +163,5 @@ class NodeReferenceFormTest extends FieldTestCase { $this->assertRaw(t('!post %title has been created.', array('!post' => 'Post', '%title' => $edit["title"])), t('Post created.')); $this->assertText($node_long_title->title, t('Referenced node title is displayed.')); } + } diff --git a/references.feeds.inc b/references.feeds.inc index ad319a3..778ee07 100644 --- a/references.feeds.inc +++ b/references.feeds.inc @@ -1,11 +1,15 @@ t('Feed node: Node Reference (nid): @field_name', array('@field_name' => $field['field_name'])), 'description' => t('Node References from the parent feed node.'), 'callback' => 'node_reference_feeds_get_source', @@ -30,22 +34,26 @@ function node_reference_feeds_parser_sources_alter(&$sources, $content_type) { /** * Callback for mapping parent node references to child node reference values. * - * @param $source + * @param object $source * A FeedsSource object. - * @param $result + * @param object $result * FeedsParserResult object. - * @param $key + * @param string $key * The key as defined in the _feeds_parser_sources_alter() hook defined above. + * * @return array * The node ids that the parent node references. + * + * @codingStandardsIgnoreStart */ function node_reference_feeds_get_source(FeedsSource $source, FeedsParserResult $result, $key) { + // @codingStandardsIgnoreEnd if ($node = node_load($source->feed_nid)) { $results = array(); $field = substr($key, 22); - if (!empty($node->{$field}['und'])) { - foreach ($node->{$field}['und'] as $delta => $value) { - $results[] = $value['nid']; + if (!empty($node->{$field}[LANGUAGE_NONE])) { + foreach ($node->{$field}[LANGUAGE_NONE] as $value) { + $results[] = $value[LANGUAGE_NONE]; } } return $results; @@ -53,9 +61,9 @@ function node_reference_feeds_get_source(FeedsSource $source, FeedsParserResult } /** - * Implements hook_feeds_processor_targets_alter() for node_reference fields + * Implements hook_feeds_processor_targets_alter() for node_reference fields. * - * @see FeedsNodeProcessor::getMappingTargets(). + * @see FeedsNodeProcessor::getMappingTargets() */ function node_reference_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { @@ -63,60 +71,68 @@ function node_reference_feeds_processor_targets_alter(&$targets, $entity_type, $ if ($info['type'] == 'node_reference') { $targets[$name . ':title'] = array( - 'name' => $instance['label'] . t(' (Node reference by node title)'), + 'name' => t('@label (Node reference by node title)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by node title.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':nid'] = array( - 'name' => $instance['label'] . t(' (Node reference by node ID)'), + 'name' => t('@label (Node reference by node ID)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by node ID.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':url'] = array( - 'name' => $instance['label'] . t(' (Node reference by Feeds URL)'), + 'name' => t('@label (Node reference by Feeds URL)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':guid'] = array( - 'name' => $instance['label'] . t(' (Node reference by Feeds GUID)'), + 'name' => t('@label (Node reference by Feeds GUID)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':title:duplicates'] = array( - 'name' => $instance['label'] . t(' (Node reference by node title) -- allow duplicate nodes'), + 'name' => t('@label (Node reference by node title) -- allow duplicate nodes', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by node title. This target allows duplicate nodes (nodes can appear more than once in a field).', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':nid:duplicates'] = array( - 'name' => $instance['label'] . t(' (Node reference by node ID) -- allow duplicate nodes'), + 'name' => t('@label (Node reference by node ID) -- allow duplicate nodes', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by node ID. This target allows duplicate nodes (nodes can appear more than once in a field).', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':url:duplicates'] = array( - 'name' => $instance['label'] . t(' (Node reference by Feeds URL) -- allow duplicate nodes'), + 'name' => t('@label (Node reference by Feeds URL) -- allow duplicate nodes', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':guid:duplicates'] = array( - 'name' => $instance['label'] . t(' (Node reference by Feeds GUID) -- allow duplicate nodes'), + 'name' => t('@label (Node reference by Feeds GUID) -- allow duplicate nodes', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); } } } + /** - * Implements hook_feeds_processor_targets_alter() for user_reference fields - * - * @see FeedsNodeProcessor::getMappingTargets(). + * Implements hook_feeds_processor_targets_alter() for user_reference fields. * + * @see FeedsNodeProcessor::getMappingTargets() */ function user_reference_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { @@ -124,68 +140,76 @@ function user_reference_feeds_processor_targets_alter(&$targets, $entity_type, $ if ($info['type'] == 'user_reference') { $targets[$name . ':name'] = array( - 'name' => $instance['label'] . t(' (User reference by user name)'), + 'name' => t('@label (User reference by user name)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', - 'description' => t('The @label field of the user matched by user name. ', array('@label' => $instance['label'])), - 'real_target' => $name); + 'description' => t('The @label field of the user matched by user name.', array('@label' => $instance['label'])), + 'real_target' => $name, + ); $targets[$name . ':uid'] = array( - 'name' => $instance['label'] . t(' (User reference by user ID)'), + 'name' => t('@label (User reference by user ID)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the user matched by user ID.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':url'] = array( - 'name' => $instance['label'] . t(' (User reference by Feeds URL)'), + 'name' => t('@label (User reference by Feeds URL)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':guid'] = array( - 'name' => $instance['label'] . t(' (User reference by Feeds GUID)'), + 'name' => t('@label (User reference by Feeds GUID)', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':name:duplicates'] = array( - 'name' => $instance['label'] . t(' (User reference by user name) -- allow duplicate users'), + 'name' => t('@label (User reference by user name) -- allow duplicate users', array('label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the user matched by user name. This target allows duplicate users (users can appear more than once in a field).', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':uid:duplicates'] = array( - 'name' => $instance['label'] . t(' (User reference by user ID) -- allow duplicate users'), + 'name' => t('@label (User reference by user ID) -- allow duplicate users', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the user matched by user ID. This target allows duplicate users (users can appear more than once in a field).', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':url:duplicates'] = array( - 'name' => $instance['label'] . t(' (User reference by Feeds URL) -- allow duplicate users'), + 'name' => t('@label (User reference by Feeds URL) -- allow duplicate users', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); $targets[$name . ':guid:duplicates'] = array( - 'name' => $instance['label'] . t(' (User reference by Feeds GUID) -- allow duplicate users'), + 'name' => t('@label (User reference by Feeds GUID) -- allow duplicate users', array('@label' => $instance['label'])), 'callback' => 'references_feeds_set_target', 'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])), - 'real_target' => $name); + 'real_target' => $name, + ); } } } /** - * Callback for mapping both node reference and user_reference fields + * Callback for mapping both node reference and user_reference fields. * * Implementation of hook_feeds_set_target(). * - * @param $source + * @param object $source * A FeedsSource object. - * @param $entity + * @param object $entity * The entity to map to. - * @param $target + * @param string $target * The target key on $entity to map to. - * @param $value + * @param mixed $value * The value to map. Can be an array or a string. */ function references_feeds_set_target($source, $entity, $target, $value) { @@ -198,9 +222,10 @@ function references_feeds_set_target($source, $entity, $target, $value) { $value = array($value); } - // Determine the field we are matching against, and whether duplicates are allowed. + // Determine the field we are matching against, and whether duplicates are + // allowed. $target_info = explode(':', $target, 3); - if (sizeof($target_info) == 3) { + if (count($target_info) == 3) { list($target, $match_key, $duplicates) = $target_info; } else { @@ -209,7 +234,8 @@ function references_feeds_set_target($source, $entity, $target, $value) { // Load field definition. $info = field_info_field($target); - // Parameters to handle differences between node references and user references + // Parameters to handle differences between node references and user + // references. if ($info['type'] == 'user_reference') { $idname = 'uid'; $typename = 'user'; @@ -222,8 +248,8 @@ function references_feeds_set_target($source, $entity, $target, $value) { } $field = isset($entity->$target) ? $entity->$target : array(); - if (!isset($field['und'])) { - $field['und'] = array(); + if (!isset($field[LANGUAGE_NONE])) { + $field[LANGUAGE_NONE] = array(); } // Match values against nodes and add to field. @@ -242,14 +268,14 @@ function references_feeds_set_target($source, $entity, $target, $value) { // Validate node title or user name. if ((is_string($options['string']) && $options['string'] != '') || is_numeric($options['string'])) { // Lookup potential exact matches for the value (limit to one result). - $matches = $validate_function($info,$options); + $matches = $validate_function($info, $options); // Use the first element of the potential matches. - $options['ids']= key($matches); + $options['ids'] = key($matches); } // Alert if no match is found. if (empty($options['ids'])) { - backdrop_set_message(t('%title does not match an existing '.$typename, array('%title' => $options['string']))); + backdrop_set_message(t('%title does not match an existing @typename', array('%title' => $options['string'], '@typename' => $typename))); } break; @@ -268,19 +294,19 @@ function references_feeds_set_target($source, $entity, $target, $value) { // Alert if no match is found. if (empty($options['ids'])) { - backdrop_set_message(t('%id is not a valid '.$typename.' id for this field.', array('%id' => $options['string']))); + backdrop_set_message(t('%id is not a valid @typename id for this field.', array('%id' => $options['string'], '@typename' => $typename))); } break; case 'guid': case 'url': - // get the value from table feeds-item. - $result = db_query('SELECT f.entity_id FROM {feeds_item} f WHERE f.'.$match_key.' = :v', array( ':v' => $v) ); + // Get the value from table feeds-item. + $result = db_query('SELECT f.entity_id FROM {feeds_item} f WHERE f.' . $match_key . ' = :v', array(':v' => $v)); $options['ids'] = $result->fetchField(); // Alert if no match is found. if (empty($options['ids'])) { - backdrop_set_message(t('%id is not a valid '.$typename.' id for this field.', array('%id' => $v))); + backdrop_set_message(t('%id is not a valid @typename id for this field.', array('%id' => $v, '@typename' => $typename))); } break; } @@ -289,11 +315,11 @@ function references_feeds_set_target($source, $entity, $target, $value) { $reference = array($idname => $options['ids']); if (!empty($duplicates)) { // Add the reference, ignoring duplicates. - $field['und'][] = $reference; + $field[LANGUAGE_NONE][] = $reference; } - else if (!in_array($reference, $field['und'])) { + elseif (!in_array($reference, $field[LANGUAGE_NONE])) { // Add the reference only if it doesn't already exist. - $field['und'][] = $reference; + $field[LANGUAGE_NONE][] = $reference; } if ($info['cardinality'] == 1) { diff --git a/references.module b/references.module index 226c48f..9aaf409 100644 --- a/references.module +++ b/references.module @@ -25,7 +25,7 @@ function reference_autocomplete_access($entity_type, $bundle, $field_name, $enti function references_init() { // Include feeds.module integration. if (module_exists('feeds')) { - module_load_include('inc','references','references.feeds'); + module_load_include('inc', 'references', 'references.feeds'); } } @@ -109,12 +109,15 @@ function references_views_plugins() { } /** - * Retrieves the list of views with a 'references' display, in a format suitable for a 'select' form element.. + * Get Views Options. * - * @param $entity_type + * Retrieves the list of views with a 'references' display, in a format suitable + * for a 'select' form element.. + * + * @param string $entity_type * The entity type. * - * @return + * @return array * An array of eligible views displays. */ function references_get_views_options($entity_type) { @@ -129,7 +132,7 @@ function references_get_views_options($entity_type) { foreach ($displays as $data) { list($view, $display_id) = $data; if ($view->base_table == $entity_info['base table']) { - $options[$view->name . ':' . $display_id] = $view->name .' - ' . $view->display[$display_id]->display_title; + $options[$view->name . ':' . $display_id] = $view->name . ' - ' . $view->display[$display_id]->display_title; } } @@ -139,29 +142,32 @@ function references_get_views_options($entity_type) { /** * Retrieves an array of candidate referenceable entities, defined by a view. * - * @param $entity_type + * @param string $entity_type * The entity type. - * @param $view_name + * @param string $view_name * The name of the view. - * @param $display_name + * @param string $display_name * The name of the view's display. This has to be a 'References' display. - * @param $args + * @param array $args * The array of arguments ("contextual filters") for the view. - * @param $options + * @param array $options * Array of options to limit the scope of the returned list. This parameter * is similar to the $options parameter for * node_reference_potential_references(). An additional key is required: * - title_field: the name of the column holding entities 'titles' within the * entity base table. * - * @return + * @return array * An array of entities, in the format expected by * node_reference_potential_references(). * * @see node_reference_potential_references() * @see _node_reference_potential_references_views() + * + * @codingStandardsIgnoreStart */ function references_potential_references_view($entity_type, $view_name, $display_name, $args, $options) { + // @codingStandardsIgnoreEnd $entity_info = entity_get_info($entity_type); // Check that the view is valid and the display still exists. @@ -172,7 +178,7 @@ function references_potential_references_view($entity_type, $view_name, $display // If we have no access to the View an empty result should be returned to // avoid triggering the fallback results. - if (!$view->access(array($display_name))) { + if (!$view->access(array($display_name))) { return array(); } @@ -188,7 +194,6 @@ function references_potential_references_view($entity_type, $view_name, $display // the style setting. // We might also need to check if there's an argument, and set its // style_plugin as well. - // Set additional options to let references_plugin_display::query() narrow // the results. $references_options = array( @@ -209,11 +214,7 @@ function references_potential_references_view($entity_type, $view_name, $display $view->add_item($display_name, 'field', $entity_info['base table'], $options['title_field'], $label_options); } - // Limit result set size. - $limit = !empty($options['limit']) ? $options['limit'] : 0; - $view->display_handler->set_option('pager', array('type' => 'some', 'options' => array('items_per_page' => $limit))); - - // Make sure the query is not cached + // Make sure the query is not cached. $view->is_cacheable = FALSE; // Get the results. diff --git a/references_uuid/references_uuid.info b/references_uuid/references_uuid.info index fc7176b..bd476c4 100644 --- a/references_uuid/references_uuid.info +++ b/references_uuid/references_uuid.info @@ -1,4 +1,5 @@ name = References UUID +description = UUID for References project. core = 7.x backdrop = 1.x type = module diff --git a/references_uuid/references_uuid.module b/references_uuid/references_uuid.module index 1a3f7f3..3cca179 100644 --- a/references_uuid/references_uuid.module +++ b/references_uuid/references_uuid.module @@ -1,7 +1,8 @@ 'checkboxes', '#title' => t('User roles that can be referenced'), '#default_value' => is_array($settings['referenceable_roles']) - ? array_filter($settings['referenceable_roles']) - : array(), - '#options' => user_roles(TRUE), + ? array_filter($settings['referenceable_roles']) + : array(), + '#options' => $options, ); $form['referenceable_status'] = array( '#type' => 'checkboxes', '#title' => t('User status that can be referenced'), '#default_value' => is_array($settings['referenceable_status']) - ? array_filter($settings['referenceable_status']) - : array(1), + ? array_filter($settings['referenceable_status']) + : array(1), '#options' => array(1 => t('Active'), 0 => t('Blocked')), ); @@ -77,7 +86,7 @@ function user_reference_field_settings_form($field, $instance, $has_data) { // Special note for legacy fields migrated from D6. if (!empty($view_settings['view_name']) && $view_settings['display_name'] == 'default') { - $description .= ''. t("Important D6 migration note:") . ''; + $description .= '
' . t("Important D6 migration note:") . '';
$description .= '
' . t("The field is currently configured to use the 'Master' display of the view %view_name.", array('%view_name' => $view_settings['view_name']));
$description .= '
' . t("It is highly recommended that you:
- edit this view and create a new display using the 'References' display type,
- update the field settings to explicitly select the correct view and display.");
$description .= '
' . t("The field will work correctly until then, but submitting this form might inadvertently change the field settings.") . '
' . t('Choose the view and display that select the nodes that can be referenced.
Only views with a display of type "References" are eligible.') . '
' . t('No eligible view was found.') .'
', + '#markup' => '' . t('No eligible view was found.') . '
', ); } } @@ -150,7 +159,11 @@ function _user_reference_view_settings_validate($element, &$form_state, $form) { $args_string = trim($element['args']['#value']); $args = ($args_string === '') ? array() : array_map('trim', explode(',', $args_string)); - $value = array('view_name' => $view, 'display_name' => $display, 'args' => $args); + $value = array( + 'view_name' => $view, + 'display_name' => $display, + 'args' => $args, + ); form_set_value($element, $value, $form_state); } @@ -158,7 +171,8 @@ function _user_reference_view_settings_validate($element, &$form_state, $form) { * Implements hook_field_validate(). * * Possible error codes: - * - 'invalid_uid': uid is not valid for the field (not a valid user id, or the user is not referenceable). + * - 'invalid_uid': uid is not valid for the field (not a valid user id, or the + * user is not referenceable). */ function user_reference_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { // Extract uids to check. @@ -206,7 +220,6 @@ function user_reference_field_prepare_view($entity_type, $entities, $field, $ins $checked_ids = &backdrop_static(__FUNCTION__, array()); // Set an 'access' property on each item (TRUE if the user exists). - // Extract ids to check. $ids = array(); foreach ($items as $id => $entity_items) { @@ -288,7 +301,7 @@ function user_reference_field_formatter_info() { 'field types' => array('user_reference'), 'settings' => array( 'alias' => TRUE, - 'absolute' => FALSE + 'absolute' => FALSE, ), ), ); @@ -316,7 +329,7 @@ function user_reference_field_formatter_settings_form($field, $instance, $view_m '#type' => 'select', '#options' => $options, '#default_value' => $settings['user_reference_view_mode'], - // Never empty, so no #empty_option + // Never empty, so no #empty_option. ); break; @@ -362,7 +375,6 @@ function user_reference_field_formatter_settings_summary($field, $instance, $vie return implode('