Please find the attached patch file to be ported to make the module work as said.
Thanks

Comments

joachim’s picture

Status: Patch (to be ported) » Postponed (maintainer needs more info)

Thanks!

But could you explain what this fixes please?

sanchi.girotra’s picture

Status: Postponed (maintainer needs more info) » Patch (to be ported)

Hi @joachim,
When i used this module i found that after clicking on "Save and add similar" button in add taxonomy form, term get saved but the content of the previous term don't come auto filled when the form for next term get loaded again.
So as to fix this issue i provided the above patch.
Thanks And Regards
Sanchi

joachim’s picture

Title: Patch Related to "To Do List in the .module File" » content of the previous term don't come auto filled when the form for next term get loaded again.
Category: task » bug
Status: Patch (to be ported) » Needs work

So... you're saying the module doesn't work at all? That's odd, as I've tested it and it works for me.

The issue title should describe the problem to be fixed. Also, set the category: this should be a bug report.

+++ b/taxonomy_add_previous.module
@@ -53,9 +53,9 @@ function taxonomy_add_previous_form_taxonomy_form_term_alter(&$form, &$form_stat
-      $fields = field_info_instances('taxonomy_term', $vocabulary_name);
+      $fields = $form['#term'];

I think it's cleaner to get the fields from the field info API. The $term object will have other things on it such as the tid, which we don't want to bring over!

+++ b/taxonomy_add_previous.module
@@ -53,9 +53,9 @@ function taxonomy_add_previous_form_taxonomy_form_term_alter(&$form, &$form_stat
-        $form[$field_name]['#process'][] = 'taxonomy_add_previous_taxonomy_form_term_process';
+        $form[$field_name]['#default_value'] = $form_state['taxonomy_add_previous_previous_term_form']['#term'][$field_name];

Could you explain why the process function isn't working? Also, if your patch makes the module cease to use a function, you should also remove it.

sanchi.girotra’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new3.28 KB

Hi @joachim,
1. $fields = field_info_instances('taxonomy_term', $vocabulary_name);
I have not used this because it returns empty array as field_info_instances() calls _field_info_collate_fields() which returns
... [instances] = array(
.... [taxonomy_term] => Array
(
[tags] => Array
(
)

) ...
i.e. don't go in any condition in field_info_instances().
2.I have not used process function bacause :
if (array_key_exists('#default_value', $element) && array_key_exists('#value', $element)) {
any process function call will not go in this condition as #value of a newly created element is always empty.

$matching_fake_form_element = drupal_array_get_nested_value($form_state['taxonomy_add_previous_previous_term_form'], $element['#array_parents']);
this will set $matching_fake_form_element as
Array
(
[#type] => textfield
[#title] => Name
[#default_value] =>
[#maxlength] => 255
[#required] => 1
[#weight] => -5
)
having #default_value as empty.

$element['#value'] = $matching_fake_form_element['#default_value'];
so this will set $element['#value'] to null.

Please find the new patch having no process function.
Thanks And Regards
Sanchi

joachim’s picture

Status: Needs work » Needs review

Could you possibly edit your comment and use code tags to make it a bit more readable please?

Also, the status for this should be 'needs review'. You'll find an explanation of issue statuses here: http://drupal.org/node/156119

joachim’s picture

Status: Patch (to be ported) » Needs review

> I have not used this because it returns empty array

I don't understand what you mean here.
field_info_instances() returns an array of fields. It's the correct way to get the list of fields for the current term.

> if (array_key_exists('#default_value', $element) && array_key_exists('#value', $element)) {
> any process function call will not go in this condition as #value of a newly created element is always empty.

That's fine. That's why I'm using array_key_exists() rather than !empty().

sanchi.girotra’s picture

1.

I have not used this because it returns empty array
I don't understand what you mean here.
field_info_instances() returns an array of fields. It's the correct way to get the list of fields for the current term.

explanation of how it all woks:
when the function taxonomy_add_previous_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) { calls field_info_instances('taxonomy_term', 'tag');

function field_info_instances($entity_type = NULL, $bundle_name = NULL) {
  $info = _field_info_collate_fields(); 
  /*Returns an array  like 
       ... [instances] = array(
         .... [taxonomy_term] => Array
             (
               [tags] => Array
               (
               )
            ) ... */
  if (!isset($entity_type)) {//$entity_type = 'tag' so will not enter in this condition.
    return $info['instances'];
  }
  if (!isset($bundle_name)) { //$bundle_name = 'taxonomy_term'  so will not enter in this condition also.
    return $info['instances'][$entity_type];
  }
  if (isset($info['instances'][$entity_type][$bundle_name])) {/* as seen above it is also not set so will not enter in this condition also.*/
    return $info['instances'][$entity_type][$bundle_name];
  }
  return array(); /*thus returns empty array but this functions works for other forms and can see by displaying the content of _field_info_collate_fields(). */
}

2.

> if (array_key_exists('#default_value', $element) && array_key_exists('#value', $element)) {
> any process function call will not go in this condition as #value of a newly created element is always empty.
That's fine. That's why I'm using array_key_exists() rather than !empty().

if (array_key_exists('#default_value', $element) && array_key_exists('#value', $element)) {
but there is no array corresponding to #value or #default_value, you can see this by displaying the content of $element.

Thanks for guiding me.

joachim’s picture

It should be 'tags' for the OOTB vocab, not 'tag'.

dsm(field_info_instances('taxonomy_term', 'tags'));

gets me an empty array, but that's because on my site I have no fields defined on the tags vocab. That's normal.

sanchi.girotra’s picture

Yes ,it should be 'tags' its my mistake .

but that's because on my site I have no fields defined on the tags vocab. That's normal.

But drupal standard profile provides us default vocabulary "tags" having fields name,description, url, parent.
So now what we should do to get data through field_info_instances('taxonomy_term', 'tags') ??

joachim’s picture

> name,description, url, parent

Those aren't FieldAPI fields. Also, I didn't think those should be copied: the url and name need to be unique, at least.

sanchi.girotra’s picture

@joachim,
Most of us use these default fields only with in the 'tags' vocabulary so your module should work with that also.
So finally is this patch worth it ??

joachim’s picture

I can see that you might want the same parent for the next term -- so if that's the actual problem you are trying to solve, you could rework the patch to fix that (and update the issue title too).

But would you really want to repeat the description?

sanchi.girotra’s picture

@joachim,
No, i want same data for name, desc, url, parent i.e. all fields should come for the next term which user can change accordingly.
I think this is what your module desc says

This module adds an extra button to the form for adding a taxonomy term. Whereas saving a new term normally takes you to a blank form for adding another term, this extra button inserts the fields values from the first term.

Regards
Sanchi

joachim’s picture

Status: Needs review » Needs work

I can see that you might want these to be prefilled so the prefilled value can then be altered by the user before saving.

I'm a bit concerned that at this point, it might be a good idea to stick some sort of visual warning on anything that's been prefilled, but that's going to be pretty messy to do.

At any rate, I am about to change the way this works completely to fix #1617956: doesn't work on multi-select widgets, so this patch will need work.

joachim’s picture

Title: content of the previous term don't come auto filled when the form for next term get loaded again. » built-in term form fields aren't handled

Better title.