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.
<br><br>+1 on this idea.<br><br><br><div><span class="gmail_quote">2006/8/20, Angela Byron <<a href="mailto:drupal-devel@webchick.net">drupal-devel@webchick.net</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>On 20-Aug-06, at 2:06 AM, Boris Mann wrote:<br>><br>> I don't know what the best approach is here, but if, as Angie says,<br>> we can make functions a bit more modular so that they CAN be called<br>> externally with predictable results...it's a good thing.
<br><br>Let me elaborate for a moment what my current train of thought is.<br><br>Let's take user_admin_role() as an example. This ~50 line function<br>encompasses full CRUD (create, read, update, delete) and then some on
<br>user roles. However, it takes no parameters, so there is no way to<br>get in there and pull out specific pieces to do just one of the<br>things it does.<br><br>I was thinking we could go one of two ways on this. Either a series
<br>of functions like:<br><br>user_role_create() // or user_role_insert or user_role_add<br>user_role_read() // or user_role_get<br>user_role_update() // or user_role_save<br>user_role_delete()<br>user_role_list() // retrieve a list of all user roles as an array of
<br>objects or whatever<br><br>Or one "mega" function which incorporates the logic like:<br><br>function api_user_role($op, $name = NULL, $id = 0) {<br> switch ($op) {<br> case 'create':<br> db_query("INSERT INTO {role} (name) VALUES ('%s')", $name);
<br> break;<br> case 'delete':<br> db_query('DELETE FROM {role} WHERE rid = %d', $id);<br> db_query('DELETE FROM {permission} WHERE rid = %d', $id);<br> // Update the users who have this role set:
<br> db_query('DELETE FROM {users_roles} WHERE rid = %d', $id);<br> break;<br> // etc.<br> }<br>}<br><br>(I named it "api" because it would be nice if all such functions were<br>grouped together so you could find them easily, a better prefix
<br>probably exists :))<br><br>Then, user_role would be changed internally to call:<br><br>api_user_role('create', $edit['name']); // or user_role_add($edit<br>['name']);<br><br>but at the same time I could put in my install file:
<br><br>api_user_role('create', 'Seamonkey'); // or user_role_add('Seamonkey');<br><br> From a calling module's point of view, there's no difference;<br>user_admin_role() still takes no parameters, and it still encompasses
<br>all of the functionality it ever did. The difference is that now we<br>can actually get at that functionality in bite-sized chunks to do<br>specific things.<br><br>Obviously, each "thing" in Drupal should get its own set of functions/
<br>mega function. I don't know which approach is better... I lean<br>towards the micro-functions though rather than the mega-function,<br>even though it will add to the number of functions Drupal has. Open<br>to ideas on this point. :)
<br><br>-Angie<br><br></blockquote></div><br>