This module is amazing. Are you planning on porting it to Drupal 7?

Comments

developer-x’s picture

I am at some point - but if some industrious type wanted to show off and supply a ported version - it wouldn't hurt my feelings ;-)

john bickar’s picture

Status: Active » Needs work
StatusFileSize
new10.11 KB

Here is the initial porting patch from Coder Upgrade. When I enable the ported module on a D7 site, I get the following errors at node/add:

Fatal error: Call to undefined function content_fields() in drupal/sites/all/modules/custom/datetweaks/datetweaks.module on line 177
Warning: Missing argument 3 for datetweaks_process_date_popup(), called in drupal/includes/theme.inc on line 845 and defined in datetweaks_process_date_popup() (line 112 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).
Warning: Missing argument 4 for datetweaks_process_date_popup(), called in drupal/includes/theme.inc on line 845 and defined in datetweaks_process_date_popup() (line 112 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).
Notice: Undefined index: #granularity in datetweaks_process_date_popup() (line 113 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).
Warning: Missing argument 3 for datetweaks_process_date_combo(), called in drupal/includes/theme.inc on line 845 and defined in datetweaks_process_date_combo() (line 77 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).
Warning: Missing argument 4 for datetweaks_process_date_combo(), called in drupal/includes/theme.inc on line 845 and defined in datetweaks_process_date_combo() (line 77 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).
Warning: Missing argument 4 for datetweaks_process_date_combo(), called in drupal/includes/form.inc on line 1724 and defined in datetweaks_process_date_combo() (line 77 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).
Warning: Missing argument 4 for datetweaks_process_date_popup(), called in drupal/includes/form.inc on line 1724 and defined in datetweaks_process_date_popup() (line 112 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).
Notice: Undefined index: #granularity in datetweaks_process_date_popup() (line 113 of drupal/sites/all/modules/custom/datetweaks/datetweaks.module).

This is on a content type that has a date field that is the "Text field with Date pop-up" widget.

brightbold’s picture

Thanks both of you for working on this. I'm staying tuned...

tim.plunkett’s picture

Sub!

marcus178’s picture

subscribing

d0t15t’s picture

subscribe

dhalbert’s picture

I spent some time using the patch from #2 above and trying to get datetweaks to work on D7. The #process functions registered in hook_element_info() (was hook_elements() in D6) now take slightly different arguments, which causes the errors shown in #2. I tried fixing this but I don't really know what I'm doing yet: I just have the Drupal 7 Module Development book and it doesn't answer all my questions.

Also, the way the functions are named, it appears they MAY be accidentally invoked as MODULE_process_HOOK() functions by the theme processing. Or maybe they are supposed to be?

Perhaps someone with a little more experience can use this as a starting point. I don't think this small module has to change all that much for D7.

(The patch doesn't apply completely automatically because of some slight differences in the .info file. But you can do "git apply --reject foo.patch" to get it to apply most of the patch, and then fix the .info file by hand.)

seanbfuller’s picture

I've been spending some time working on this also. I think that with the changes in D7, some of the registry overrides might not be necessary anymore. I tried playing around with how the process function is being handled and found the following:

Using hook_element_info_alter() along these lines seems the cleanest way to add a processor function:

function datetweaks_element_info_alter(&$type) {
  // Add our processor function to date_combo
  if (isset($type['date_combo']['#process'])) {
    $type['date_combo']['#process'][] = 'datetweaks_proc_date_combo';
  }
}

Notice that this is "proc" and not "process". Doing it this way adds our processing function after date's date_combo_element_process() function located in date.element.inc.

@dahlbert, you are correct in thinking that a function named datetweaks_process_date_combo() is being picked up. I think it's in the form of a suggested process function for a theme call. It seems to be getting called after the form elements have been "processed" and just before passing it to the theme. Also, the actual form element is coming in as a child to the $element param, so that all the references would need to be changed to $element['element'].

I *think* the difference here is one of a processor function for a field element vs. a processor for a theme function. I could be wrong, however, because like you I'm still trying to get my head around some of the new D7 stuff. In the D6 version, it seemed like the module needed to own the element a bit more in order to make things work, whereas now that element can be altered in a cleaner way.

I'm gonna keep going, but so far I'm wondering if a lot of the module can be simplified to the hook_element_alter_info() that defines two processor functions (one for combo and one for popup). The theme functions seem to be pulled directly from date's code, so I don't think we'd need those either. I'll submit a patch shortly and report back if I run into any issues.

seanbfuller’s picture

StatusFileSize
new13.47 KB

Here's a second round based on my notes in #8 above. It was made against 6.x-1.x in git, incorporating some of the changes in the first patch. It still has a way to go, but it seems to be creating some of the classes and most of the critical errors are gone. Some additional notes and todos:

  • As I mentioned above, I got rid of the theme functions because they were basically the same as in date. However, date module's theme_date_combo in date.theme is obliterating any attributes on the combo element by setting the #attribute to array(). This line should be '#attributes' => $element['#attributes'], to allow the datetweaks-combo class to make it to the page. This will require either a quick patch in date or for datetweaks to hijack the theme function via the registry (as before) and include that minor fix.
  • The time dropdown is correctly showing up, but the am/pm format is just showing up as a "a" character for me. Not sure what's going on there.
  • The all day checkbox isn't working yet, but is showing up on the page.
  • The "to date" is not updating when the "from date" is updated yet.
  • The default value for the all day checkbox is currently commented out and will need to be figured out.

As I said, still a ways to go, but this at least gets rid of some of the major errors that were showing up and fixes some of the changes to how various elements are structured in D7. I haven't touched the JS yet, so some of the fixes could be there. I'm sure I've missed some things, so feedback would be much appreciated.

seanbfuller’s picture

A bit more testing after I posted this and I came across two more issues with the patch above:

  • The classes are getting set on the input as opposed to the div containing the input. This is causing the $(".datetweaks-value input") selector to fail, which is why some of the JS isn't working correctly.
  • These processor function are getting an additional parameter. This third parameter is the array of the complete form.

Not sure if this is because I'm setting it in the wrong place, due to the change regarding the form processor vs the theme processor, or is because I removed the theme functions and something else what happening there. The footprint of how much the module is overriding seems cleaning this way (as mentioned above), and I wonder if just changing the classes and selectors would be a better way forward so we can keep that.

cajmcmahon’s picture

+1

d0t15t’s picture

where does one find the d7 version to test this with?

dhalbert’s picture

@#12: See the patch attachment in comment #2. But it will not work at all as is; that is just an automatically-generated first start at a D7 version.

rv0’s picture

sub

john bickar’s picture

There is a working timepicker patch to the date_popup module at http://drupal.org/node/233047#comment-4808300. That may be helpful for folks waiting for Date Tweaks functionality.

nagiek’s picture

StatusFileSize
new5.86 KB

Here's my contribution to this issue. I know it's been a while, but hey, it helps!

Any of the original maintainers still interesting in committing a D7 version?

hanness’s picture

Issue summary: View changes

thanks nagiek!

i tired it and it does not work, which versions are you using?