Hi, I was making the review of this project and as I need something similar for one of my clients I started working on the code. Here are the remarks I've found for the parsing functionnality / preview on the edit/creation form:
3. The #ajax callback is not working on line 90 of the module file, mostly because you use an incorrect wrapper "edit-field-url". the last part of the string "url" is in fact the field name that is entered by the user so you cannot relay into that name to make the ajax replacement. Is better to create a fieldset with an #id on the widget form:
exwample:
$element['link_fieldset'] = array(
'#title' => t("Parser preview"),
// The prefix/suffix provide the div that we're replacing, named by
// #ajax['wrapper'] above.
'#prefix' => '<div id="parser-review">',
'#suffix' => '</div>',
'#type' => 'fieldset',
'#description' => t('This is where we get automatically generated checkboxes'),
);In this case you could use "parser-review" as the ajax wrapper. In any case this won't be enough when unlimited (or more than one) values are selected for this field...
To make this work the "easy way" I managed to do as follow:
$element['parse'] = array(
'#type' => 'button',
'#value' => t('Parse'),
'#weight' => 19,
'#ajax' => array(
'callback' => '_parser_parse_link',
'wrapper' => "parser-preview-".$delta,
'effect' => 'fade',
),
) + $base;
$element['link_fieldset'] = array(
'#title' => t("Parser preview"),
// The prefix/suffix provide the div that we're replacing, named by
// #ajax['wrapper'] above.
'#prefix' => '<div id="parser-preview-'.$delta.'">',
'#suffix' => '</div>',
'#type' => 'fieldset',
'#description' => t('This is where we get automatically generated checkboxes'),
);Regarding the processed values in the ajax callback
The problem I had solving the multi-value ajax callback was the $delta... I don't know why the $form_state['trigerring_element']['#delta'] is always the value of the last multifield, instead of the one that is clicked. After expending a lot of time trying to get the correct delta without success I solved this doing a little trick... I used the dynamic ID generated on the form and got a numeric index from it:
$delta = substr($form_state['triggering_element']['#id'], strrpos($form_state['triggering_element']['#id'], '-') + 1 );
Then replaced the hard coded 0 by that value.
That solves the preview and the replacement on multifields at the form edition.
Other issues related to the multiple values problem (.3)
3.1 When attaching the field into a content type setting as parameters Unlimited to the number of items of this field. :
Notice: Undefined offset: 0 in _parser_link_fetcher() (line 325 of /home/type/public_html/sites/all/modules/parser/includes/parser.inc).
3.2 When trying to add multiple fields fields there many warnings and only the first parser field is showing content and the values are mixed (images from the 1° field but text description from the last one):
Notice: Undefined variable: width in _parser_link_fetcher() (line 377 of /home/type/public_html/sites/all/modules/parser/includes/parser.inc).
Notice: Undefined variable: height in _parser_link_fetcher() (line 378 of /home/type/public_html/sites/all/modules/parser/includes/parser.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/type/public_html/includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/type/public_html/includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/type/public_html/includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/type/public_html/includes/entity.inc).
Comments
Comment #1
cubeinspire commentedGetting the $delta from the #ID didn't worked neither... I start thinking that this could be a problem from ajax field API on multiple values fields... Maybe getting an eye to the file-managed can help, as they use more or less the same system than this module.
i think a solution to this would be to use a custom ajax call.