Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

widget altered #1

Closed
wants to merge 4 commits into from

2 participants

@vredeling

Hi Kevin,

I changed the widget to cure a common problem we're facing with the super_nodereference.
If the target node get changed, the value of the primary field could be different in the node itself, then in the nodereference. For instance: let's say I've got a football club. I've got a several lists of members of each team. One member is called Paul Smith. I saved his first name in a node reference on his "team" node. Then, I find out, he's actually called Peter Smith. So I change his personal node, but the team still displays "Paul" as his first name. The nodereference is still working but if I try to save the team, I get an inconsistency error: the node ID and primary field do not match.

With the latest commit I force the widget to lookup the primary field's value if you edit the node.

best regards,
Bas

vredeling added some commits
@kswan
Owner

I looked at your diff and I see most of the code is added to the uper_nodereference_widget() function. This shouldn't be necessary. The primary field is already (supposed to be) filled by the super_nodereference_autocomplete_value() function based on the referenced nid.

In my branch there is the potential for an error message if a referenced node (for example Paul Smith) is changed while the team node is on the edit form (after the default value is generated). I don't think this is the issue you are trying to resolve.

Can you let me know the detailed configuration that might be related to super_nodereference_autocomplete_value() not retrieving the current Primary Field value?

@vredeling

If the node ID wasn't saved (as it wasn't on node creation before SHA: 71a99d8), the extra validation did serve a purpose, because data integrity problems could arise, I guess that is solved now.

@vredeling vredeling closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 20, 2010
  1. @vredeling

    Altered form autocomplete widget.

    vredeling authored
    Recheck the value of the primary field on node edit in case the target field's value has been changed
Commits on Dec 21, 2010
  1. @vredeling
Commits on Mar 3, 2011
  1. @vredeling
Commits on May 2, 2011
  1. @vredeling

    rewrite the super_nodereference field deltas and values not just on n…

    vredeling authored
    …ode updates but also on new nodes
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 3 deletions.
  1. +18 −3 super_nodereference.module
View
21 super_nodereference.module
@@ -307,6 +307,7 @@ function super_nodereference_field($op, &$node, $field, &$items, $teaser, $page)
}
return $addition;
+ case 'insert':
case 'update':
foreach ($items as $delta => $item) {
$items[$delta] = _super_nodereference_text_to_array($item['value']);
@@ -614,6 +615,20 @@ function super_nodereference_widget_settings($op, $widget) {
* the form item for a single element for this field
*/
function super_nodereference_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+ // lookup the value of the primary field (in case the target field has changed since the connection was made)
+ if($items[$delta]['nid'] !== '') {
+ drupal_set_message(t('One of your super_nodereference fields is empty.'), 'message', FALSE);
+ }
+ elseif (is_numeric($items[$delta]['nid'])) {
+ $node = node_load($items[$delta]['nid']);
+ $primary = $node->$field['primary_field'];
+ $items[$delta]['value'] = $primary[0]['value'];
+ }
+ elseif (!$field['allow_text']) {
+ drupal_set_message(t('One of your super_nodereference fields has text only input. It does not actually reference another node.'), 'warning', FALSE);
+ }
+
+
switch ($field['widget']['type']) {
case 'super_nodereference_autocomplete':
$element = array(
@@ -732,15 +747,15 @@ function super_nodereference_autocomplete_validate($element, &$form_state) {
// If the nid isn't specified, use the first matching entry. Using
// Views, the sort order can be set to control how this is handled.
$reference = array_slice($potential_references, 0, 1, TRUE);
- if (!empty($reference)) {
+ if (!empty($reference)) {
$validated['nid'] = key($reference);
$validated['value'] = $reference[$validated['nid']]['title'];
}
- elseif (!empty($field['allow_text'])) {
+ elseif ($field['allow_text']) {
$validated['value'] = $value;
}
else {
- $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
+ $error_element = $field['field_name'] . '][' . $delta . ']['. $field_key . '][value';
form_set_error($error_element, t('%name: valid record not found. Please check your selection.',
array('%name' => t($field['widget']['label']))));
}
Something went wrong with that request. Please try again.