Hey all,

I'm trying to create an security module to allow maestro workflows to be assigned to Groups (as in the Group module). I've made some good progress, I'm able to modify the assignments form, and have a group type in the drop down that spawns an auto complete field for groups.

Great so far.

But when I try to hook into the maestro_pre_task_save hook, there is no reference to the from values at-all being passed into this hook, so even though this is supposed to be where modules do their own assignments and mods, I have zero access to the submission information to actually mod the assignments.

I think it would be as simple as adding the $form_state variable to the pre task save hook.

or if I'm going about this all wrong and there's a better way of doing it I'm all ears :)

Comments

endorn created an issue. See original summary.

SlayJay’s picture

StatusFileSize
new760 bytes
_randy’s picture

I'm not sure how you did the implementation, but are you not getting the $task array populated with the 'assigned' key that holds the assignments? It should be stored in there as by-assignment-type : by-var-or-fixed : to-whom

SlayJay’s picture

@_randy -

Since the $task that is being returned in the task array has not been updated yet, I don't get any information about which group is supposed to be assigned.

For example, in this photo you can see I've provided an option to select a group, and we already have a role assigned from a previous submission:

.

but the in the task array during the pre task save hook, the assigned key you mentioned only has information about the role. It's (to my understanding) here that I'm supposed to take the data from the group assignment, and modify the assigned key to actually do the assignment, but I have no information in this task array about the value submitted in the group field.

.

_randy’s picture

Ok, I see. I suppose it's debatable whether we should send along the form state or the $taskAssignments and the $taskNotifications in the hook -- what we've done/seen is people will throw in their own form submit handler and process from there when the form was altered in-module-code.

$taskAssignments and $taskNotificaitons are taken directly from the form state, so perhaps those are better options for your use case?

This way the hook becomes:

\Drupal::moduleHandler()->invokeAll('maestro_pre_task_save', array($templateMachineName, $taskID, &$task, $taskAssignments, $taskNotifications));

Thoughts?

SlayJay’s picture

I just checked out those two variables and yep, that's *exactly* what I'm missing for my use case! Those would do nicely!

  • _randy committed 18051f2 on 8.x-2.x
    Issue #2989204: Added taskAssignment and taskNotifications to the...
_randy’s picture

Status: Active » Needs review
SlayJay’s picture

Status: Needs review » Reviewed & tested by the community

marking RBTC, modifications work great, thank you!

bildesbil’s picture

Hello endorn,
very interesting what you did it's exactly what I'd like to do, so
would it be possible to test the changes you made?
thank you.

SlayJay’s picture

@bildesbil,
I'm actually planning to release everything we're building as a module once it's finished. In the end, we decided to make two Group plugins, one for interactive tasks, and one "If" task that checks if the submitter is a member (and/or role) of a certain group. Both of these can be assigned by specific groups / roles or by variable (which we use for someone to select a group on a webform when they submit, and then people with the admin role of that group get assigned the task for exaxmple.)

I *really* wanted to just hook into the standard assignment form like my screenshot above, but it turns out that assign by "fixed" and "variable" are just hard coded in to many places in the code... things like, if variable then do this, otherwise assume it's fixed and do the fixed stuff. I found my self continuously coding into a corner and decided the safer route with our timeline was to just make separate plugins.

At any rate, I have to go live with this project by november, so I imagine I'll release an alpha of the module to drupal.org shortly after that. If you don't want to wait, we literally *just* sent the plugins to QA for testing last week, but so far signs are good. If you want them, send me a message monday morning to remind me when I'm at work and I'll email them to you.

_randy’s picture

@endorn #11

If I understand correctly, you were trying to code a single task type and you ran into issues with the Maestro internal checking to see if it's by variable, else by fixed. I wonder if there's a better way to do this as perhaps your use case is something that could be done at the task definition level that helps.

SlayJay’s picture

@_randy

Nope, I was trying to hook into the assignments form to add group assignment functionality to all task types. (all built in ones at least). That's where I was running into the issues with internal variable / fixed checking.

If I'm understanding you correctly, your suggestion is what we ended up doing. We created "group if" and "group interactive" task types. to get around the issue.

_randy’s picture

@endorn

Hmm.. Doesn't seem right that you couldn't add "group" as an option with the available groups to that drop down for assignments. Perhaps I'm missing something in the implementation. I'll have a better idea when you've released the module.

Perhaps posting it to a sandbox module area on d.o or github?

_randy’s picture

Status: Reviewed & tested by the community » Fixed

In dev release.

Status: Fixed » Closed (fixed)

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

SlayJay’s picture

Sorry for the late reply on this, it's crunch time here.
Here's the sandbox with the basic functionality.

https://www.drupal.org/sandbox/endorn/3003157

Just a warning, there's a lot in the .module file that isn't actively being used... that was when we were attempting to add group as an option beside fixed and variable.

_randy’s picture

@endorn

I only see a readme in the git repository.

SlayJay’s picture

@_randy bah.... I needed more coffee apparently..... try now.