Currently it is not possible for a site administrator to change the way that differences between issues and/or comments are displayed. This is true both for the tables displayed on issue nodes and comments, as well as in email notifications of changes. Besides just allowing a developer to actually theme these displays, this patch does the following:

  1. Allows the $changes[]['old'] and $changes[]['new'] arrays returned by project_issue_comment_changes() to provide changes in either string or array form.
    String form:
        'taxonomy_vid_10' => array(
           'label' => 'Vocabulary 10',
           'old' => 'MySQL, pgSQL, javascript',
           'new' => 'pgSQL, newbie',
         ),
    

    Array form:

        'taxonomy_vid_10' => array(
           'label' => 'Vocabulary 10',
           'old' => array('MySQL', 'javascript'),
           'new' => array('newbie'),
         ),
    

    Without this patch the second form (array) would cause errors. This patch fixes that and also provides for different theming of the output based on whether 'new' and 'old' are strings or arrays. See below for example output and use cases.

  2. Adds a new hook (hook_project_issue_issue_table_alter()) that allows other modules to add additional rows of metadata to the metadata table that is displayed at the top of every issue. The addition of the hook hook_followup_metadata_changes() from #140473: refactor code to compute the diff on an issue generated by a given follow-up made it possible for other modules to add rows to the metadata tables displayed on comments, but it didn't occur to me at the time that we'd also want to allow modules to add rows to the table at the top of the issue that shows all of the current values of the metadata.
  3. Fixes a minor bug introduced in #140473: refactor code to compute the diff on an issue generated by a given follow-up that prevented the "Reported by:" and "Updated by:" fields from being added to the metadata information on the top of emails sent in response to issue creation or followups.
  4. Adds some additional information in the comment of project_issue_comment_changes() describing hook_followup_metadata_changes().

I have tested this pretty extensively, but there's a lot to keep track of during testing so it's possible that this patch breaks something, so I'd like to get someone else to test it out as well in case I did miss something.

I've again provided a simple testing module that you can download and enable. Please note that this fake_testing_module is not smart and just adds some data via the two relevant hooks. Therefore, it will add the same data to every comment of an issue.

As an example of how data is displayed, I've also attached some screenshots and have email output below.

For a new issue, the metadata information in an email looks like this:

 Project:      Subscribe
 Component:    Code
 Category:     task
 Priority:     normal
 Assigned to:  Anonymous
 Status:       active
 Reported by:  a
 Updated by:   a
 Vocab 8:      myterm1
 Vocab 8a:     myterm1, myterm2
 Vocab 9:      New term
 Vocab 10:     Javascript, MySQL, pgSQL, IE7, Safari, Firefox
 Vocab 11:     Firefox
 Vocab 12:     newtag1, newtag2, newtag3
 Vocab 13:     newtag1, newtag2, newtag3

This is the original issue

For a followup on that issue, here's how the metadata looks:

 Project:      Subscribe
 Component:    Code
 Category:     task
-Priority:     normal
+Priority:     minor
 Assigned to:  Anonymous
 Status:       active
 Reported by:  a
 Updated by:   site2
-Vocab 9:      Old term
+Vocab 9:      New term
-Vocab 10:     Javascript, MySQL, pgSQL, IE6, IE7, Safari
+Vocab 10:     Javascript, MySQL, pgSQL, IE7, Safari, Firefox
 Vocab 11:     -IE6   +Firefox
 Vocab 12:     -oldtag1 , -oldtag2 , -oldtag3   +newtag1 , +newtag2 , +newtag3
 Vocab 13:     +newtag1 , +newtag2 , +newtag3
 Vocab 14:     -oldtag1 , -oldtag2 , -oldtag3

This is the first follow up to the issue.

Again, let me point out that the Vocab metadata comes from fake_tesing_module and does not actually make any sense. It is there primarily to demonstrate how metadata changes returned as strings and arrays print out. In the second example, you can compare Vocab 10 and Vocab 11 with one another. Both represent the same terms; in the first case all terms for the vocab are printed, whereas in the second case only the terms that were added/removed are printed.

Comments

webchick’s picture

Subscribe.

hunmonk’s picture

Status: Needs review » Needs work

i think there are some inconsistencies we need to address:

  1. i think the hook naming could be more consistent -- hook_project_issue_issue_table_alter() and hook_followup_metadata_changes() are named pretty disparately considering they operate on the same kind of metadata.
  2. i'm not sure i like having a theming function for a single row. it seems more in keeping with the Drupal way to provide a theming function the generates the full output (in this case the full table).
  3. For display of initial metadata values in the original e-mail sent after an issue is created, your module should implement hook_followup_metadata_changes() and watch for the case where $old_data is empty
    this seems weird, and makes me think that we need some more thought to make the handling more consistent.
  4. function project_issue_issue_table_alter() is never called anywhere. is that dead code?
  5. seems like there could be better code re-use between theme_project_issue_comment_table_row() theme_project_issue_mail_summary_field() -- the array conditional looks exactly the same?
