[development] Looking for patch love

Bèr Kessels ber at webschuur.com
Sat Aug 26 14:19:43 UTC 2006


Hi

We seem to be moving towards an overall new hook system, all based around the 
callbacks and alters of forms. I have worked with form api for a long enough 
time to say that I very much dislike it. 

I prefer hooks over _alter's and callbacks. Thats all.

>      - Not always easier to use or easier to theme.  Not exactly
> elegant either -- often very verbose.

Theme functions in fapi have become a LOT more complex. EG: 
+function theme_profile_category($element) {
+  $output = ($element['#title'] != '') ? '<h3>'. 
$element['#title'] .'</h3>' : '';
+  $output .= '<dl'. drupal_attributes($element['#attributes']) .'>';
+
+  foreach (element_children($element) as $key) {
+    if ($element[$key]['#title'] != '') {
+      $output .= '<dt'. drupal_attributes($element[$key]
['#attributes']) .'>'. $element[$key]['#title'] .'</dt>';
+      unset($element[$key]['#title']);
+      $output .= '<dd'. drupal_attributes($element[$key]
['#attributes']) .'>' . $element[$key]['#value'] .'</dd>';
+      unset($element[$key]['#value']);
+    }
+  }
+  $output .= '</dl>';
+  return $output;
+}

2 ifs, 1 foreach, 1 unset, 2 api calls and loads of complex concanations. 
This should not even be considered a theme function. This is business logic 
pur sang. Complex business logic even. Not fit for a theme. FAPI (alike code) 
has introduced lots of these waaaay too complex theme functions. 

Compare to a properly crafted theme function, wich gets prepared data: 

function theme_profile_category($elements) {
  foreach ($elements as $key => $element) {
     $out .= theme('profile_element', $element, $key);
  }
  return "<dl>$out</dl>";
}

function theme_profile_element($element, $key) {
  $elements = drupal_attributes($element['#attributes']);
  $out .= "<dt $elements>$element['#title']</dt>";
  $out .= "<dd>$element['#value']</dd>"
}

This latter solution is 1) cleaner, 2) gives the same power to the themer, and 
is 3) far easier to grok.

I don't have a good feeling about this FAPI direction. not at all.  Is this 
explanation why i dislike the fapi-concept technical enough? 

There, I've said it. :)

Bèr
-- 
 PGP ber at webschuur.com
  http://www.webschuur.com/sites/webschuur.com/files/ber_webschuur.asc

Nieuwsartikelen, of weblog.:
 http://help.sympal.nl/nieuwsartikelen_of_weblog
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.drupal.org/pipermail/development/attachments/20060826/cf6d0eab/attachment.pgp


More information about the development mailing list