logo       

[task] Drupal_map_assoc - extending the platform: msg#00557

php.drupal.devel

Subject: [task] Drupal_map_assoc - extending the platform

Project: Drupal
Version: cvs
Component: base system
Category: tasks
Priority: normal
Assigned to: Goba
Reported by: Goba
Updated by: Goba
-Status: fixed
+Status: active

More to come later - hope to do it before the freeze :)

Goba



Previous comments:
------------------------------------------------------------------------

February 2, 2004 - 17:07 : Goba

Attachment: http://drupal.org/files/issues/Drupal-map-assoc.patch (4.95 KB)

On the 24th of December, I have suggested [1] that a bunch of repeated
code could be elminated with modifying format_() functions to accept
arrays. That was turned down by Dries so then I came up [2] with a more
general solution to 'extend the Drupal platform' by adding a
drupal_map_assoc() function for module authors to use.

Here is an effort to turn this idea into a working patch and get the
support of someone who might commit it :) The idea behind this patch is
that there are a lot of places (most of the time settings, dropdowns)
when a function is called with different values repeatedly. The
function names overweight the actual parameter values and therefore it
is hard to have an overview of what is happening there... Since this
most of the time involves associative arrays, the approach is also a
possible typo point, since the array key and function parameter values
should be changed the same time.

My patch adds a general function to Drupal for any module to use. It
either converts an array to an associative array with the same values
and keys, or an array with keys and values with the function applied. I
have also included some examples of where this could help remove
repetition from the Drupal code, though there are more places to use
this. User.module is one perfect example, but I am waiting for another
patch to get accepted before I will next touch it :).

This patch is part of the continuation of my efforts to do more with
less and better organized code :)
[1] http://lists.drupal.org/archives/drupal-devel/2003-12/msg01029.html
[2] http://lists.drupal.org/archives/drupal-devel/2003-12/msg01137.html


------------------------------------------------------------------------

February 2, 2004 - 17:21 : Goba

Attachment: http://drupal.org/files/issues/Drupal-map-assoc_0.patch (4.95 KB)

Cosmetics: remove a trailing comma from the end of an array (regardless
of PHP allows it, it looked silly...)


------------------------------------------------------------------------

February 10, 2004 - 06:45 : weitzman@xxxxxxxxxxxx

to me, this patch cleans some ugly code and has no drawback.


------------------------------------------------------------------------

February 10, 2004 - 14:11 : Goba

And it will be able to clean a lot more, if this patch gets accepted :)


------------------------------------------------------------------------

February 12, 2004 - 21:44 : Dries

Committed to HEAD. Thanks.


--
View: http://drupal.org/node/view/5592
Edit: http://drupal.org/project/comments/add/5592





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise