From 5f7b87166a9c19f7b063e1c23a9a81625f663960 Mon Sep 17 00:00:00 2001 From: CashWilliams Date: Tue, 18 Apr 2017 18:48:25 +0200 Subject: [PATCH 01/33] Fixes long outstanding issue by cashwilliams, Alex Andrascu, mhless, Nick_vh, nielsaers --- node_reference/node_reference.module | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 78acbe3..6a1aa70 100755 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -838,11 +838,29 @@ function _node_reference_potential_references_standard($field, $options) { } $query = db_select('node', 'n'); + + if (!user_access('bypass node access')) { + // If the user is able to view their own unpublished nodes, allow them to + // see these in addition to published nodes. Check that they actually have + // 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') + ); + } + else { + // If not, restrict the query to published nodes. + $query->condition('n.status', NODE_PUBLISHED); + } + + $query->addTag('node_access'); + } + $node_nid_alias = $query->addField('n', 'nid'); $node_title_alias = $query->addField('n', 'title', 'node_title'); $node_type_alias = $query->addField('n', 'type', 'node_type'); - $query->addTag('node_access') - ->addMetaData('id', ' _node_reference_potential_references_standard') + $query->addMetaData('id', ' _node_reference_potential_references_standard') ->addMetaData('field', $field) ->addMetaData('options', $options); From 052dfc5d3fc80245e8a25c2469eb68eb06d08a34 Mon Sep 17 00:00:00 2001 From: Thomasdbcklr Date: Fri, 21 Apr 2017 16:24:42 +0200 Subject: [PATCH 02/33] Issue #2807141 by prince_zyxware, Thomasdbcklr: Fix coding standard - spacing issues --- references.feeds.inc | 14 +++++++------- references.module | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/references.feeds.inc b/references.feeds.inc index c5c2f70..5618318 100644 --- a/references.feeds.inc +++ b/references.feeds.inc @@ -16,7 +16,7 @@ function node_reference_feeds_parser_sources_alter(&$sources, $content_type) { $fields = field_info_fields(); foreach ($fields as $field) { if ($field['type'] == 'node_reference' && isset($field['bundles']['node']) && in_array($content_type, $field['bundles']['node'])) { - $sources['parent:node_reference:'. $field['field_name']] = array( + $sources['parent:node_reference:' . $field['field_name']] = array( 'name' => 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', @@ -242,14 +242,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); } // Alert if no match is found. if (empty($options['ids'])) { - drupal_set_message(t('%title does not match an existing '.$typename, array('%title' => $options['string']))); + drupal_set_message(t('%title does not match an existing ' . $typename, array('%title' => $options['string']))); } break; @@ -268,19 +268,19 @@ function references_feeds_set_target($source, $entity, $target, $value) { // Alert if no match is found. if (empty($options['ids'])) { - drupal_set_message(t('%id is not a valid '.$typename.' id for this field.', array('%id' => $options['string']))); + drupal_set_message(t('%id is not a valid ' . $typename. ' id for this field.', array('%id' => $options['string']))); } 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) ); + $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'])) { - drupal_set_message(t('%id is not a valid '.$typename.' id for this field.', array('%id' => $v))); + drupal_set_message(t('%id is not a valid ' . $typename . ' id for this field.', array('%id' => $v))); } break; } @@ -291,7 +291,7 @@ function references_feeds_set_target($source, $entity, $target, $value) { // Add the reference, ignoring duplicates. $field['und'][] = $reference; } - else if (!in_array($reference, $field['und'])) { + elseif (!in_array($reference, $field['und'])) { // Add the reference only if it doesn't already exist. $field['und'][] = $reference; } diff --git a/references.module b/references.module index 21284f6..d57f46e 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'); } } @@ -114,7 +114,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; } } From 1af659d99122e42b42e737106879fdb6466bee75 Mon Sep 17 00:00:00 2001 From: renatog Date: Tue, 13 Jun 2017 12:59:41 -0300 Subject: [PATCH 03/33] Issue #2885779 by RenatoG: Documentation README with new Template of Drupal.org --- README.txt | 56 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/README.txt b/README.txt index f1fc8cd..972d5cb 100644 --- a/README.txt +++ b/README.txt @@ -1,19 +1,39 @@ +CONTENTS OF THIS FILE +--------------------- + + * Introduction + * Requirements + * Installation + * Goals and limitations + * Configuration + * Maintainers --- SUMMARY -- -The References project contains straight ports of the node_reference and +INTRODUCTION +------------ + +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 -- +http://drupal.org/project/references + + +REQUIREMENTS +------------ + +No special requirements -None. -CCK for Drupal 7 is /not/ a requirement for these modules. +INSTALLATION +------------ --- GOALS AND LIMITATIONS -- +Install as you would normally install a contributed Drupal module. See: +https://drupal.org/documentation/install/modules-themes/modules-7 for further +information. + +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 @@ -27,10 +47,22 @@ someday be 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: +CONFIGURATION +------------- + + * There is no configuration. -* References: Frederic G. MARAND (fgm) - http://drupal.org/user/27985 -* CCK D7: Yves CHEDEMOIS (yched) - http://drupal.org/user/39567 +MAINTAINERS +----------- + +Current maintainers: + * Alexandru Andrascu (Alex Andrascu) - https://www.drupal.org/user/429248 + * Karen Stevenson (KarenS) - https://www.drupal.org/user/45874 + * Nick Veenhof (Nick_vh) - https://www.drupal.org/user/122682 + * Renato Gonçalves (RenatoG) - https://www.drupal.org/user/3326031 + * Thomas De Beuckelaer (Thomasdbcklr) - https://www.drupal.org/user/2945061 + * Frédéric G. Marand (fgm) - https://www.drupal.org/user/27985 + * Niels Aers (nielsaers) - https://www.drupal.org/user/752444 + * Yves Chedemois (yched) - https://www.drupal.org/user/39567 From 45de08dd01e0a42baba90ee886776be23ec9a1a0 Mon Sep 17 00:00:00 2001 From: renatog Date: Tue, 13 Jun 2017 13:13:59 -0300 Subject: [PATCH 04/33] Issue #2885787 by RenatoG: Use LANGUAGE_NONE instead of ['und'] --- references.feeds.inc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/references.feeds.inc b/references.feeds.inc index 5618318..43c2926 100644 --- a/references.feeds.inc +++ b/references.feeds.inc @@ -43,9 +43,9 @@ function node_reference_feeds_get_source(FeedsSource $source, FeedsParserResult 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 $delta => $value) { + $results[] = $value[LANGUAGE_NONE]; } } return $results; @@ -222,8 +222,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. @@ -289,11 +289,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; } - elseif (!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) { From 438e168b1791da32a6152e97c738910d18953d3a Mon Sep 17 00:00:00 2001 From: renatog Date: Wed, 14 Jun 2017 12:06:49 -0300 Subject: [PATCH 05/33] Issue #2886167 by RenatoG: Clean all variables unused in project --- .../node_reference.devel_generate.inc | 1 - node_reference/node_reference.module | 28 +++++++++++-------- references.feeds.inc | 2 +- references.module | 10 ++++--- user_reference/user_reference.module | 19 ++++--------- views/references_plugin_style.inc | 2 +- 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/node_reference/node_reference.devel_generate.inc b/node_reference/node_reference.devel_generate.inc index 46c2cac..d7eacf9 100644 --- a/node_reference/node_reference.devel_generate.inc +++ b/node_reference/node_reference.devel_generate.inc @@ -1,6 +1,5 @@ addField('n', 'title'); + $q->addField('n', 'title'); $q->addTag('node_access') ->condition('n.nid', $nid) ->range(0, 1); @@ -666,7 +670,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')) @@ -857,7 +861,7 @@ 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'); $query->addMetaData('id', ' _node_reference_potential_references_standard') @@ -952,7 +956,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]); @@ -1078,7 +1082,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': @@ -1126,7 +1130,7 @@ function node_reference_field_views_data($field) { $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 +1180,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'); diff --git a/references.feeds.inc b/references.feeds.inc index 43c2926..8300e9b 100644 --- a/references.feeds.inc +++ b/references.feeds.inc @@ -44,7 +44,7 @@ function node_reference_feeds_get_source(FeedsSource $source, FeedsParserResult $results = array(); $field = substr($key, 22); if (!empty($node->{$field}[LANGUAGE_NONE])) { - foreach ($node->{$field}[LANGUAGE_NONE] as $delta => $value) { + foreach ($node->{$field}[LANGUAGE_NONE] as $value) { $results[] = $value[LANGUAGE_NONE]; } } diff --git a/references.module b/references.module index d57f46e..c925c29 100644 --- a/references.module +++ b/references.module @@ -169,10 +169,12 @@ function references_potential_references_view($entity_type, $view_name, $display $view->set_display($display_name); - // @todo From merlinofchaos on IRC : arguments using summary view can defeat - // the style setting. - // We might also need to check if there's an argument, and set its - // style_plugin as well. + /** + * @todo From merlinofchaos on IRC : arguments using summary view can defeat + * 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. diff --git a/user_reference/user_reference.module b/user_reference/user_reference.module index b2d6c8f..7df28cf 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -206,7 +206,6 @@ function user_reference_field_prepare_view($entity_type, $entities, $field, $ins $checked_ids = &drupal_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) { @@ -371,7 +370,6 @@ function user_reference_field_formatter_settings_summary($field, $instance, $vie function user_reference_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) { // Load the referenced users, except for the 'user_reference_uid' which does // not need full objects. - // Collect ids to load. $ids = array(); foreach ($displays as $id => $display) { @@ -404,15 +402,8 @@ function user_reference_field_formatter_view($entity_type, $entity, $field, $ins $settings = $display['settings']; $result = array(); - // @todo Optimisation: use hook_field_formatter_prepare_view() to load - // user names or full user entities in 'multiple' mode. - - // Collect the list of user ids. - $uids = array(); - foreach ($items as $delta => $item) { - $uids[$item['uid']] = $item['uid']; - } - + // @todo Optimisation: use hook_field_formatter_prepare_view() to load. + // User names or full user entities in 'multiple' mode. switch ($display['type']) { case 'user_reference_default': case 'user_reference_plain': @@ -439,7 +430,7 @@ function user_reference_field_formatter_view($entity_type, $entity, $field, $ins break; case 'user_reference_user': - $view_mode = $display['settings']['user_reference_view_mode']; + // To prevent infinite recursion caused by reference cycles, we store // diplayed accounts in a recursion queue. $recursion_queue = &drupal_static(__FUNCTION__, array()); @@ -1102,7 +1093,7 @@ function user_reference_field_views_data($field) { $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['uid']; @@ -1152,7 +1143,7 @@ function user_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'); diff --git a/views/references_plugin_style.inc b/views/references_plugin_style.inc index ac93005..4175277 100644 --- a/views/references_plugin_style.inc +++ b/views/references_plugin_style.inc @@ -25,7 +25,7 @@ class references_plugin_style extends views_plugin_style { $results = array(); $this->view->row_index = 0; foreach ($sets as $title => $records) { - foreach ($records as $label => $values) { + foreach ($records as $values) { // Render the row. $rendered = $this->row_plugin->render($values); // Remove linebreaks and extra spaces introduced by templates. From 6378ca9f237ac6b3bdeb7da67f47570fcc1d9bf5 Mon Sep 17 00:00:00 2001 From: nlohar Date: Wed, 14 Jun 2017 12:12:53 -0300 Subject: [PATCH 06/33] Issue #2861031 by nileshlohar, naveenvalecha, Nick_vh, RenatoG: Incorrect file permission on node_reference.module file --- node_reference/node_reference.module | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 node_reference/node_reference.module diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module old mode 100755 new mode 100644 From 83c54fbc16a4e863bfc9cd73cb854147714a7289 Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 15 Jun 2017 11:37:59 -0300 Subject: [PATCH 07/33] Issue #2886520 by RenatoG: Fixed pareview itens for node_reference --- .../node_reference.devel_generate.inc | 18 ++- node_reference/node_reference.module | 127 +++++++++++------- node_reference/node_reference.test | 36 +++-- 3 files changed, 119 insertions(+), 62 deletions(-) diff --git a/node_reference/node_reference.devel_generate.inc b/node_reference/node_reference.devel_generate.inc index d7eacf9..75e1b26 100644 --- a/node_reference/node_reference.devel_generate.inc +++ b/node_reference/node_reference.devel_generate.inc @@ -1,5 +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.") . '

'; @@ -92,14 +94,14 @@ function node_reference_field_settings_form($field, $instance, $has_data) { $form['view']['#element_validate'] = array('_node_reference_view_settings_validate'); $views_options = array('' => '<' . t('none') . '>') + $views_options; - $default = empty($view_settings['view_name']) ? '' : $view_settings['view_name'] . ':' .$view_settings['display_name']; + $default = empty($view_settings['view_name']) ? '' : $view_settings['view_name'] . ':' . $view_settings['display_name']; $form['view']['view_and_display'] = array( '#type' => 'select', '#title' => t('View used to select the nodes'), '#options' => $views_options, '#default_value' => $default, '#description' => '

' . 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('Note:
  • This will discard the "Content types" settings above. Use the view\'s "filters" section instead.
  • Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.
  • Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.
'), + t('Note:
  • This will discard the "Content types" settings above. Use the view\'s "filters" section instead.
  • Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.
  • Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.
'), ); $default = implode(', ', $view_settings['args']); @@ -113,7 +115,7 @@ function node_reference_field_settings_form($field, $instance, $has_data) { } else { $form['view']['no_view_help'] = array( - '#markup' => '

' . 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. @@ -196,12 +203,9 @@ function node_reference_field_validate($entity_type, $entity, $field, $instance, */ function node_reference_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { $checked_ids = &drupal_static(__FUNCTION__, array()); - - /** - * Set an 'access' property on each item (TRUE if the node exists and is - * accessible by the current user). - */ + // 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) { @@ -233,7 +237,7 @@ function node_reference_field_prepare_view($entity_type, $entities, $field, $ins // (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 + // ... AND n.status = 1. $status_condition = db_or() ->condition('n.status', NODE_PUBLISHED); @@ -242,7 +246,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'); @@ -273,7 +281,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']); } @@ -309,7 +317,7 @@ function node_reference_field_formatter_info() { 'field types' => array('node_reference'), 'settings' => array( 'alias' => TRUE, - 'absolute' => FALSE + 'absolute' => FALSE, ), ), ); @@ -338,7 +346,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; @@ -390,11 +398,9 @@ 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. - */ + // 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) { @@ -463,8 +469,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(); @@ -633,8 +640,11 @@ 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) { + // @codingStandardsIgnoreEnd if ($input === FALSE) { // We're building the displayed 'default value': expand the raw nid into // "node title [nid:n]". @@ -717,22 +727,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(); @@ -766,9 +782,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). @@ -777,7 +793,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( @@ -786,8 +802,11 @@ function _node_reference_options($field, $flat = TRUE) { * ), * ... * ) - */ + * + * @codingStandardsIgnoreStart + */ function node_reference_potential_references($field, $options = array()) { + // @codingStandardsIgnoreEnd // Fill in default options. $options += array( 'string' => '', @@ -836,7 +855,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(); } @@ -849,8 +868,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 { @@ -863,7 +882,7 @@ function _node_reference_potential_references_standard($field, $options) { $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); @@ -890,7 +909,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; } @@ -1005,20 +1025,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; @@ -1105,10 +1128,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'; @@ -1188,10 +1213,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, @@ -1208,9 +1241,9 @@ function node_reference_field_views_data_views_data_alter(&$data, $field) { } /** - * '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) { diff --git a/node_reference/node_reference.test b/node_reference/node_reference.test index 54f6c36..a29c363 100644 --- a/node_reference/node_reference.test +++ b/node_reference/node_reference.test @@ -2,13 +2,17 @@ /** * @file - * Initial node_reference tests + * Initial node_reference tests. */ /** * Unit tests for referenceability of node types in entity forms. */ class NodeReferenceFormTest extends FieldTestCase { + + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Node reference', @@ -17,7 +21,10 @@ class NodeReferenceFormTest extends FieldTestCase { ); } - function setUp() { + /** + * Setup. + */ + public function setUp() { parent::setUp(array('node_reference', 'field_test')); $this->langcode = LANGUAGE_NONE; @@ -56,7 +63,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)), @@ -69,13 +79,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]); } @@ -83,26 +93,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->drupalCreateUser(array('create article content', 'access content')); $this->drupalLogin($web_user); @@ -152,4 +161,5 @@ class NodeReferenceFormTest extends FieldTestCase { $this->assertRaw(t('!post %title has been created.', array('!post' => 'Article', '%title' => $edit["title"])), t('Article created.')); $this->assertText($node_long_title->title, t('Referenced node title is displayed.')); } + } From 2db3917662ce714a85d1d537bd398146d50a2a09 Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 15 Jun 2017 15:59:24 -0300 Subject: [PATCH 08/33] Issue #2886594 by RenatoG: Fixed Drupal recomendations for user_reference --- .../user_reference.devel_generate.inc | 11 + user_reference/user_reference.install | 4 +- user_reference/user_reference.module | 221 ++++++++++-------- user_reference/user_reference.test | 4 +- 4 files changed, 143 insertions(+), 97 deletions(-) diff --git a/user_reference/user_reference.devel_generate.inc b/user_reference/user_reference.devel_generate.inc index edf2dac..69115c8 100644 --- a/user_reference/user_reference.devel_generate.inc +++ b/user_reference/user_reference.devel_generate.inc @@ -1,5 +1,13 @@ 'checkboxes', '#title' => t('User roles that can be referenced'), '#default_value' => is_array($settings['referenceable_roles']) - ? array_filter($settings['referenceable_roles']) - : array(), + ? array_filter($settings['referenceable_roles']) + : array(), '#options' => user_roles(TRUE), ); $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 +77,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.") . '

