Problem/Motivation

In some cases, the authors list is bigger than 256 chars.

Proposed resolution

The solution implies to change the field author to be a multivalue field and to perform some changes in the module so that it fills the authors list. This can be done in the current implementation of the hook_form_alter.

Comments

vertikal.dk’s picture

Status: Active » Closed (won't fix)

bit_jammer,

I can see that this becomes a problem when the author list is very long. I haven't met the problem.

My first reaction would simply be to make the author field longer, accomodating to long author strings. Separating the authors into seperate fields, one author at a time, would require some more work, and basically change the structure of this otherwise pretty simple content type.
I can also see from the data that I get back that the author field is highly irregular, not using any standard for separating authors and oftentimes adding illustrators, editors and other roles to this text.

These are just a few examples from books I fetched:
Dick Brown
Taff Price; illustrations by George Thompson
by Gary LaFontaine
Kim Vletas, Stephen Vletas
Barry & Cathy Beck

As you can see they are not exactly standardized, and separating them into individuals would not be easy. In my own projects I haven't needed separate authors, and I think I'll leave it like it is - apart from making more space in the field.

Martin

bit_jammer’s picture

Ok. I took the hard way (it seems).
I've converted the field in a multivalued one and then splitted the outcome from the webservice and filled this field. My final idea is to become this field in searcheable.
These are my changes:

// in isbn2node.install
 91     'isbn2node_author' => array(
 92       'field_name' => 'isbn2node_author',
 93       'cardinality' => FIELD_CARDINALITY_UNLIMITED,
 94       'type' => 'text',
 95     ),
// in isbn2node.module
326           case 'isbn2node_author':
327             // convert the names list into an array, remove withe spaces and sort by name
328             $authors_array = explode(',', $default_value);
329             foreach ($authors_array as $key => $value) {
330               $authors_array[$key] = trim($value);
331             }
332             sort($authors_array);
333 
334             // process the array by copying the current first empty row and filling the original one (this is, copy n to
335             // n+1 and fill n).
336             $rows = 0;
337             for ($index = 0; $index < count($authors_array); $index++) {
338               if ( strlen(trim($authors_array[$index])) > 0 ) {
339                 $form[$field][LANGUAGE_NONE][$rows + 1] = $form[$field][LANGUAGE_NONE][$rows];
340                 $form[$field][LANGUAGE_NONE][$rows]['value']['#default_value'] = trim($authors_array[$index]);
341                 $form[$field][LANGUAGE_NONE][$rows]['#weight'] = $rows;
342                 $form[$field][LANGUAGE_NONE][$rows]['_weight']['#default_value'] = $rows;
343                 $form[$field][LANGUAGE_NONE][$rows]['_weight']['#delta'] = &$rows; // this value has to be the total 
344                 $form[$field][LANGUAGE_NONE][$rows]['#delta'] = $rows;
345                 $form[$field][LANGUAGE_NONE][$rows]['value']['#weight'] = $rows;
346                 $form[$field][LANGUAGE_NONE][$rows]['value']['#delta'] = $rows;
347 
348                 $rows++;
349               }
350             }
351 
352             // place the last copy of the original row into the last position
353             $form[$field][LANGUAGE_NONE][$rows]['#weight'] = $rows ;
354             $form[$field][LANGUAGE_NONE][$rows]['_weight']['#default_value'] = $rows;
355             $form[$field][LANGUAGE_NONE][$rows]['_weight']['#delta'] = &$rows;
356             $form[$field][LANGUAGE_NONE][$rows]['#delta'] = $rows;
357             $form[$field][LANGUAGE_NONE][$rows]['value']['#weight'] = $rows;
358             $form[$field][LANGUAGE_NONE][$rows]['value']['#delta'] = $rows;
359 
360             // inform the number of rows used in this field
361             $form[$field]['#max_delta'] = $rows;
362             $form_state['field'][$field][LANGUAGE_NONE]['items_count'] = $rows;
363 
364             break;

I'm pretty sure this can be done in a easier way but since I'm quite new to this drupal world, this is the best I can give.
By the way, thanks for the answer.