We're going to need some magic for the "Assigned" entity_reference on issue nodes to support various features we're relying on in D6. See project_issue_assigned_choices(). We've got a hook for this in D6, and probably want to retain that. It allows for things like:
- The "Maintain issues" project permission (see #1551156: Port maintainers system from D6).
- The global "Assign and be assigned issues" site-wide permission.

I forget what other modules are implementing this hook and why, but it'd be worth a grep. Regardless, we need to figure out if entity_reference gives us a clean way to do this (I'm guessing no). If so, great. If not, we need to figure out a good way to make this work.

Comments

dww’s picture

mikey_p’s picture

Assigned: Unassigned » mikey_p

Note that this will also have to tie into the maintainers system, which is still in progress: #1551156: Port maintainers system from D6

dww’s picture

Actually, I just closed #1551208: Don't have both "Anonymous" and "- None -" options for assigned; just use None. as a duplicate. Really, this issue can take care of that, too. The point is that whatever we do here to populate the allowed values, we want to *not* include "Anonymous" and just use the default Field API value of "- None -" for issues that aren't currently assigned.

mikey_p’s picture

Status: Active » Needs review
StatusFileSize
new17.32 KB

So this ended up being a little crazy, but here goes.

Not even sure how to try to explain this. I'm probably over-engineering this because I stayed up too late.

dww’s picture

Status: Needs review » Needs work

Excellent! This is a great start, and it's definitely most of the way there. This is almost exactly what I had in mind.

However, a few concerns:

A) Looks like ProjectIssue_SelectionHandler_Assigned duplicates a *lot* of functions (exactly) from EntityReference_SelectionHandler_Generic. Any reason we can't just have: class ProjectIssue_SelectionHandler_Assigned extends EntityReference_SelectionHandler_Generic implements EntityReference_SelectionHandler?
For example:

  • getReferencableEntities() is identical (except for the check_plain() on the label -- seems like ours would lead to double-escaping in that case?)
  • A whole bunch of the settings form (all the sort-related crap) is identical. Perhaps we can just call parent::settingsForm() and then add the Project field stuff (and maybe hide something we don't need)?
  • countReferencableEntities() is identical
  • validateReferencableEntities()is identical
  • entityFieldQueryAlter() is identical
  • getLabel() is identical
  • buildEntityFieldQuery() is nearly identical -- could we just alter via entityFieldQueryAlter() to add this: $query->propertyCondition('uid', $this->getAllowedAssignees(), 'IN');?

B) What's up with validateAutocompleteInput()? It doesn't seem like it's getting called anywhere, nor that there's any other support for doing this selection widget as an autocomplete instead of a select dropdown. If we do keep it here, the convention is for @see to go at the end of the PHPDoc block, after @return. That said, dereferencing the @see didn't help me understand this any better. ;) So, if this is actually being used somehow, maybe you could explain that better in the comment?

C) Inside project_issue_project_issue_assignees(), why do we need LIKE here:
WHERE permission LIKE :perm
? In D7, now that we have {role_permission}, it's just a separate row in the table for each perm assigned to a role.

D) Extra "of" in this PHPdoc:

+ * Implements of hook_project_issue_assignees().

E) When I actually try to run this on my local dev site, I get a fatal error at node/add/project-issue/[whatever]:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) ORDER BY users.name ASC' at line 1: SELECT users.uid AS entity_id, :entity_type AS entity_type, NULL AS revision_id, :bundle AS bundle FROM {users} users WHERE (users.uid IN ()) ORDER BY users.name ASC; Array ( [:entity_type] => user [:bundle] => user ) inEntityFieldQuery->execute() (line 1139 of /.../includes/entity.inc).

Looks like in this case, getAllowedAssignees() is confused since $this->entity is still NULL at this point, so we never bother calling project_issue_assigned_choices().

  • We need to handle the node/add case
  • We should also be more resilient in case we come up with an empty array so as not to create PDO exceptions

F) Maybe to address my concern from comment #3 and #1551208: Don't have both "Anonymous" and "- None -" options for assigned; just use None. we should have project_issue_assigned_choices() responsible for always calling unset($assigned[0]) so that "Anonymous" never shows up as an option? Can you think of a better/cleaner place to do that?

Hopefully these are relatively easy fixes. Let me know what you think.

Thanks!
-Derek

senpai’s picture

Status: Needs work » Needs review
Issue tags: +sprint 2, +sprint 3, +sprint 4

Tagging for Sprint 4.

dww’s picture

Status: Needs review » Needs work

Still needs work.

mikey_p’s picture

Status: Needs work » Needs review
StatusFileSize
new10.15 KB

Updated patch, I think I addressed everything from #5, and we now inherit from EntityReference_SelectionHandler_Generic so we include alot less code.

FWIW, the autocomplete does work on existing nodes, but not on new nodes. The issue seems to be that the select list can use the empty entity present while creating the form, but the autocomplete callback doesn't have this info. I don't see any reason to take this functionality out (I'm not even sure we can).

dww’s picture

Status: Needs review » Needs work

Excellent, much better, thanks!

A few lingering concerns:

G) Wouldn't hurt to have some PHPDoc for ProjectIssue_SelectionHandler_Assigned::getAllowedAssignees(), especially since it returns either an array or FALSE. Maybe it's better to just always have it return an array() and if there are no allowed values, the array is empty? That'd simplify a bunch of the else { return FALSE } stuff and not have multiple return points. Just have it return $return in all cases, and just let that be empty or not as appropriate.

H) Totally minor, but this should be a real English sentence: // Remove anonymous user from list

I) While testing, I'm hitting this when trying to update an issue:

Notice: Undefined property: ProjectIssue_SelectionHandler_Assigned::$entity in ProjectIssue_SelectionHandler_Assigned->getAllowedAssignees() (line 50 of /.../sites/all/modules/project_issue/plugins/entityreference_selection/ProjectIssue_SelectionHandler_Assigned.class.php).

That appears to be b/c there's no longer a constructor at all, so we're not saving the $entity from the factory. That breaks the rest of the logic, so I can't really test much else.

dww’s picture

Assigned: mikey_p » dww

Heh, whoops. (I) is a non-issue. I was just running a stale copy of entityreference. You need at least rc3 for all this to work. Once I upgraded, that's all working fine.

Based on the IRC conversation where mikey_p sorted me out on that, I'm going to take this to clean up the other minor stuff from #9. Stay tuned.

Thanks,
-Derek

dww’s picture

p.s. And I just fixed projectinstall for this: a361522

dww’s picture

Assigned: dww » mikey_p
Status: Needs work » Fixed

Now that I'm using entityreference 7.x-1.0-rc3, it's all working nicely in my local testing. I cleaned up the other minor issues from #9, committed, and pushed to 7.x-2.x.

Thanks!
-Derek

dww’s picture

Follow-up if anyone's interested: #1633020: Port issue maintainer tests to D7

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