'; @@ -100,14 +100,14 @@ function user_reference_field_settings_form($field, $instance, $has_data) { $form['view']['#element_validate'] = array('_user_reference_view_settings_validate'); $views_options = array('' => '<' . t('none') . '>') + $views_options; - $default = empty($view_settings['view_name']) ? '' : $view_settings['view_name'] . ':' .$view_settings['display_name']; + $default = empty($view_settings['view_name']) ? '' : $view_settings['view_name'] . ':' . $view_settings['display_name']; $form['view']['view_and_display'] = array( '#type' => 'select', '#title' => t('View used to select the users'), '#options' => $views_options, '#default_value' => $default, '#description' => '

' . 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('Note:
  • This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.
  • Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.
  • Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.
'), + t('Note:
  • This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.
  • Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.
  • Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.
'), ); $default = implode(', ', $view_settings['args']); @@ -121,7 +121,7 @@ function user_reference_field_settings_form($field, $instance, $has_data) { } else { $form['view']['no_view_help'] = array( - '#markup' => '

' . t('No eligible view was found.') .'

', + '#markup' => '

' . t('No eligible view was found.') . '

', ); } } @@ -150,7 +150,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 +162,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. @@ -287,7 +292,7 @@ function user_reference_field_formatter_info() { 'field types' => array('user_reference'), 'settings' => array( 'alias' => TRUE, - 'absolute' => FALSE + 'absolute' => FALSE, ), ), ); @@ -315,7 +320,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; @@ -361,7 +366,6 @@ function user_reference_field_formatter_settings_summary($field, $instance, $vie return implode('
', $summary); } - /** * Implements hook_field_formatter_prepare_view(). * @@ -437,8 +441,9 @@ function user_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 accounts 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 accounts 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(); @@ -613,7 +618,7 @@ function user_reference_field_widget_settings_form($field, $instance) { '#required' => TRUE, ); } - return $form; + return $form; } /** @@ -639,8 +644,11 @@ function user_reference_field_widget_form(&$form, &$form_state, $field, $instanc * Value callback for a user_reference autocomplete element. * * Substitute in the user name for the uid. + * + * @codingStandardsIgnoreStart */ function user_reference_autocomplete_value($element, $input = FALSE, $form_state) { + // @codingStandardsIgnoreEnd if ($input === FALSE) { // We're building the displayed 'default value': expand the raw uid into // "user name [uid:n]". @@ -719,19 +727,25 @@ function user_reference_field_widget_error($element, $error, $form, &$form_state } /** - * Builds a list of referenceable users suitable for the '#option' FAPI property. + * Options. + * + * Builds a list of referenceable users suitable for the '#option' FAPI + * property. * * Warning: the function does NOT take care of encoding or escaping the user * names. 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. * - * @return + * @return array * An array of referenceable user names, keyed by user id. + * + * @codingStandardsIgnoreStart */ function _user_reference_options($field, $flat = TRUE) { + // @codingStandardsIgnoreEnd $references = user_reference_potential_references($field); $options = array(); @@ -763,9 +777,9 @@ function _user_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). @@ -774,7 +788,7 @@ function _user_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 users in the form: * array( * uid => array( @@ -783,8 +797,11 @@ function _user_reference_options($field, $flat = TRUE) { * ), * ... * ) + * + * @codingStandardsIgnoreStart */ function user_reference_potential_references($field, $options = array()) { + // @codingStandardsIgnoreEnd // Fill in default options. $options += array( 'string' => '', @@ -870,7 +887,8 @@ function _user_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('u.name', $options['string'], '='); break; } @@ -900,7 +918,10 @@ function _user_reference_potential_references_standard($field, $options) { } /** - * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users + * Menu callback. + * + * Retrieve a pipe delimited string of autocomplete suggestions for existing + * users. */ function user_reference_autocomplete($entity_type, $bundle, $field_name, $string = '') { $instance = field_info_instance($entity_type, $field_name, $bundle); @@ -936,77 +957,81 @@ function user_reference_options_list($field) { */ /*function user_reference_user_load($accounts) { - // Only add links if we are on the user 'view' page. - if (arg(0) != 'user' || arg(2)) { - return; - } +// Only add links if we are on the user 'view' page. +if (arg(0) != 'user' || arg(2)) { +return; +} - foreach ($accounts as $uid => $account) { - - // find CCK user_reference field tables - // search through them for matching user ids and load those nodes - $additions = array(); - $fields = field_info_instances('user'); - - // TODO : replace with field_attach_query() + synchronize with latest D6 code. - - // Find the table and columns to search through, if the same - // table comes up in more than one field type, we only need - // to search it once. - $search_tables = array(); - $search_links = array(); - foreach ($fields as $field) { - if ($field['type'] == 'user_reference' && !empty($field['widget']['reverse_link'])) { - $db_info = content_database_info($field); - $search_tables[$db_info['table']] = $db_info['columns']['uid']['column']; - $search_links[$db_info['table']] = $field['widget']['reverse_link']; - } - } - foreach ($search_tables as $table => $column) { - $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1")); - while ($data = db_fetch_object($ids)) { - // TODO, do we really want a complete node_load() here? We only need the title to create a link. - $node = node_load($data->nid); - $node->reverse_link = $search_links[$table]; - $additions[$node->type][] = $node; - } - } - $accounts[$uid]->user_reference = $additions; - } - return; +foreach ($accounts as $uid => $account) { + +// find CCK user_reference field tables +// search through them for matching user ids and load those nodes +$additions = array(); +$fields = field_info_instances('user'); + +// TODO : replace with field_attach_query() + synchronize with latest D6 code. + +// Find the table and columns to search through, if the same +// table comes up in more than one field type, we only need +// to search it once. +$search_tables = array(); +$search_links = array(); +foreach ($fields as $field) { +if ($field['type'] == 'user_reference' +&& !empty($field['widget']['reverse_link'])) { +$db_info = content_database_info($field); +$search_tables[$db_info['table']] = $db_info['columns']['uid']['column']; +$search_links[$db_info['table']] = $field['widget']['reverse_link']; +} +} +foreach ($search_tables as $table => $column) { +$ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n +LEFT JOIN {". $table ."} f ON n.vid = f.vid +WHERE f.". $column ."=". $account->uid. " AND n.status = 1")); +while ($data = db_fetch_object($ids)) { +// TODO, do we really want a complete node_load() here? We only need the title +// to create a link. +$node = node_load($data->nid); +$node->reverse_link = $search_links[$table]; +$additions[$node->type][] = $node; +} +} +$accounts[$uid]->user_reference = $additions; +} +return; }*/ /** * Implementation of hook_user_view(). */ /*function user_reference_user_view($account, $view_mode, $langcode) { - if (!empty($account->user_reference)) { - $node_types = content_types(); - $additions = array(); - $values = array(); - foreach ($account->user_reference as $node_type => $nodes) { - foreach ($nodes as $node) { - if ($node->reverse_link) { - $values[$node_type][] = l($node->title, 'node/' . $node->nid); - } - } - if (isset($values[$node_type])) { - $additions[] = array( - '#type' => 'user_profile_item', - '#title' => check_plain($node_types[$node_type]['name']), - '#value' => theme('item_list', $values[$node_type]), - ); - } - } - if ($additions) { - $account->content['user_reference'] = $additions + array( - '#type' => 'user_profile_category', - '#attributes' => array('class' => array('user-member')), - '#title' => t('Related content'), - '#weight' => 10, - ); - } - } +if (!empty($account->user_reference)) { +$node_types = content_types(); +$additions = array(); +$values = array(); +foreach ($account->user_reference as $node_type => $nodes) { +foreach ($nodes as $node) { +if ($node->reverse_link) { +$values[$node_type][] = l($node->title, 'node/' . $node->nid); +} +} +if (isset($values[$node_type])) { +$additions[] = array( +'#type' => 'user_profile_item', +'#title' => check_plain($node_types[$node_type]['name']), +'#value' => theme('item_list', $values[$node_type]), +); +} +} +if ($additions) { +$account->content['user_reference'] = $additions + array( +'#type' => 'user_profile_category', +'#attributes' => array('class' => array('user-member')), +'#title' => t('Related content'), +'#weight' => 10, +); +} +} }*/ /** @@ -1068,10 +1093,12 @@ function user_reference_content_migrate_instance_alter(&$instance_value, $field_ $instance_value['widget']['type'] = 'user_reference_autocomplete'; $instance_value['widget']['module'] = 'user_reference'; break; + case 'userreference_select': $instance_value['widget']['type'] = 'options_select'; $instance_value['widget']['module'] = 'options'; break; + case 'userreference_buttons': $instance_value['widget']['type'] = 'options_buttons'; $instance_value['widget']['module'] = 'options'; @@ -1151,10 +1178,18 @@ function user_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['users'][$pseudo_field_name]['relationship'] = array( 'title' => $title, @@ -1171,12 +1206,12 @@ function user_reference_field_views_data_views_data_alter(&$data, $field) { } /** - * '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. * - * @return + * @return array * The array of allowed options for the filter. */ function user_reference_views_filter_options($field_name) { diff --git a/user_reference/user_reference.test b/user_reference/user_reference.test index d98019d..e628c2a 100644 --- a/user_reference/user_reference.test +++ b/user_reference/user_reference.test @@ -2,5 +2,5 @@ /** * @file - * Placeholder for the development of user_reference tests - */ \ No newline at end of file + * Placeholder for the development of user_reference tests. + */ From b8569cd1fde65f2c87516ee04667997de74d81b6 Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 15 Jun 2017 16:36:11 -0300 Subject: [PATCH 09/33] Issue #2886602 by RenatoG: Create help section for CMS user can understand how it works. --- references.module | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/references.module b/references.module index c925c29..c663baa 100644 --- a/references.module +++ b/references.module @@ -208,3 +208,22 @@ function references_potential_references_view($entity_type, $view_name, $display return $results; } + +/** + * Implements hook_help(). + */ +function references_help($path, $arg) { + + switch ($path) { + case 'admin/help#references': + $output = '

