Targeting CCK in 6 not working

mikelove - May 14, 2008 - 15:38
Project:Prepopulate
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

I am trying to target an autocomplete node reference field and having difficulty formulating the URL.

I can successfully edit the title and other fields, but not this field. I'm using the URL ending:

&edit[field_interview_link][0][nid][nid]=test

And here is the HTML for the first input:

<table id="field_interview_link_values" class="content-multiple-table sticky-enabled">
<thead><tr><th colspan="2">Interview link: </th><th>Order</th> </tr></thead>
<tbody>
<tr class="draggable odd"><td class="content-multiple-drag"></td><td><div class="form-item" id="edit-field-interview-link-0-nid-nid-wrapper">
<input type="text" maxlength="128" name="field_interview_link[0][nid][nid]" id="edit-field-interview-link-0-nid-nid" size="60" value="" class="form-text form-autocomplete" />
</div>
<input class="autocomplete" type="hidden" id="edit-field-interview-link-0-nid-nid-autocomplete" value="http://alegent.iftf.net/nodereference/autocomplete/field_interview_link" disabled="disabled" /></td><td class="delta-order"><div class="form-item" id="edit-field-interview-link-0--weight-wrapper">
<select name="field_interview_link[0][_weight]" class="form-select field_interview_link-delta-order" id="edit-field-interview-link-0--weight" ><option value="-10">-10</option><option value="-9">-9</option><option value="-8">-8</option><option value="-7">-7</option><option value="-6">-6</option><option value="-5">-5</option><option value="-4">-4</option><option value="-3">-3</option><option value="-2">-2</option><option value="-1">-1</option><option value="0" selected="selected">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select>
</div>
</td> </tr>...

#1

add1sun - May 14, 2008 - 15:45
Status:active» duplicate

Check out this issue: http://drupal.org/node/247399

#2

mikelove - May 14, 2008 - 16:51

I started with this, and having difficulty with this method also. This what I'm trying:

&edit[field_interview_link][0][node_name]=test

#3

mikelove - May 15, 2008 - 16:02
Status:duplicate» active

I'm going to switch back to active because the [node_name] solution doesn't seem to work with 6.x. Maybe something to do with the fields being rearrangeable.

#4

add1sun - June 23, 2008 - 14:14
Title:Targeting CCK autocomplete node reference» Targeting CCK in 6 not working
Category:support request» bug report

Marking #270116: cannot populate cck fields as a duplicate of this. Looks like CCK changes for 6 are making this wonky.

#5

ddanier - July 17, 2008 - 11:30

I fixed CCK in D6 using the following patch. Not sure if this does something bad, as I really don't know how forms in D6 are handled. But var_dump() helped me finding the problem and it works for me now.

AttachmentSize
prepopulate_d6_cck.patch 760 bytes

#6

add1sun - July 17, 2008 - 12:21
Component:Documentation» Code
Status:active» needs review

Thanks for the patch. I won't get a chance to look at this for a week or so but I'm marking it needs review and hopefully others can take it for a spin.

#7

ddanier - July 17, 2008 - 12:59
Component:Code» Documentation
Status:needs review» active

Perhaps I should describe what the problem was, so you don't have to find out yourself...:

I use the Prepopulate-module to fill nodereferences with initial data (other cck-fields may behave different). Within _prepopulate_get_walk() the module tries to find the last entry in $form according to the array given in $_GET. It seems like things have changed here, at least nodereference stores an array inside $field['#default_value']. So the array needs to be set right. Walking the $form-array fails, because it only tries to use the last element as a default value. Instead with the patch I checked if $form has an #default_value-item and set it using array_merge(), so the whole array gets copied into the form. I don't know if replacing the array instead of doing array_merge() would be better or if there is some better way to figure out that #default_value needs to be set (or further walking is needed). Like said before, I don't know much about drupal forms, but the patch just worked...so I thought it might be worth sharing. ;-)

#8

ddanier - July 17, 2008 - 13:00
Component:Documentation» Code
Status:active» needs review

Sorry, somehow the status of the ticket got changed...

#9

chirale - July 20, 2008 - 10:01
Status:needs review» needs work

On Drupal 6.3 this module works only with [title]. Body and CCK fields cannot be changed. #5 patch is ineffective on my installation.

Drupal: 6.3, CCK: 6.x-2.0-rc4

#10

chirale - October 4, 2008 - 20:39
Version:6.x-1.0» 6.x-2.x-dev

Well, It works only under some conditions.

Following tests run on a 6.x-2.x-dev (2008-Jun-24) patched with #5.

  1. [taxonomy][1]=3
    <?php
    <option value="2">A</option>
    <
    option value="3">AB</option>
    <
    option value="4">B</option>
    <
    option value="1">O</option>
    </
    select>
    ?>

    Select AB option on from vocabulary 1
  2. [field_references][0][value]=My%20References
    <?php
    <textarea id="edit-field-references-0-value" class="form-textarea resizable textarea-processed" name="field_references[0][value]" rows="5" cols="60">My References</textarea>
    ?>

    Add My References to field_references field (text field on multiple rows).
    Note: it only works outside Groups (fieldset). Moving a field outside fieldset make it works.
  3. [language]=en
    <?php
    <select id="edit-language" class="form-select" name="language">
    <
    option value="">Indipendente dalla lingua</option>
    <
    option selected="selected" value="en">Inglese</option>
    <
    option value="it">Italiano</option>
    </
    select>
    ?>

    Select "Inglese" multilingual option (using the value as ID, like taxonomy) from Internationalization module.
  4. edit[field_work][0][nid]=12
    <?php
    <input id="edit-field-work-0-nid-nid" class="form-text form-autocomplete" type="text" value="Mai [nid:12]" size="60" name="field_work[0][nid][nid]" maxlength="128" autocomplete="OFF"/>
    ?>

    To select Mai (node/12) on the first nodereference CCK field. Note: name is field_work[0][nid][nid] but only [field_work][0][nid] works.

