In order for timefield to validate and format correctly, the validation object needs to call #field_parents before grabbing field information. This is useful for being embedded inside field_collections.

Comments

japerry’s picture

Status: Active » Needs review
StatusFileSize
new1.29 KB

Patch included here

spadxiii’s picture

Maybe it's better to use 'drupal_array_get_nested_value' instead of looping manually.

like so:

$key_exists = false;
$field_value = drupal_array_get_nested_value($form_state['values'], $element['#field_parents'], $key_exists);

The if-statement would also check if $key_exists is true:

if ($key_exists && isset($field_value[$field_name][$element['#language']][$delta])) {
//..
}
spadxiii’s picture

Made a few changes and additions to the patch in #1

I noticed that the validation didn't check for #required. I have added that, but perhaps things might be done simpler. :)

wesnick’s picture

First, thanks for posting patches! This was actually a big can of worms. There were some other things that weren't working correctly that I discovered when I started troubleshooting this. After adding some of these changes, of course, the tests failed.

Here is my take on it. Check to see that it works for you.

@SpadXIII, I am wondering about this part of the patch from #3, maybe you could give me a test case where this would fail without this strlen() part.

@@ -922,7 +936,7 @@ function timefield_build_time_format($settings) {
  */
 function timefield_integer_to_time($settings, $value) {
   $format = timefield_build_time_format($settings);
-  if (isset($value)) {
+  if (isset($value) && strlen($value) > 0) {
     if ($value >= 86400) {
       $value = $value - 86400;
spadxiii’s picture

@wesnick, I'm not sure where or why it happened. But when I was trying to figure out what went wrong, I was getting errors because the $value was an empty string.

I'll have a go with your patch later this week and will report back then. I will also see if I can come up with a test-case for the empty string.

spadxiii’s picture

Status: Needs review » Reviewed & tested by the community

I just applied the patch to the 7.x-1.x-dev (2012-Oct-08) and it seems to work just fine!

I couldn't come up with the test-case for the extra value-check. This probably happened because of me debugging/messing up the code while figuring out a fix :)

arrow’s picture

Confirming the patch in #4 works.

wesnick’s picture

Status: Reviewed & tested by the community » Fixed

commited, thanks all for your help testing

#c411a03

Status: Fixed » Closed (fixed)

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