The steps to reproduce this error seem convoluted but occur in practice when our users use AJAX funtionality in node forms with the oa_section_ref field.

  1. Edit a node that is part of a space to which the user only has admin access.
  2. This means that 'target group' contains the space in 'other groups' and nothing in 'your groups'.
  3. When the form loads, the Section selection list is populated via a query that is modified by oa_sections_query_entityreference_alter()
  4. This function uses _oa_sections_get_current_selected_space() to find the current space of the entity. As this is the initial load, the space is read from the entity itself.
  5. When some AJAX action is triggered, such as clicking 'Add another item' below the 'Other Groups' field, the Sections field is repopulated in this AJAX callback.
  6. Again, oa_sections_query_entityreference_alter() and _oa_sections_get_current_selected_space() are invoked.
  7. Now, the following branch in _oa_sections_get_current_selected_space() is triggered:
      if (isset($_POST['og_group_ref'])) {
        $process = $_POST['og_group_ref'];
      }
    

    As this is now a POST request.

  8. When the user is not member of the space but has administrative access, the contents of $_POST['og_group_ref']
    are like this:
    ['und' => [['default' => '', 'admin' => 'Group (123)']]]
  9. Somewhere further along this function, only $process[LANGUAGE_NONE][0]['default'] is checked and $process[LANGUAGE_NONE][0]['admin'] is ignored.
  10. Because of this, the code assumes there is no space associated with the node.
  11. oa_sections_query_entityreference_alter() now adds $query->condition('1', '0', '='); to the query and the Sections option list is populated with 0 choices (except '- None -').

The bug can be easily fixed by also checking $process[LANGUAGE_NONE][0]['admin'].

CommentFileSizeAuthor
#2 2918907-oa_core-sections-on-ajax-2.patch614 bytesJorrit
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jorrit created an issue. See original summary.

Jorrit’s picture

Status: Active » Needs review
FileSize
614 bytes

The patch.

Jorrit’s picture

Title: Section field looses choices after AJAX action » Section field loses choices after AJAX action
mschuurman’s picture

I'm having the same issue.
How can i apply the patch ?

I already tried it bij copying the patch in the root directory of the sit and execute git apply -v 2918907-oa_core-sections-on-ajax-2.patch

This doesn't work.

Jorrit’s picture

You need to go to the oa_core directory, probably profiles/openatrium/modules/contrib/oa_core. Copy the file there and execute the command in that directory. Drupal patches are module specific, so they need to be applied in the module directory itself.

mschuurman’s picture

Thanks i applied the patch and it seems like it solved the problem.

Jorrit’s picture

Status: Needs review » Reviewed & tested by the community

Great!

mpotter’s picture

Status: Reviewed & tested by the community » Fixed

Committed to a38650f in oa_core. Thanks!

Status: Fixed » Closed (fixed)

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