aclight’s picture

Status: Needs work » Needs review
StatusFileSize
new15.45 KB

In response to the comment above (#2):

1. i think the hook naming could be more consistent -- hook_project_issue_issue_table_alter() and hook_followup_metadata_changes() are named pretty disparately considering they operate on the same kind of metadata.

They operate on the same kind of metadata but they are doing different things. In the case of hook_project_issue_issue_table_alter(), we're altering metadata displayed in the top "current status" table, whereas in hook_followup_metadata_changes() we're not dealing with *display* of metadata yet but instead with finding differences in metadata. I'm not opposed to changing the names of these hooks, but I can't think of any names that are more descriptive and similarly named. Suggestions?

2. I kept the single row/field theme functions but also created new theme functions that theme the entire metadata table.

3. For display of initial metadata values in the original e-mail sent after an issue is created, your module should implement hook_followup_metadata_changes() and watch for the case where $old_data is empty
this seems weird, and makes me think that we need some more thought to make the handling more consistent.

I know it's kind of weird but in the email summary table we're not printing just the current metadata values, but instead the changes since the last entry. In the project issue node display, we're actually displaying the current state of all metadata. I'm not sure of a better way to do this, given what our actual goal for the type of metadata to display is.

4. Yep, that was dead code. I've taken it out.

5. seems like there could be better code re-use between theme_project_issue_comment_table_row() theme_project_issue_mail_summary_field() -- the array conditional looks exactly the same?

Yeah, the first if clause those two conditionals are pretty similar but the else/elseif clauses are different. I'm not sure that creating a new function to reuse this code will help make the code any clearer overall.

aclight’s picture

StatusFileSize
new16.5 KB

This patch fixes a few things hunmonk and I talked about in person:

1. Instead of passing the stuff that will go into the tables through check_plain(), I'm now passing it through filter_xss, allowing for a, strong, and em tags. This will pave the wave for potentially allowing links in the metadata table (eg. to a username or something like that), which would be nice.

2. The conditional statements in the mail and table row/field theming functions were't checking for array vs. string every place they needed to be, so fixed that.

3. Fixed a few typos in the code comments.

Still to go: potentially changing name of one or more hooks.

aclight’s picture

StatusFileSize
new2.07 KB

Here's the updated fake_testing_module.module file that uses the a, em, and strong tags.

Also, BTW, don't freak out about the use of strip_tags() in my previous patch. That's only used in mail output and only there to get rid of the tags for display purposes, not for security.

hunmonk’s picture

StatusFileSize
new2.26 KB
new24.93 KB

k, this is a fairly major rewrite, in an attempt to simplify the hooks we're exposing for this functionality.

  • it's now one hook, hook_project_issue_metadata()
  • first arg of the hook is a metadata 'view'. the existing views as of now are 'current', and 'diff'
  • project_comment_changes() is now project_issue_diff_metadata(), and has been relocated to project_issue.module for more general use.
  • main table of an issue node now uses the 'current' op of hook_project_issue_metadata.

tested with and updated version of fake testing module, and it seems to work great. posting that here as well.

hunmonk’s picture

StatusFileSize
new26.32 KB

couple of cleanups:

  • remove unneeded spaces
  • renamed project_issue_diff_metadata() to project_issue_metadata_changes()
  • moved the conversion of the $current_data array to theme_project_issue_summary(), and added filter_xss so that some tags can be used.
  • some code comment cleanups
aclight’s picture

Status: Needs review » Reviewed & tested by the community

I tested hunmonk's most recent patch in #7 with auth and admin users. Worked as expected. Code looks good. I think the changes in the hooks hunmonk made make sense.

hunmonk’s picture

Status: Reviewed & tested by the community » Fixed

committed to 5.x-2.x, applied to d.o, project.d.o

aclight’s picture

Category: feature » bug
Status: Fixed » Needs review
StatusFileSize
new1.44 KB

There's a little cruft in the code that finally got committed. This patch cleans it up. There are extra parenthesis in the filter_xss calls. More importantly, there is an unnecessary call to check_plain() that will mess up the a, em, and strong tags that filter_xss allows.

hunmonk’s picture

Status: Needs review » Fixed

code looks good. committed to 5.x-2.x and 5.x-3.x, deployed on d.o et. all

Anonymous’s picture

Status: Fixed » Closed (fixed)

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