There is a critical bug in the latest release because recipe_schema() currently defines pretime as an integer field, but there is no validation on the Preparation Time field. I got a fatal error when simply leaving it blank.

I went to patch and saw that it was trying to be a select list of predefined times, but I don't think this is sufficient for this use case.

Attached is a patch that makes "preptime" a varchar field and fixes the formAPI definition.

What I meant in the title, is with more work on this patch, we could use PHPs time string functions to detect whatever people enter and translate that to seconds to store in the database. For end users, this field needs to be as flexible as possible.

CommentFileSizeAuthor
#2 recipe.preptime.patch2.42 KBJon Pugh
recipe.preptime.patch1.79 KBJon Pugh
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jon Pugh’s picture

Title: Prep Time should be textfield... mostly? » Fatal Error on submit with non-integer Prep Time. PATCH to change to Varchar
Jon Pugh’s picture

FileSize
2.42 KB

Updated patch with a hook_update_N function, and a fix to the previous update_N function, which Failed if RDF module was not enabled.

jvandervort’s picture

Title: Fatal Error on submit with non-integer Prep Time. PATCH to change to Varchar » Prep Time should be changed from a selectbox to a textbox
Category: bug » feature
Priority: Critical » Normal

The Bug wasn't in recipe, but seemed to be created by your first patch of changing the select box to a textfield. In the current alpha4, the recipe select box defaults to a value of 5 minutes (and has no "" value possible) so it would never be empty. So this is really a feature request to change the preptime to a free-typing control.

What kind of values would you want. PHP time interval handling is not that flexible.

1/2 a day.
10 minutes
1.5 hours
1-1/2 hours
2H
une heure (French, ie free typing with translations)
One hour, ten minutes

PHP can't really deal with most of these without me writing a routine to parse it myself.
http://www.php.net/manual/en/dateinterval.format.php

Would it be ok to label the box "Minutes" and then allow people to type them in?
Or an number box with a unit selectox after it?
Right now the selectbox is used so people don't have to figure out how many minutes are in 2.5 hours:)
But it is obviously inadequate if you need a value of 5-1/2 hours as it is not available.

We might need to get some more feedback from others in the community to see if there is any consensus.

jvandervort’s picture

Version: 7.x-1.0-alpha4 » 7.x-1.x-dev

Moved to dev version.

jvandervort’s picture

I was hoping for more user responses. I guess I'll have to implement something and see how people react.

csc4’s picture

Does seem quite wide standardisation on minutes - but there's always a risk of exceptional cases, so I think people aren't sure what to say...

Maybe not quite the right place to ask but I'd like to see cooking time done similarly - if that would be possible please ;)

cmurph’s picture

I would say that changing the select box to a text field would be easily interpreted for users to enter, as well as having the ability to have good granularity for entering preparation times and cooking times.

I'm currently playing around with getting this functionality and will post a patch for it soon hopefully. It looks to be a quick fix. I just need to change the form to a "textfield," add validation for them, and voila (hopefully).
Since the formatting of the preptime and cooktime displays are not dependent on the global variable "$_RECIPE_DURATIONS" (where the list of times for the select box is located), no other necessary code changes will probably be necessary.

However, I am looking into allowing a user to input both hours and minutes, but I wouldn't think the database would need to be changed. I stick with my above change as a first cut, and then move on from there. Comments welcomed.

cmurph’s picture

Status: Needs work » Needs review

I've created a patch which converts the select box into a textbox and allows users to input minutes. When displayed, the minutes is converted to hours as necessary.

This patch is a part of the "sub recipes" patch I created for issue #776884.

To view/add the patch, go to my comment here: Issue Patch/Comment

jvandervort’s picture

Status: Needs review » Fixed

Committed to dev, thanks.

Status: Fixed » Closed (fixed)

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