Main issues:

  • Cannot select any CCK field contained into a fieldset: moving out make they work.
  • Second cck nodereference field (e.g. [field_work][1][nid]) cannot be populated.

Update: to select CCK field into fieldsets, postpone the fieldset class, replacing "-" with "_" (tested using #13 patch). e.g.:

Standard field targeting:

<?php
edit
[field_surname][0][value]=Smith
?>

Same field, into group (fieldset) named "ID":

<?php
edit
[group_id][field_surname][0][value]=Smith
?>

I hope these tests will be useful to fix these bugs.

#11

kriskd - August 17, 2008 - 21:28

I don't believe the patch is working for me, but I could have my URL formatted wrong too.

I want to prepopulate a CCK nodereference dropdown field. Here is the HTML for the field:

<select id="edit-field-customer-nid-nid" class="form-select required" name="field_customer[nid][nid]">

And here is what I attempted for a URL:

http://localhost/drupal-6/node/add/activity?edit[field_customer][nid][nid]=Kingdom

I'd appreciate any suggestions. :)

#12

ddanier - August 19, 2008 - 16:15

Try http://localhost/drupal-6/node/add/activity?edit[field_customer][0][nid]=$nid
($nid means it should be the ID, not the title)

#13

chirale - August 31, 2008 - 11:28

Sometimes ddanier #5 patch on my installation causes a "warning: array_keys() [function.array-keys]: The first argument should be an array" when targeting page title. On _prepopulate_get_walk !is_null($form['#default_value']) else missed the is_array($getslice) control statement. I attach the new patch (I have to test it more deeply).

AttachmentSize
prepopulate_d6_cck_v2.patch 1.01 KB

#14

moshe weitzman - October 3, 2008 - 21:21
Status:needs work» reviewed & tested by the community

#13 works for me on a node reference field (single value, select widget). Since thats better than what we have today, I mark this RTBC. You might want to fix up a few braces before commit since they don't perfectly match coding standards.

#15

corey.aufang - October 21, 2008 - 00:10

I thought I would help out so I went ahead and fixed the patch.

Don't want to seem impatient, but I like this module and have a few projects that could benefit from it.

AttachmentSize
prepopulate_d6_cck_v3.patch 1.22 KB

#16

DizzyC - October 27, 2008 - 10:16

Yup! Thanks alot. Lost half aday because of this bug. I fixed it by myself and (idiot me) only afterwards looked at the issues queue to find this patch already exists :)

Anyways! Good job!

And... MERGE IT INTO HEAD please! :)

#17

scottrigby - November 10, 2008 - 22:00

#15 works for me on a nodereference select widget.

#18

corey.aufang - November 13, 2008 - 21:20

Any maintainers know when we could get this rolled into a new release or dev?

#19

vacilando - November 16, 2008 - 23:54

I confirm patch #15 this works nicely, please commit.

#20

add1sun - November 17, 2008 - 17:44
Status:reviewed & tested by the community» fixed

Committed to 6 dev and HEAD. Thanks to all. There are some new maintainers for the project, so hopefully they will step up and start getting the code moving again.

#21

System Message - December 1, 2008 - 17:51
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#22

brevity - February 16, 2009 - 22:37

As is stated in #10 there only can be the first value of a multiple value field pre-populated.
(Second cck nodereference field (e.g. [field_work][1][nid]) cannot be populated.)

Any ideas how to accomplish this? Just adding up the delta doesn't work. CCK seems to need a preparation of values beforehand, maybe this is of any use: _content_widget_invoke('prepare form values', $node);

#23

brevity - February 17, 2009 - 13:13

I added in my _form_alter (using SESSION var instead of GET var):

<?php
...
    foreach (
array_keys((array)$_SESSION['createfromweb_edit']) as $getvar) {
      if (isset(
$form[$getvar][1])) { // we have a multiple value field
       
$fieldname = $form[$getvar][1]['#field_name'];
       
$slots = count($_SESSION['createfromweb_edit'][$fieldname]);
       
// prepare needed slots (copy array from first field)
       
for ($i = 1; $i<=4; $i++) {
         
$form[$getvar][$i] = $form[$getvar][$i-1];
         
$form[$getvar][$i]['#default_value'] = array();
        }
      }
      if (
element_child($getvar) && !is_null($form[$getvar])) {
...
?>

Then I can set multiple values via

<?php
$_SESSION
['createfromweb_edit'][$fieldname][$i]['value'] = trim($val);
?>

#24

jsaints - March 3, 2009 - 06:16

This post was very helpful.

As a note, I was able to populate 6.X node_reference checkbox fields using:

<input id="edit-field-guides-nid-nid-18043" class="form-checkbox" type="checkbox" checked="checked" value="18043" name="field_guides[nid][nid][18043]"/>

The prepopulate URL looks like:
http://mysite/node/add/story?edit[field_guides][nid][18043]=18043

Thanks

 
 

Drupal is a registered trademark of Dries Buytaert.