After installing project-HEAD and project_issue-HEAD a new "issue" content type is created. Attempting to create a issue without the project name argument causes a HTTP 302 which will eventually time out and display a "Redirect Loop" message in firefox.

Verified this is not the case on d.o, which correctly returns a form to select from a list of projects.

Comments

kars-t’s picture

I can verify this issue and I can't get the creation of issue nodes to work.

kars-t’s picture

Status: Active » Needs work

Found it:
issue_node_form.onc line 41

  elseif (count($projects) == 1) {
    $project = node_load(key($projects));
    drupal_goto('node/add/project-issue/' . $project->project['uri']);
  }

print_r($projects)

Array ( [Drupal Site] => Array ( [221] => comm-press Webseite ) ) 

"Drupal Site" is the projecttype from the taxonomy and the key is not directly key($projects) but key($projects['Drupal Site'])

Today I don't have enough time to make a patch so probably tomorrow :)

kars-t’s picture

Status: Needs work » Needs review
StatusFileSize
new1023 bytes

A patch for this.

project_projects_select_options sadly gives us a different structured array if there is a term set in the projecttypes vocabulary. If we just use the key we get the name of this term. So we have to use the key of the current item wich is an array.

    $key = key($projects);

    // The projects array is two dimensional if a projecttype vocabulary entry exists.
    if(!is_numeric($key)) {
      $key = key(current($projects));
    }

    $project = node_load($key);
    drupal_goto('node/add/project-issue/' . $project->project['uri']);
zoltán balogh’s picture

Patch in #3 works fine.

nicoloconte’s picture

Works fine #3 but now I'm not able to select the project for the issue!

kars-t’s picture

@nicoloconte
Do you have more than one project? Because that should be the only way you could enter the code from the patch?

evoltech’s picture

#3 just takes the first issue in the list and attempts to add an issue for it. I think a better solution is what the d.o version does: giving you a list of projects, which seem to be independent of available "projects" as in modules or themes.

nicoloconte’s picture

Yes I have some different project (approximately 10).

dww’s picture

This code was added by #526438: Skip project selection if user has access to only one project. We just want to make sure that fixing this bug doesn't re-break that feature... Don't have time right this second to setup a test site for this (since the d.o testing install profile populates the project taxonomy in a way that this bug wouldn't show up), but I'll try to get to it in the next few days if possible, maybe later this evening...

kars-t’s picture

Status: Needs review » Needs work

@dww
As far as I have tested the code should behave exactly like you intended to but be more robust and handle both return values from project_projects_select_options. Maybe there should be a check if the int we get really is a project node. I don't know if an added node_load is a good solution to check this or just wasted performance.

But I have to conform the behaviour nicoloconte has on my own site. So I set this to needs work again. I probably be able to put in some more work into this later this week. And if I find some time I'd love to add a test for this.

kars-t’s picture

Okay its obvious why this doesn't work now:

Again project_projects_select_options gives a us a multi dimensional array like

Array
(
    [Drupal Site] => Array
        (
            [221] => comm-press Webseite
            [245] => aaa Webseite
            [247] => bbb
            [244] => Tower Defense Headquarter
        )

)

So count of this array will always be 1 if there are no projects of different types. My patch always uses the first project from the projecttype array. Bad thing this way.

Quick Fix patch later:

// Fetch a list of all projects.
  $uris = NULL;
  $projects = project_projects_select_options($uris);

  if (!$projects) {
    drupal_set_message(t('You do not have access to any projects.'), 'error');
  }

  $key = 0;

  // The array from project_projects_select_options might be 2 dimensional.
  // COUNT_RECURSIVE helps us to check this.
  if (count($projects, COUNT_RECURSIVE) === 2) {
    $key = key(current($projects));
  }

  if (!$key && count($projects) === 1) {
    $key = key($projects);
  }

  // If a key was found redirect to the issue input form.
  if(is_numeric($key)) {
    $project = node_load($key);
    drupal_goto('node/add/project-issue/' . $project->project['uri']);
  }

This works but I don't know if its the best stile and it still has a problem.

As PHP lacks an array_depth() funktion I use COUNT_RECURSIVE to check. But there could be two projects as well. I will think about this.

dww’s picture

Assigned: Unassigned » dww

I have a real solution to this, I just have to run to class right now. I'll post a patch later... Stay tuned.

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new1.66 KB

Right, the array we get back from project_projects_select_options() is complicated, since it can be either a flat array of nid => title options, or it can be a nested array of project types, with nid => title mappings in each subarray (if the project taxonomy is defined). It's kind of painful, in that circumstance, to figure out if there's only one project that the user has access to. :(

However, the good news is that if you pass a reference to an array as the first argument to project_projects_select_options(), it populates that array with all the project shortname => nid mappings in a flat, 1-dimensional array. That's perfect for two reasons: a) we can safely just count() that, regardless of the project type taxonomy and get a real value, and b) since we already have the short name, so we don't even need to do the node_load() to create the URL we want to redirect to. ;)

So, new patch that takes advantage of all this, and also includes better code comments. Tested locally in a bunch of different cases and it's all working properly now. Anyone else want to give this a test drive before I commit?

Thanks,
-Derek

nicoloconte’s picture

In my case it works great!!

dww’s picture

Status: Needs review » Fixed

Committed #13 to HEAD.

kars-t’s picture

Great and many thanks! :D

Status: Fixed » Closed (fixed)

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

xaa’s picture

hi, I have this problem with the project-isssue alpha5 & vertical-tabs rc2.
Is there another fix ?
thanks