Closed (fixed)
Project:
Party
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
3 Jul 2012 at 16:29 UTC
Updated:
29 Dec 2012 at 20:30 UTC
Jump to comment: Most recent file
See http://drupal.org/node/1669924#comment-6191058 for some background.
I reckon we need:
- a new form for attaching an existing entity
- data sets define whether they allow this (as some, eg p2, don't)
- data sets define whether they allow creating a new attached entity (as that doesn't always make sense)
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | dataUIbuild.patch | 45.89 KB | rlmumford |
| #2 | 1669982.party_.data-set-actions.patch | 20.61 KB | joachim |
Comments
Comment #1
joachim commentedSo I scratched my head over this this morning, and thought that adding two actions to each dataset, and form callbacks for them, would result in a ton of new form functions, and page callbacks that have to find the right form builder, and then we'd have to provide some default form builders too for good DX and the function names would multiply like crazy. Especially as where we have two actions, we may want more.
So here's the idea in a nutshell:
Data set info defines actions that you can perform on their entities. Here's some examples:
- profile2 can:
-- 'add' a new entity
- user can:
-- 'attach' an existing user
-- possibly 'add' a new user too -- TODO!
When defining actions, data set info must also give the controller for this. This is a pretty simple class that wraps up the form handlers and a little bit more. Party code provides two default controllers which data sets can use:
- PartyDefaultDataSetUIAdd: add a new attached entity
- PartyDefaultDataSetUIAttach: attach an existing entity
Getting these actions in the UI is done by:
- party_menu_local_tasks_alter() looks at all of a data set's defined actions
- party_attached_entity_action_form() is a general dispatch point page callback which gets the right controller, and gets the form from it.
So that's the new architecture.
Here's the actual situation on the ground, patch imminent:
- PartyDefaultDataSetUIAttach is not implemented and only a stub class, because so far the only thing we know how to attach is users. Enter PartyUserDataSetUIAttach.
- PartyDefaultDataSetUIAdd is not implemented and only a stub class, because this is currently handled by party_attached_entity_edit_form() and I feel such refactoring belongs to a follow-up because this code change is complex enough already. That means that data sets declare the 'add' action in order to have the local action appear, but the controller they give for it is irrelevant ;)
Here's the planned follow-ups, in rough order:
- make a data sets actions define access. If you don't declare the 'add' action, then party_access() should reflect that this action is not allowed.
- make local action links for data set actions reflect cardinality: #1669758: add entity link in party_menu_local_tasks_alter() doesn't consider singleton/cardinality
- move 'detach' into a data set action
- add 'delete' as a data set action
- refactor 'edit' as a data set action
Comment #2
joachim commentedHere's the patch.
Though with Rob out of range in the US, I'm going to commit this, as it's a big step in fixing user integration.
I'll merge my branch in so we have the individual steps.
Comment #3
joachim commentedIssue #1669982 by joachim: Add a system for data sets to define their own actions.
Clear caches LOTS -- this adds new classes which the registry needs to pick up.
Comment #4
joachim commentedFollow-ups:
#1673604: make a data set's actions define access to matching $op in party_access()
#1669758: add entity link in party_menu_local_tasks_alter() doesn't consider singleton/cardinality
#1673606: move 'detach' into a data set action
#1673608: create 'delete' as a data set action
#1673610: refactor attached entity edit as a data set action
Comment #6
rlmumfordThought it was best to build on this here, rather than create a whole new issue.
I've been working on the data set actions stuff for a couple of weeks now, and the process of re-factoring I've gone through has reduced the size of the party code significantly, made the forms stuff much more robust, and given sub-modules such as party_user and party_simplenews much more flexibility.
The patch is a bit of a monster one and includes a number of the follow up issues in it. Here is a list of what's in this patch.
In this patch I have:
Things still to do/ Follow up:
Some examples of how this works
To embed a data set action form programmatically, all you need to do is:
To get the title of a particular action, all you need to do is:
Comment #7
rlmumfordComment #8
joachim commented> $data_set_controller->getAction('edit')->build($party, $data_set_controller);
Er... you're calling on the object, and then PASSING the object?
Sorry, but that looks really weird.
> The patch is a bit of a monster one and includes a number of the follow up issues in it. Here is a list of what's in this patch.
Could this be broken up into smaller issues please?
Comment #9
joachim commentedA few things that stick out at the start of the patch, but as you say, it's a monster.
But as I say -- multiple issues for all this please. Start with building the framework you need, and then converting the actions.
There should be a helper for this. Or rather, doesn't the data set class already hold its own info?
You're giving the data set controller to the action. So it never needs it again -- see my previous comment.
Comment #10
rlmumfordYeah, that would be preferable. Hard to find blocks of it that work without the whole. But will endeavour to do so.
I totally agree, its in my list of things to do in comment 6 =)
Comment #11
joachim commented> I totally agree, its in my list of things to do in comment 6 =)
Right, but let's please not commit code that's in that shape!
If your new actions depend on the refactoring, I suggest making patches for the refactoring first.
> . Hard to find blocks of it that work without the whole
I trust you've been working on a local git branch for this? ;)