' . t('About') . '

'; + $output .= '

' . t('The References project contains straight ports of the node_reference and user_reference modules to the Drupal 7 API.') . '

'; + $output .= '

' . t('Usage') . '

'; + $output .= '
    '; + $output .= '
  • ' . t('Access: Structure » Content types and edit one Content type.') . '
  • '; + $output .= '
  • ' . t('Go to Manage Fields and add new field with field type = "Node Reference" or "User Reference".') . '
  • '; + $output .= '
  • ' . t('Access onde with this type and see new field with reference.') . '
  • '; + $output .= '
'; + return $output; + } +} From 33b1ec51b87e3b61f03b67d7fe3038fc935c779b Mon Sep 17 00:00:00 2001 From: renatog Date: Mon, 19 Jun 2017 16:50:10 -0300 Subject: [PATCH 10/33] Issue #2887444 by RenatoG: Fixed itens in references_plugin_style.inc and references_plugin_display.inc --- views/references_plugin_display.inc | 49 ++++++++++++++++++++++++----- views/references_plugin_style.inc | 16 ++++++++-- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/views/references_plugin_display.inc b/views/references_plugin_display.inc index 9ba3c8e..e56f16c 100644 --- a/views/references_plugin_display.inc +++ b/views/references_plugin_display.inc @@ -4,9 +4,22 @@ * @file * Handler for references_plugin_display. */ -class references_plugin_display extends views_plugin_display { - function option_definition() { +/** + * Default class. + * + * @codingStandardsIgnoreStart + */ +class references_plugin_display extends views_plugin_display { + //@codingStandardsIgnoreEnd + + /** + * Option Definition. + * + * @codingStandardsIgnoreStart + */ + public function option_definition() { + // @codingStandardsIgnoreEnd $options = parent::option_definition(); // Force the style plugin to 'references_style' and the row plugin to @@ -25,26 +38,47 @@ class references_plugin_display extends views_plugin_display { return $options; } - function get_style_type() { + /** + * Style type. + * + * @codingStandardsIgnoreStart + */ + public function get_style_type() { + // @codingStandardsIgnoreEnd return 'references'; } - function execute() { + /** + * Execute. + */ + public function execute() { return $this->view->render($this->display->id); } - function render() { + /** + * Render. + */ + public function render() { if (!empty($this->view->result) || !empty($this->view->style_plugin->definition['even empty'])) { return $this->view->style_plugin->render($this->view->result); } return ''; } - function uses_exposed() { + /** + * Uses exposed. + * + * @codingStandardsIgnoreStart + */ + public function uses_exposed() { + // @codingStandardsIgnoreEnd return FALSE; } - function query() { + /** + * Query. + */ + public function query() { $options = $this->get_option('references_options'); // Play nice with View UI 'preview' : if the view is not executed through @@ -85,4 +119,5 @@ class references_plugin_display extends views_plugin_display { $this->view->query->add_where(NULL, $table_alias . '.' . $this->view->base_field, $options['ids'], 'IN'); } } + } diff --git a/views/references_plugin_style.inc b/views/references_plugin_style.inc index 4175277..bea1cba 100644 --- a/views/references_plugin_style.inc +++ b/views/references_plugin_style.inc @@ -4,8 +4,19 @@ * @file * Handler for references_plugin_style. */ -class references_plugin_style extends views_plugin_style { - function render() { + +/** + * Class to plugin style. + * + * @codingStandardsIgnoreStart + */ +class references_plugin_style extends views_plugin_style { + // @codingStandardsIgnoreEnd + + /** + * Render. + */ + public function render() { $options = $this->display->handler->get_option('references_options'); // Play nice with View UI 'preview' : if the view is not executed through @@ -45,4 +56,5 @@ class references_plugin_style extends views_plugin_style { return $results; } + } From 1a2979f7378895b5ef69a209c75a06f436b1a857 Mon Sep 17 00:00:00 2001 From: renatog Date: Mon, 19 Jun 2017 16:55:53 -0300 Subject: [PATCH 11/33] Issue #2887444 by RenatoG: Fixed itens in references_plugin_style.inc and references_plugin_display.inc --- views/references_plugin_display.inc | 49 ++++++++++++++++++++++++----- views/references_plugin_style.inc | 16 ++++++++-- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/views/references_plugin_display.inc b/views/references_plugin_display.inc index 9ba3c8e..e56f16c 100644 --- a/views/references_plugin_display.inc +++ b/views/references_plugin_display.inc @@ -4,9 +4,22 @@ * @file * Handler for references_plugin_display. */ -class references_plugin_display extends views_plugin_display { - function option_definition() { +/** + * Default class. + * + * @codingStandardsIgnoreStart + */ +class references_plugin_display extends views_plugin_display { + //@codingStandardsIgnoreEnd + + /** + * Option Definition. + * + * @codingStandardsIgnoreStart + */ + public function option_definition() { + // @codingStandardsIgnoreEnd $options = parent::option_definition(); // Force the style plugin to 'references_style' and the row plugin to @@ -25,26 +38,47 @@ class references_plugin_display extends views_plugin_display { return $options; } - function get_style_type() { + /** + * Style type. + * + * @codingStandardsIgnoreStart + */ + public function get_style_type() { + // @codingStandardsIgnoreEnd return 'references'; } - function execute() { + /** + * Execute. + */ + public function execute() { return $this->view->render($this->display->id); } - function render() { + /** + * Render. + */ + public function render() { if (!empty($this->view->result) || !empty($this->view->style_plugin->definition['even empty'])) { return $this->view->style_plugin->render($this->view->result); } return ''; } - function uses_exposed() { + /** + * Uses exposed. + * + * @codingStandardsIgnoreStart + */ + public function uses_exposed() { + // @codingStandardsIgnoreEnd return FALSE; } - function query() { + /** + * Query. + */ + public function query() { $options = $this->get_option('references_options'); // Play nice with View UI 'preview' : if the view is not executed through @@ -85,4 +119,5 @@ class references_plugin_display extends views_plugin_display { $this->view->query->add_where(NULL, $table_alias . '.' . $this->view->base_field, $options['ids'], 'IN'); } } + } diff --git a/views/references_plugin_style.inc b/views/references_plugin_style.inc index 4175277..bea1cba 100644 --- a/views/references_plugin_style.inc +++ b/views/references_plugin_style.inc @@ -4,8 +4,19 @@ * @file * Handler for references_plugin_style. */ -class references_plugin_style extends views_plugin_style { - function render() { + +/** + * Class to plugin style. + * + * @codingStandardsIgnoreStart + */ +class references_plugin_style extends views_plugin_style { + // @codingStandardsIgnoreEnd + + /** + * Render. + */ + public function render() { $options = $this->display->handler->get_option('references_options'); // Play nice with View UI 'preview' : if the view is not executed through @@ -45,4 +56,5 @@ class references_plugin_style extends views_plugin_style { return $results; } + } From 335777b7015aa4eec93cc90f64c871043670da2f Mon Sep 17 00:00:00 2001 From: renatog Date: Tue, 20 Jun 2017 12:33:19 -0300 Subject: [PATCH 12/33] Issue #2887799 by RenatoG: Fixed pareview itens for inc files --- CHANGELOG.txt | 11 +++++---- references_uuid/references_uuid.info | 1 + views/references_handler_argument.inc | 14 +++++++++-- views/references_handler_relationship.inc | 30 +++++++++++++++++++---- views/references_plugin_row_fields.inc | 28 ++++++++++++++++++--- 5 files changed, 68 insertions(+), 16 deletions(-) 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/references_uuid/references_uuid.info b/references_uuid/references_uuid.info index 67a32e3..6d61ad8 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 package = Fields dependencies[] = references diff --git a/views/references_handler_argument.inc b/views/references_handler_argument.inc index d9fc1b5..5f91712 100644 --- a/views/references_handler_argument.inc +++ b/views/references_handler_argument.inc @@ -4,12 +4,21 @@ * @file * Provide handler to replace reference with title. */ + +/** + * Default class for handler argument. + * + * @codingStandardsIgnoreStart + */ class references_handler_argument extends views_handler_argument_numeric { /** - * Use entity title for % placeholders in argument titles. + * Use entity title for % placeholders in argument titles. + * + * @codingStandardsIgnoreStart */ - function title_query() { + public function title_query() { + // @codingStandardsIgnoreEnd // Use the same table and field than those used for summary lists // ('name table', 'name field'). $table_data = views_fetch_data($this->name_table); @@ -36,4 +45,5 @@ class references_handler_argument extends views_handler_argument_numeric { return $titles; } + } diff --git a/views/references_handler_relationship.inc b/views/references_handler_relationship.inc index 792ba3a..fcbefe2 100644 --- a/views/references_handler_relationship.inc +++ b/views/references_handler_relationship.inc @@ -4,9 +4,19 @@ * @file * Provide relationship handler for reference fields. */ + +/** + * Default class for handler relationship. + * + * @codingStandardsIgnoreStart + */ class references_handler_relationship extends views_handler_relationship { - function option_definition() { + /** + * Option Definition. + */ + public function option_definition() { + // @codingStandardsIgnoreEnd $options = parent::option_definition(); $options['delta'] = array('default' => -1); @@ -15,12 +25,15 @@ class references_handler_relationship extends views_handler_relationship { /** * Add a delta selector for multiple fields. + * + * @codingStandardsIgnoreStart */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { + // @codingStandardsIgnoreEnd parent::options_form($form, $form_state); $field = field_info_field($this->definition['field_name']); - + // Only add the delta selector if the field is multiple. if ($field['cardinality']) { $max_delta = ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) ? 10 : $field['cardinality']; @@ -39,9 +52,15 @@ class references_handler_relationship extends views_handler_relationship { } } - function ensure_my_table() { + /** + * Function to ensure my table. + * + * @codingStandardsIgnoreStart + */ + public function ensure_my_table() { + // @codingStandardsIgnoreEnd $field = field_info_field($this->definition['field_name']); - + if (!isset($this->table_alias)) { $join = $this->get_join(); if ($this->options['delta'] != -1 && $field['cardinality']) { @@ -55,4 +74,5 @@ class references_handler_relationship extends views_handler_relationship { } return $this->table_alias; } + } diff --git a/views/references_plugin_row_fields.inc b/views/references_plugin_row_fields.inc index 24d5e96..b3f2fb9 100644 --- a/views/references_plugin_row_fields.inc +++ b/views/references_plugin_row_fields.inc @@ -4,9 +4,19 @@ * @file * Handler for references_plugin_row_fields. */ + +/** + * Default class for plugin row fields. + * + * @codingStandardsIgnoreStart + */ class references_plugin_row_fields extends views_plugin_row_fields { - function option_definition() { + /** + * Option Definition. + */ + public function option_definition() { + // @codingStandardsIgnoreEnd $options = parent::option_definition(); $options['separator'] = array('default' => '-'); @@ -16,15 +26,24 @@ class references_plugin_row_fields extends views_plugin_row_fields { /** * Provide a form for setting options. + * + * @codingStandardsIgnoreStart */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { + // @codingStandardsIgnoreEnd parent::options_form($form, $form_state); // Expand the description of the 'Inline field' checkboxes. - $form['inline']['#description'] .= '
' . t("Note: In 'References' displays, all fields will be displayed inline unless an explicit selection of inline fields is made here." ); + $form['inline']['#description'] .= '
' . t("Note: In 'References' displays, all fields will be displayed inline unless an explicit selection of inline fields is made here."); } - function pre_render($row) { + /** + * Pre Render. + * + * @codingStandardsIgnoreStart + */ + public function pre_render($row) { + // @codingStandardsIgnoreEnd // Force all fields to be inline by default. if (empty($this->options['inline'])) { $fields = $this->view->get_items('field', $this->display->id); @@ -33,4 +52,5 @@ class references_plugin_row_fields extends views_plugin_row_fields { return parent::pre_render($row); } + } From 909407d3b2ea6b60b9b7ef2cb90d962b95e66d51 Mon Sep 17 00:00:00 2001 From: jenlampton Date: Thu, 6 Jul 2017 10:01:52 -0300 Subject: [PATCH 13/33] Issue #1345920 by jenlampton, grendzy, RenatoG, wuinfo, igormoreira: Add a limit to the number of results in _node_reference_options() --- node_reference/node_reference.module | 2 +- references.module | 6 +----- user_reference/user_reference.module | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 83601b6..d8508fd 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -812,7 +812,7 @@ function node_reference_potential_references($field, $options = array()) { 'string' => '', 'match' => 'contains', 'ids' => array(), - 'limit' => 0, + 'limit' => 25, ); $results = &drupal_static(__FUNCTION__, array()); diff --git a/references.module b/references.module index c663baa..71e06cd 100644 --- a/references.module +++ b/references.module @@ -196,11 +196,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/user_reference/user_reference.module b/user_reference/user_reference.module index ad5f61b..02b3919 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -807,7 +807,7 @@ function user_reference_potential_references($field, $options = array()) { 'string' => '', 'match' => 'contains', 'ids' => array(), - 'limit' => 0, + 'limit' => 25, ); $results = &drupal_static(__FUNCTION__, array()); From d34db68f195fb70ff8c95d81944e5126a4393a0e Mon Sep 17 00:00:00 2001 From: attiks Date: Thu, 6 Jul 2017 10:17:55 -0300 Subject: [PATCH 14/33] Issue #1818868 by attiks, RenatoG, jenlampton: Only link to account if user may view the profile --- user_reference/user_reference.module | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/user_reference/user_reference.module b/user_reference/user_reference.module index 02b3919..5977ff9 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -417,12 +417,20 @@ function user_reference_field_formatter_view($entity_type, $entity, $field, $ins $label = entity_label('user', $user); if ($display['type'] == 'user_reference_default') { $uri = entity_uri('user', $user); - $result[$delta] = array( - '#type' => 'link', - '#title' => $label, - '#href' => $uri['path'], - '#options' => $uri['options'], - ); + $router_item = menu_get_item($uri['path']); + if ($router_item && $router_item['access']) { + $result[$delta] = array( + '#type' => 'link', + '#title' => $label, + '#href' => $uri['path'], + '#options' => $uri['options'], + ); + } + else { + $result[$delta] = array( + '#markup' => check_plain($label), + ); + } } else { $result[$delta] = array( From b82cc47a27d7516feb003e684077829d82b2ef92 Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 6 Jul 2017 12:09:47 -0300 Subject: [PATCH 15/33] Issue #2892787 by RenatoG: [Code Review] Translatable strings must not begin or end with white spaces, use placeholders with t() for variables --- references.feeds.inc | 142 +++++++++++++++---------- references.module | 37 ++++--- references_uuid/references_uuid.module | 3 +- 3 files changed, 106 insertions(+), 76 deletions(-) diff --git a/references.feeds.inc b/references.feeds.inc index 8300e9b..baac669 100644 --- a/references.feeds.inc +++ b/references.feeds.inc @@ -1,11 +1,15 @@ feed_nid)) { $results = array(); $field = substr($key, 22); @@ -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'; @@ -244,12 +270,12 @@ function references_feeds_set_target($source, $entity, $target, $value) { // Lookup potential exact matches for the value (limit to one result). $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'])) { - drupal_set_message(t('%title does not match an existing ' . $typename, array('%title' => $options['string']))); + drupal_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'])) { - drupal_set_message(t('%id is not a valid ' . $typename. ' id for this field.', array('%id' => $options['string']))); + drupal_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'])) { - drupal_set_message(t('%id is not a valid ' . $typename . ' id for this field.', array('%id' => $v))); + drupal_set_message(t('%id is not a valid @typename id for this field.', array('%id' => $v, '@typename' => $typename))); } break; } diff --git a/references.module b/references.module index 71e06cd..98c3419 100644 --- a/references.module +++ b/references.module @@ -94,12 +94,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) { @@ -124,29 +127,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. @@ -157,7 +163,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(); } @@ -169,13 +175,10 @@ function references_potential_references_view($entity_type, $view_name, $display $view->set_display($display_name); - /** - * @todo From merlinofchaos on IRC : arguments using summary view can defeat - * the style setting. - * We might also need to check if there's an argument, and set its - * style_plugin as well. - */ - + // @todo From merlinofchaos on IRC : arguments using summary view can defeat + // 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( 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 @@ Date: Thu, 6 Jul 2017 16:42:30 -0300 Subject: [PATCH 16/33] Issue #2892835 by RenatoG: Select all/none roles in Field Settings of User References --- js/references.admin.js | 19 +++++++++++++++++++ user_reference/user_reference.module | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 js/references.admin.js diff --git a/js/references.admin.js b/js/references.admin.js new file mode 100644 index 0000000..659f949 --- /dev/null +++ b/js/references.admin.js @@ -0,0 +1,19 @@ +/** + * @file + * JavaScript for References Admin Pages. + */ + +(function ($) { + Drupal.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/user_reference/user_reference.module b/user_reference/user_reference.module index 5977ff9..f559250 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -50,8 +50,17 @@ function user_reference_field_info() { * Implements hook_field_settings_form(). */ function user_reference_field_settings_form($field, $instance, $has_data) { + + $path = drupal_get_path('module', 'references'); + + drupal_add_js($path . '/js/references.admin.js'); + $settings = $field['settings']; + $options['user_reference_config_select_all_roles'] = t('Select all/none'); + + $options = ($options + user_roles(TRUE)); + $form = array(); $form['referenceable_roles'] = array( '#type' => 'checkboxes', @@ -59,7 +68,7 @@ function user_reference_field_settings_form($field, $instance, $has_data) { '#default_value' => is_array($settings['referenceable_roles']) ? array_filter($settings['referenceable_roles']) : array(), - '#options' => user_roles(TRUE), + '#options' => $options, ); $form['referenceable_status'] = array( '#type' => 'checkboxes', From c74202fc5ae5205b44c20924d6048f9492e5da14 Mon Sep 17 00:00:00 2001 From: Zombienaute Date: Fri, 7 Jul 2017 10:15:25 -0300 Subject: [PATCH 17/33] Issue #1423682 by acbramley, Dmitriy.trt, coredumperror, yched, RenatoG, Alex Andrascu: Allowing override of node_reference and user_reference autocomplete field limits --- node_reference/node_reference.module | 22 +++++++++++++++++++++- user_reference/user_reference.module | 22 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index d8508fd..7f27dc8 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -568,6 +568,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', ), @@ -604,6 +605,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' => drupal_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'), @@ -949,7 +969,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); diff --git a/user_reference/user_reference.module b/user_reference/user_reference.module index f559250..935499d 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -592,6 +592,7 @@ function user_reference_field_widget_info() { 'field types' => array('user_reference'), 'settings' => array( 'autocomplete_match' => 'contains', + 'limit' => 10, 'size' => 60, 'autocomplete_path' => 'user_reference/autocomplete', ), @@ -627,6 +628,25 @@ function user_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 users.'), ); + $form['limit'] = array( + '#type' => 'select', + '#title' => t('Dropdown limit'), + '#options' => drupal_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'), @@ -947,7 +967,7 @@ function user_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 = user_reference_potential_references($field, $options); From d8567b3e8ca6d80fd3edfb21bceb7254a6ddccde Mon Sep 17 00:00:00 2001 From: mh86 Date: Fri, 7 Jul 2017 10:22:44 -0300 Subject: [PATCH 18/33] Issue #1249268 by mh86, John Franklin, Aron Novak, chalee, Sinan Erdem, Jason Dean, chrisroditis, tim.plunkett, wozzz7, aaron.r.carlton, RenatoG, Ramdas Gaikar, newswatch, charlie-s, Alex Andrascu: Undefined index: access in node_reference_field_formatter_view() --- node_reference/node_reference.module | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 7f27dc8..ca67f2e 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -406,7 +406,7 @@ 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']) { + if (!empty($item['access'])) { $ids[$item['nid']] = $item['nid']; } } @@ -418,7 +418,7 @@ 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']) { + if (!empty($item['access'])) { $items[$id][$delta]['node'] = $entities[$item['nid']]; } } @@ -437,7 +437,7 @@ 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']) { + if (!empty($item['access'])) { $node = $item['node']; $label = entity_label('node', $node); if ($display['type'] == 'node_reference_default') { @@ -487,7 +487,7 @@ 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']])) { + if (!empty($item['access']) && !isset($recursion_queue[$item['nid']])) { $nodes_display[$item['nid']] = $item['node']; } } @@ -503,7 +503,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']]; } @@ -528,7 +528,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'], ); @@ -538,7 +538,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'], From df12780a5da01d10b48e301fdff275f0602e1bf2 Mon Sep 17 00:00:00 2001 From: oschaetzke Date: Fri, 7 Jul 2017 12:02:07 -0300 Subject: [PATCH 19/33] Issue #2010572 by kleinmp, RenatoG, oschaetzke, jenlampton: Undefined index: nid in node_reference_field_formatter_view() (line 481 of [..]/sites/all/modules/_basic/references/node_referen --- node_reference/node_reference.module | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index ca67f2e..e726833 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -438,7 +438,14 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins case 'node_reference_plain': foreach ($items as $delta => $item) { if (!empty($item['access'])) { - $node = $item['node']; + + 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); @@ -488,7 +495,12 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins $nodes_display = array(); foreach ($items as $delta => $item) { if (!empty($item['access']) && !isset($recursion_queue[$item['nid']])) { - $nodes_display[$item['nid']] = $item['node']; + if (!empty($item['node'])) { + $nodes_display[$item['nid']] = $item['node']; + } + else { + $nodes_display[$item['nid']] = node_load($item['nid']); + } } } From 3ae6434a74e0e32b1fdac251b3ef22566217e555 Mon Sep 17 00:00:00 2001 From: "kenneth.venken" Date: Fri, 7 Jul 2017 13:06:07 -0300 Subject: [PATCH 20/33] Issue #1535716 by kenneth.venken, RenatoG, alfaguru, gauravjeet: Workbench moderation 'all unpublished content' permission support. --- node_reference/node_reference.module | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index e726833..6480f6c 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -234,9 +234,10 @@ 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')) { + // '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); From 3b89238ea2862730a93f6d083360e17d4bc05fbb Mon Sep 17 00:00:00 2001 From: rfay Date: Tue, 11 Jul 2017 14:38:04 -0300 Subject: [PATCH 21/33] Issue #1462976 by rfay, StephenRobinson, jbeall, manoloka, RenatoG: Warning: array_filter() [function.array-filter]: The first argument should be an array --- user_reference/user_reference.module | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/user_reference/user_reference.module b/user_reference/user_reference.module index 935499d..6c9e2e8 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -889,7 +889,13 @@ function _user_reference_potential_references_views($field, $options) { function _user_reference_potential_references_standard($field, $options) { // Avoid useless work. $filter_roles = array_filter($field['settings']['referenceable_roles']); - $filter_status = array_filter($field['settings']['referenceable_status']); + // $field['settings']['referenceable_status'] may be an int/boolean on D6 + // upgraded sites + $filter_status = array(); + if (is_array($field['settings']['referenceable_status'])) { + // Selects only items in array that are not empty (true, 1, string, etc.) + $filter_status = array_filter($field['settings']['referenceable_status']); + } if (!count($filter_status) && !count($filter_roles)) { return array(); } From 85bbef808a96c6088969fa223ebedc435dc4fabb Mon Sep 17 00:00:00 2001 From: pfrenssen Date: Tue, 11 Jul 2017 16:47:17 -0300 Subject: [PATCH 22/33] Issue #1724132 by pfrenssen, RenatoG: Provide a function to easily retrieve references from nodes --- node_reference/node_reference.module | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 6480f6c..b4f52ac 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -1297,3 +1297,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; +} From d0772fb6d2707cfa5a47c5e7239bc082841b38bd Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 27 Jul 2017 17:45:49 -0300 Subject: [PATCH 23/33] Issue #2715469 by RenatoG, davidwbarratt: Warning: Invalid argument supplied for foreach() in node_reference_field_prepare_view() --- node_reference/node_reference.module | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index b4f52ac..cf2b961 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -208,13 +208,15 @@ function node_reference_field_prepare_view($entity_type, $entities, $field, $ins // 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']; + } } } } From 9747344e5d489882b0acf3885e4c32c92f78a5cd Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 27 Jul 2017 17:51:56 -0300 Subject: [PATCH 24/33] Issue #2575343 by RenatoG, phandolin: Undefined index: access in node_reference_node_reference_field_formatter_prepare_view() --- node_reference/node_reference.module | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index cf2b961..1e01b8d 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -409,6 +409,7 @@ 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) { + // Checking item 'access' before the use. if (!empty($item['access'])) { $ids[$item['nid']] = $item['nid']; } @@ -421,6 +422,7 @@ 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) { + // Checking item 'access' before the use. if (!empty($item['access'])) { $items[$id][$delta]['node'] = $entities[$item['nid']]; } From 0b72aa3d5dcae77cbeca198ab43d9c9b097d1620 Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 27 Jul 2017 18:46:07 -0300 Subject: [PATCH 25/33] Issue #2297511 by RenatoG, paullwolborsky: Notice: Undefined index: node in node_reference_field_formatter_view() --- node_reference/node_reference.module | 1 + 1 file changed, 1 insertion(+) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 1e01b8d..903e4ce 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -444,6 +444,7 @@ function node_reference_field_formatter_view($entity_type, $entity, $field, $ins foreach ($items as $delta => $item) { if (!empty($item['access'])) { + // Checking if exists the node. If not exists use node_load to load. if (!empty($item['node'])) { $node = $item['node']; } From 1b0bcb060aede97825e5fce15847ba2e37fd8a5d Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 27 Jul 2017 19:28:10 -0300 Subject: [PATCH 26/33] Issue #1679350 by RenatoG, jfha73: Warnings showing up --- user_reference/user_reference.module | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/user_reference/user_reference.module b/user_reference/user_reference.module index 6c9e2e8..162c436 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -887,8 +887,14 @@ function _user_reference_potential_references_views($field, $options) { * List of referenceable users defined by user role and status. */ function _user_reference_potential_references_standard($field, $options) { + + $filter_roles = array(); + // Avoid useless work. - $filter_roles = array_filter($field['settings']['referenceable_roles']); + if (is_array($field['settings']['referenceable_roles'])) { + $filter_roles = array_filter($field['settings']['referenceable_roles']); + } + // $field['settings']['referenceable_status'] may be an int/boolean on D6 // upgraded sites $filter_status = array(); From 5087577cf4dfbd7925663e2fed663fafa3e58b83 Mon Sep 17 00:00:00 2001 From: scito Date: Thu, 27 Jul 2017 19:51:53 -0300 Subject: [PATCH 27/33] Issue #1468856 by scito, RenatoG: Notice: Undefined index: sql in node_reference_field_views_data() (node_reference.module) --- node_reference/node_reference.module | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 903e4ce..4a07c7e 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -1190,8 +1190,11 @@ 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 $table_data) { $table = key($table_data); From 1986e62b1c3de59161b825364c18f08b2000bf9b Mon Sep 17 00:00:00 2001 From: fcaminada Date: Tue, 3 Apr 2018 17:33:14 -0300 Subject: [PATCH 28/33] Issue #2923099 by caminadaf, RenatoG: Warning (error on PHP7) when using devel_generate with multi-valued field --- user_reference/user_reference.devel_generate.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_reference/user_reference.devel_generate.inc b/user_reference/user_reference.devel_generate.inc index 69115c8..5ecbed6 100644 --- a/user_reference/user_reference.devel_generate.inc +++ b/user_reference/user_reference.devel_generate.inc @@ -10,7 +10,7 @@ */ function user_reference_devel_generate($object, $field, $instance, $bundle) { if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) { - return devel_generate_multiple('_user_reference_devel_generate', $object, $field); + return devel_generate_multiple('_user_reference_devel_generate', $object, $field, $instance, $bundle); } else { return _user_reference_devel_generate($object, $field); From a7ad6b794f72dd4e669706b64bd8d6f1612cc0b4 Mon Sep 17 00:00:00 2001 From: renatog Date: Thu, 19 Apr 2018 11:55:31 -0300 Subject: [PATCH 29/33] Issue #2962410 by RenatoG: Resolve ESLint for JavaScript with Drupal Behaviors --- js/references.admin.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/references.admin.js b/js/references.admin.js index 659f949..5d396a1 100644 --- a/js/references.admin.js +++ b/js/references.admin.js @@ -4,14 +4,17 @@ */ (function ($) { + + 'use strict'; + Drupal.behaviors.referencesAdmin = { attach: function (context, settings) { - var config_check_uncheck_all_roles = jQuery("input:checkbox[value=user_reference_config_select_all_roles]", context); + 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 () { + jQuery(config_check_uncheck_all_roles).on('click', function () { role_options.not(this).prop('checked', this.checked); }); } From 95d57235afbaba1bf81f655fde061d91b063dcda Mon Sep 17 00:00:00 2001 From: git Date: Sun, 29 Jul 2018 06:18:54 -0300 Subject: [PATCH 30/33] Issue #2970956 by Louis Delacretaz: Could be wrong variable $user in user_reference_field_formatter_view --- user_reference/user_reference.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_reference/user_reference.module b/user_reference/user_reference.module index 162c436..da025b9 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -896,7 +896,7 @@ function _user_reference_potential_references_standard($field, $options) { } // $field['settings']['referenceable_status'] may be an int/boolean on D6 - // upgraded sites + // upgraded sites. $filter_status = array(); if (is_array($field['settings']['referenceable_status'])) { // Selects only items in array that are not empty (true, 1, string, etc.) From 970a8198e039f4bbbd13cb6ce919c040ae96ee56 Mon Sep 17 00:00:00 2001 From: thallesvf Date: Tue, 21 May 2019 13:58:06 -0300 Subject: [PATCH 31/33] Issue #3056127 by thalles: Rename README.txt to README.md --- README.txt => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.txt => README.md (100%) diff --git a/README.txt b/README.md similarity index 100% rename from README.txt rename to README.md From 7c0b4da4db7b90458429a1a27696a1a17cbb50cf Mon Sep 17 00:00:00 2001 From: DaveKopecek Date: Mon, 12 Apr 2021 22:00:42 -0300 Subject: [PATCH 32/33] Issue #1578768 by Dave Kopecek, DigitalFrontiersMedia, czigor, Chris Matthews, RenatoG: Backreference in views breaks when referenced field used in multiple bundle types --- node_reference/node_reference.module | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 4a07c7e..94d3634 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -1277,6 +1277,17 @@ 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, + ), + ), ); } } From 4e957ba7050208047196851ec89f5163f5fe1c08 Mon Sep 17 00:00:00 2001 From: paulocs Date: Fri, 17 Dec 2021 20:27:17 +0000 Subject: [PATCH 33/33] Issue #3254704 by paulocs: PHP 8.0 compatibility --- node_reference/node_reference.module | 5 ++++- user_reference/user_reference.module | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module index 94d3634..1fd6060 100644 --- a/node_reference/node_reference.module +++ b/node_reference/node_reference.module @@ -681,7 +681,10 @@ function node_reference_field_widget_form(&$form, &$form_state, $field, $instanc * * @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 diff --git a/user_reference/user_reference.module b/user_reference/user_reference.module index da025b9..bb21f10 100644 --- a/user_reference/user_reference.module +++ b/user_reference/user_reference.module @@ -684,7 +684,10 @@ function user_reference_field_widget_form(&$form, &$form_state, $field, $instanc * * @codingStandardsIgnoreStart */ -function user_reference_autocomplete_value($element, $input = FALSE, $form_state) { +function user_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 uid into