Possibility of API *additions* post-code freeze?
For this volunteer project I'm working on, I'm developing an install profile. It occurs to me that there aren't really any nice ready-made functions for doing a lot of basic stuff in Drupal like: - Creating a role, with a given list of permissions - Adding a user to a role - Enabling an input format - Turning on/off a block - etc. I can try and roll patches for these as I go, however this is something I'm doing in my "spare" time so likely I won't have encountered even 1/100th of the possible optimizations by Sept 1, and will have time for rolling patches for very few of them, if any. And while I could create my own little helper module to define these, that means a lot of copy/paste from core which is constantly changing, so it makes sense for these changes to be in core. I could see the addition of some of these API functions also being useful for things like XML-RPC, and also for making it easier for people to create their own Drupal distributions. Erm, usability? ;) I'm wondering if it's possible to add functions like this to the API, and change core to use them, post-code freeze? I know we normally don't allow API changes, but this wouldn't be _changing_ anything, per se.. people calling huge_gargantuan_function($op = something) would still get the same behaviour. It's just that internally, huge_gargantuan_function would be split it up into helper functions that each did distinct things. Just curious. :) Thanks. -Angie
Wasn't one of the main reasons for the pull-based forms change that you could do this sort of automation? So to, eg, create a new role, you'd pull the role_add form, populate it, and submit it? I agree that's not the most approachable API for every action, especially primitives like "create role", but it should be doable. On Sunday 20 August 2006 00:12, Angela Byron wrote:
For this volunteer project I'm working on, I'm developing an install profile. It occurs to me that there aren't really any nice ready-made functions for doing a lot of basic stuff in Drupal like:
- Creating a role, with a given list of permissions - Adding a user to a role - Enabling an input format - Turning on/off a block - etc.
I can try and roll patches for these as I go, however this is something I'm doing in my "spare" time so likely I won't have encountered even 1/100th of the possible optimizations by Sept 1, and will have time for rolling patches for very few of them, if any. And while I could create my own little helper module to define these, that means a lot of copy/paste from core which is constantly changing, so it makes sense for these changes to be in core. I could see the addition of some of these API functions also being useful for things like XML-RPC, and also for making it easier for people to create their own Drupal distributions. Erm, usability? ;)
I'm wondering if it's possible to add functions like this to the API, and change core to use them, post-code freeze? I know we normally don't allow API changes, but this wouldn't be _changing_ anything, per se.. people calling huge_gargantuan_function($op = something) would still get the same behaviour. It's just that internally, huge_gargantuan_function would be split it up into helper functions that each did distinct things.
Just curious. :) Thanks.
-Angie
-- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
On 19-Aug-06, at 10:12 PM, Angela Byron wrote:
For this volunteer project I'm working on, I'm developing an install profile. It occurs to me that there aren't really any nice ready-made functions for doing a lot of basic stuff in Drupal like:
- Creating a role, with a given list of permissions - Adding a user to a role - Enabling an input format - Turning on/off a block - etc.
Yep. Definitely need to do all these things to build install profiles. And we end up with little PHP code libraries that reach into Drupal and call stuff, or try and twiddle variables, usually in somewhat unclean ways. I don't know what the best approach is here, but if, as Angie says, we can make functions a bit more modular so that they CAN be called externally with predictable results...it's a good thing. -- Boris
On 20-Aug-06, at 2:06 AM, Boris Mann wrote:
I don't know what the best approach is here, but if, as Angie says, we can make functions a bit more modular so that they CAN be called externally with predictable results...it's a good thing.
Let me elaborate for a moment what my current train of thought is. Let's take user_admin_role() as an example. This ~50 line function encompasses full CRUD (create, read, update, delete) and then some on user roles. However, it takes no parameters, so there is no way to get in there and pull out specific pieces to do just one of the things it does. I was thinking we could go one of two ways on this. Either a series of functions like: user_role_create() // or user_role_insert or user_role_add user_role_read() // or user_role_get user_role_update() // or user_role_save user_role_delete() user_role_list() // retrieve a list of all user roles as an array of objects or whatever Or one "mega" function which incorporates the logic like: function api_user_role($op, $name = NULL, $id = 0) { switch ($op) { case 'create': db_query("INSERT INTO {role} (name) VALUES ('%s')", $name); break; case 'delete': db_query('DELETE FROM {role} WHERE rid = %d', $id); db_query('DELETE FROM {permission} WHERE rid = %d', $id); // Update the users who have this role set: db_query('DELETE FROM {users_roles} WHERE rid = %d', $id); break; // etc. } } (I named it "api" because it would be nice if all such functions were grouped together so you could find them easily, a better prefix probably exists :)) Then, user_role would be changed internally to call: api_user_role('create', $edit['name']); // or user_role_add($edit ['name']); but at the same time I could put in my install file: api_user_role('create', 'Seamonkey'); // or user_role_add('Seamonkey'); From a calling module's point of view, there's no difference; user_admin_role() still takes no parameters, and it still encompasses all of the functionality it ever did. The difference is that now we can actually get at that functionality in bite-sized chunks to do specific things. Obviously, each "thing" in Drupal should get its own set of functions/ mega function. I don't know which approach is better... I lean towards the micro-functions though rather than the mega-function, even though it will add to the number of functions Drupal has. Open to ideas on this point. :) -Angie
I agree with you that such functionality should be split up into separate functions. Currently, way to much modules just perform their database changes in a submit function (or something like that) without providing other modules to do the same thing through a nice interface. +1 on this idea. 2006/8/20, Angela Byron <drupal-devel@webchick.net>:
On 20-Aug-06, at 2:06 AM, Boris Mann wrote:
I don't know what the best approach is here, but if, as Angie says, we can make functions a bit more modular so that they CAN be called externally with predictable results...it's a good thing.
Let me elaborate for a moment what my current train of thought is.
Let's take user_admin_role() as an example. This ~50 line function encompasses full CRUD (create, read, update, delete) and then some on user roles. However, it takes no parameters, so there is no way to get in there and pull out specific pieces to do just one of the things it does.
I was thinking we could go one of two ways on this. Either a series of functions like:
user_role_create() // or user_role_insert or user_role_add user_role_read() // or user_role_get user_role_update() // or user_role_save user_role_delete() user_role_list() // retrieve a list of all user roles as an array of objects or whatever
Or one "mega" function which incorporates the logic like:
function api_user_role($op, $name = NULL, $id = 0) { switch ($op) { case 'create': db_query("INSERT INTO {role} (name) VALUES ('%s')", $name); break; case 'delete': db_query('DELETE FROM {role} WHERE rid = %d', $id); db_query('DELETE FROM {permission} WHERE rid = %d', $id); // Update the users who have this role set: db_query('DELETE FROM {users_roles} WHERE rid = %d', $id); break; // etc. } }
(I named it "api" because it would be nice if all such functions were grouped together so you could find them easily, a better prefix probably exists :))
Then, user_role would be changed internally to call:
api_user_role('create', $edit['name']); // or user_role_add($edit ['name']);
but at the same time I could put in my install file:
api_user_role('create', 'Seamonkey'); // or user_role_add('Seamonkey');
From a calling module's point of view, there's no difference; user_admin_role() still takes no parameters, and it still encompasses all of the functionality it ever did. The difference is that now we can actually get at that functionality in bite-sized chunks to do specific things.
Obviously, each "thing" in Drupal should get its own set of functions/ mega function. I don't know which approach is better... I lean towards the micro-functions though rather than the mega-function, even though it will add to the number of functions Drupal has. Open to ideas on this point. :)
-Angie
+1 for this, and implementing user_admin_role() (etc?) using the new functions. On 8/20/06, Angela Byron <drupal-devel@webchick.net> wrote:
I was thinking we could go one of two ways on this. Either a series of functions like:
user_role_create() // or user_role_insert or user_role_add user_role_read() // or user_role_get user_role_update() // or user_role_save user_role_delete() user_role_list() // retrieve a list of all user roles as an array of objects or whatever
After speaking with chx and JonBob about this, it seems pretty unrealistic to get this functionality in this release because of the rather large potential for bugs. And even if we did, it would likely be rushed and not thought out properly. So I've created an issue to talk more about this, in the hopes we can start laying down some code in Brussels: http://drupal.org/node/79684 Thanks in advance for any input. :)
On 8/20/06, Angela Byron <drupal-devel@webchick.net> wrote:
After speaking with chx and JonBob about this, it seems pretty unrealistic to get this functionality in this release because of the rather large potential for bugs. And even if we did, it would likely be rushed and not thought out properly. So I've created an issue to talk more about this, in the hopes we can start laying down some code in Brussels:
This is what I was going on about with the import / export stuff earlier. I definitely think we need a cleaner api for creating and manipulating 'things'
Boris Mann wrote:
Yep. Definitely need to do all these things to build install profiles. And we end up with little PHP code libraries that reach into Drupal and call stuff, or try and twiddle variables, usually in somewhat unclean ways.
I don't know what the best approach is here, but if, as Angie says, we can make functions a bit more modular so that they CAN be called externally with predictable results...it's a good thing.
-- Boris I had a patch in the queue a while ago that added those sorts of functions for blocks and themes in particular -- I too found it was pretty essential for a good install profile. I'd be willing to help out with these functions.
--Jeff
On 8/20/06, Angela Byron <drupal-devel@webchick.net> wrote:
For this volunteer project I'm working on, I'm developing an install profile. It occurs to me that there aren't really any nice ready-made functions for doing a lot of basic stuff in Drupal like:
- Creating a role, with a given list of permissions - Adding a user to a role - Enabling an input format - Turning on/off a block - etc.
Personally, I am in favour of this kind of stuff going in during the freeze. I think that it's very important that we try to ensure as clean a separation as possible between all the aspects of CRUD, and of course between all the aspects of MVC (of which CRUD generally forms the 'M' component). As Angie said, this is not new functionality; it's cleanup work. I know that I have more of an extreme view on this than other people, but I would consider any CRUD functionality (i.e. most SELECT/INSERT/UPDATE queries) that's embedded within other code (such as form _submit() functions, themable functions, and cruft-filled menu callback functions) to be a bug. And bugs can always go in during the freeze. ;-) Cheers, Jaza.
participants (8)
-
Adrian Rossouw -
Angela Byron -
Boris Mann -
Earl Dunovant -
Jeff Eaton -
Jeremy Epstein -
Konstantin Käfer -
Larry Garfield