comment_driven seems to technically work with casetracker, but the normal layout of casetracker UI on comment form gets broken.

It's still useable, but the html output has changed too much (from tables and divs to divs only). It's lacking in CSS id:s, and because of that I can't correct it with CSS only. I haven't found any theme override I could use to fix it, and I can't fix it on my custom module form_alter either. See screenshots for clarification on how the output differs.

I noticed comment_driven has a module weight of 1000, which is higher than almost any other module (except for example devel). I tried setting my module weight to 1001, but it couldn't alter the form, as driven already has rendered it (it seems).

I believe running this hook or some of it (from casetracker) somewhere in comment_driven could fix it:

/**
 * Implementation of hook_form_comment_form_alter().
 */
function casetracker_form_comment_form_alter(&$form, &$form_state) {
  $node = isset($form['nid']['#value']) ? node_load($form['nid']['#value']) : NULL;
  if (casetracker_is_case($node->type)) {
    $form['#node'] = $node;

    // add case options to the comment form.
    casetracker_case_form_common($form);

    // necessary for our casetracker_comment() callback.
    $form['revision_id'] = array('#type' => 'hidden', '#value' => $node->vid);
  }
}

Or maybe just running this theming function is enough? (it's defined in $form['casetracker']['#theme']).

/**
 * Theme function for cleaning up the casetracker common form.
 */
function theme_casetracker_case_form_common($form) {
  drupal_add_css(drupal_get_path('module', 'casetracker') .'/casetracker.css');
  $output = '';
  $output .= drupal_render($form['pid']);
  $output .= drupal_render($form['case_title']);

  if ($form['assign_to']['#type'] == 'radios') {
    if ($form['assign_to']['#access']) {
      $header = array_fill(0, 5, array());
      $header[0] = $form['assign_to']['#title'];
      $radios = array();
      foreach (element_children($form['assign_to']) as $id) {
        $radios[] = drupal_render($form['assign_to'][$id]);
      }
      $radios = array_chunk($radios, 5);
      $output .= theme('table', $header, $radios, array('class' => 'casetracker-assign-to'));
    }
    drupal_render($form['assign_to']);
  }
  else {
    $output .= drupal_render($form['assign_to']);
  }

  $row = array();
  foreach (element_children($form) as $id) {
    if (!in_array($id, array('pid', 'case_title', 'assign_to'))) {
      $row[] = drupal_render($form[$id]);
    }
  }
  $rows = array($row);
  $output .= theme('table', array(), $rows);
  $output .= drupal_render($form);
  return $output;
}

See attachment for the output on my system (using the openatrium theme rubik + subtheme cube, which I've modified). I smudged some parts since they are names of real people.

Comments

arhak’s picture

screenshots?
you forgot them

arhak’s picture

Title: Support for casetracker (layout) » Compatibility with casetracker

I noticed comment_driven has a module weight of 1000

this means "don't go after cdriven unless you really know what you're doing" (e.g. sample modules attached to #760154: provide description field for driven's properties)

which is higher than almost any other module (except for example devel)

I left devel having weight=88, but if they got higher then probably this module should review if it is ok with that

I tried setting my module weight to 1001, but it couldn't alter the form, as driven already has rendered it (it seems).

no, it isn't rendered,
but if you're trying to reach comment_form's elements they are disguised to allow merging it with the node_form
the high weight states that we intend to be the last form_alter

regarding casetracker_form_comment_form_alter:
definitely casetracker_case_form_common needs to be reviewed

regarding theme_casetracker_case_form_common:
this is obviously broken by cdriven (also related to what is into casetracker_case_form_common)

I'm curious: why are you using casetracker and cdriven at the same time?
are you trying to use cdriven as a complement to some missing functionality of casetracker?
wouldn't be better to open a feature request to casetracker project?

arhak’s picture

I really appreciate your efforts to figure this out, you have been very accurate
if you want to go further I'll give you some tips

lets say that you implement (just for testing) a custom module named FIXTEST with weight=2000 (hook_enable or hook_install)

function FIXTEST_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id != 'comment_form') {
    return; // we only care about comment_form, but in a form_alter (which goes after form_FORMID_alter)
  }
  // lets jump in without checking for cdriven nor casetracker
  // (i.e. if they aren't acting both on this comment_form other errors will show up, but this is just a test)
  $element = &$form[COMMENT_DRIVEN__DISGUISE_PREFIX . 'casetracker'];
  $element['#theme'] = 'FIXTEST_casetracker'; // the proxied theme function declared bellow
}

// remember to properly declare this theme function in the hook_theme AND clear the cache
function theme_FIXTEST_casetracker($element) {
  $element = _comment_driven_undisguise($element);
  // again, we are jumping in because we know casetracker will be there for this test
  return theme_casetracker_case_form_common($element);
}

if the above code helps, then we are getting somewhere

PS: note that the above code was written in cold (I don't even have casetracker at hand at this moment) and therefore it might have some errors/typos

bibo’s picture

Status: Needs review » Needs work
StatusFileSize
new16.26 KB
new26.91 KB

screenshots?
you forgot them

Dang, those must have been lost on preview. Maybe this time works.

Not, that they matter much, the issue just got solved and casetrackers UI is fixed :)!

I left devel having weight=88, but if they got higher then probably this module should review if it is ok with that

Oh, on second look its not devel-module itself that has over 1000 weight, it's one of its submodules at "/devel/performance/performance.module".

I'm curious: why are you using casetracker and cdriven at the same time?
are you trying to use cdriven as a complement to some missing functionality of casetracker?
wouldn't be better to open a feature request to casetracker project?

Well, actually I could have survived with casetracker alone (but the client wanted a bit more). So yes, im trying to complement
some missing features of casetracker, that is having some cck fields being editable in comments.

I'm not seeing casetracker having cck support in comments anytime soon. The idea of being able to control almost all node properties in a comment seems to have great potential.
Especially in sites driven by uhm.. comments.

Besides, it seems you're developing this module very fast and making it support all kinds of modules ;)

So, to get to what fixed the problem. I modified the "fixtest"-code you suggested a bit: changed if ($form_id != 'comment_form') { ==> $form['#id'] != 'comment-form' and the proper path to the casetracker element (and added the theme hook).

The fixtest.module looks like this now:


function fixtest_form_alter(&$form, &$form_state, $form_id) {

if ($form['#id'] != 'comment-form') {
    return; // we only care about comment_form, but in a form_alter (which goes after form_FORMID_alter)
}
  
   // lets jump in without checking for cdriven nor casetracker
  // (i.e. if they aren't acting both on this comment_form other errors will show up, but this is just a test)
 
  if(isset($form['comment_driven'][COMMENT_DRIVEN__DISGUISE_PREFIX . 'casetracker']['#theme'])){
	$form['comment_driven'][COMMENT_DRIVEN__DISGUISE_PREFIX . 'casetracker']['#theme'] = 'fixtest_casetracker';
  }
  
}

/**
* Implementation of hook_theme().
*/
function fixtest_theme(){
  return array(
    'fixtest_casetracker' => array(
      'arguments' => array('element' => NULL),
    ),
  );
}

// remember to properly declare this theme function in the hook_theme AND clear the cache
function theme_fixtest_casetracker(&$element) {

  $element = _comment_driven_undisguise($element);
  // again, we are jumping in because we know casetracker will be there for this test
  return theme_casetracker_case_form_common($element);
}

Result => Great success! Casetracker looks now like it was without "comment_driven".

Thanks for working with me on this (and the Wysiwyg issue).

EDIT: edited copypaste madness. I'm too tired.

bibo’s picture

Status: Active » Needs review

Changing status to "needs review". It's pretty close to "reviewed & tested by the community" too :)

bibo’s picture

Status: Needs work » Needs review

A funny sidenote: CCK support for casetracker was actually in the works with "cckasetracker" (http://drupal.org/project/cckasetracker).

It seemed rather limited, and the project page says:

The development of this module will stop in favor of CCK comments module, as it has a similar functionality, with no dependencies.

.. and when you go to to "comment_cck" ( http://drupal.org/project/comment_cck ), the page says

This module is going to be abandoned. An upgrade path to the Comment Driven module is being investigated. If you consider to install Comment CCK on a new site, you should rather use Comment Driven.

So.. at least this project isn't being abandoned just yet ;)

arhak’s picture

Status: Needs review » Needs work

good news then

I'm thinking about a generic solution to address these element's #theme issues altogether
(i.e. this issue and #761288: Compatibility with Team Notifications but both with a different unified approach)

PS: for other users reading this issue, the code posted above is ONLY for testing purposes, the fix for this issue won't require another module

arhak’s picture

@bibo: thank you so much for your tests & feedback

arhak’s picture

Status: Needs work » Needs review
StatusFileSize
new3.49 KB

attached patch should fix this
it follows the proxied #theme approach
(without needing the custom module)

to test it:
- remember to disable any version of the FIXTEST module
- clear the cache (a new theme function is being declared by comment_driven)

PS: right now I have no time to test it myself
this patch should address #761288: Compatibility with Team Notifications in passing by

bibo’s picture

Took me a while to start testing this patch (I'm supposed to do my thesis which is due soon :p).

It didn't seem to work: both casetracker and team_notifications UI:s were messed up.

I started fiddling around and found the reason: $element['#theme_used'] = true; . That is, Drupal thinks the form element theming is now handled and we're done with it, so it won't get themed after the undisguising. Or that's how I understand it. I tried setting that var to "false".. and both notifications_team and casetracker got rendered fine. Yay :). Probably would fix lots of other modules' output too?

Again, I only added this "$element['#theme_used'] = false;" to the theming function, which looks now like:

function theme_comment_driven_proxy($element) {
  // key #theme is expected to be overriden by its disguised version
  // but, just in case, lets ensure we won't fall back here (unintended recursion) 
  unset($element['#theme']);

  // Also need to set #theme_used to false, so drupal render doesnt get confused when it does the real theming
  $element['#theme_used'] = false;

  $element = _comment_driven_undisguise($element);
  return drupal_render($element);
}

Please try the attached patch (for alpha-2).

arhak’s picture

Priority: Normal » Critical

@10 lots of kudos for you bibo!
absolutely right
the new proposed approach is delegating to drupal_render, therefore it makes sense to clear that flag
since we are not directly invoking the theme function (which was the first test's approach)

and both notifications_team and casetracker got rendered fine. Yay :). Probably would fix lots of other modules' output too?

indeed
it is a critical missing piece of this puzzle

thanks

arhak’s picture

#10 seems great to me, but we are only addressing $element['#theme']

what about $element['#pre_render'] & $element['#post_render'] ?
- if $element['#theme'] is defined they will be also handled by drupal_render
- but otherwise they will continue malfunctioning (i.e. broken)
- besides, using drupal_render looks straightforward, but it is being processed twice

the new proposed patch (which I haven't tested not even once, yet)
attempts to address not only #theme, but also #pre_render & #post_render
since right now we don't have any contrib module using pre_render/post_render without #theme (which might be a rare case to find)
I would like to have bibo's opinion on this (code review)

I know this time the code doesn't look as simple as before
but it is addressing three different render's fragments with the same approach

for users not involved in code review, this patch is intended to behave the same as #10

bibo’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #12 works great for me! casetracker and team_notifications UI seem normal.

Currently I can't do further testing, I really have to concentrate on my thesis for a while. Luckily it's about Drupal ;)

I'm glad this is fixed and I could be of help :).

arhak’s picture

@#13 thanks, and good luck!

arhak’s picture

Status: Reviewed & tested by the community » Fixed

commited to HEAD

remember that this requires to clear cache
(there is a new theme function)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.