Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We need to convert a couple of fields from date & time to just date.
There is a lot of content and a lot of functionality based of these fields (views, etc), so a new field is out of the question.
Can you see any reason why these are locked after the field has data? There are not any schema changes, so afaick there should be not negative side effects. We have already run one field update script without issues, but now we need to repeat this with another field.
$description = t('Select the date attributes to collect and store.');
+ if ($has_data) {
+ $description .= ' ' . t('Changes to date attributes only effects new or updated content.');
+ }
$form['granularity'] = array(
'#type' => 'checkboxes',
'#title' => t('Date attributes to collect'),
'#default_value' => $granularity,
'#options' => $options,
'#attributes' => array('class' => array('container-inline')),
'#description' => $description,
- '#disabled' => $has_data,
'year' => $checkbox_year,
);
Comment | File | Size | Author |
---|---|---|---|
#10 | date-unlock-field-granularity-1840008-1.patch | 1.16 KB | cr0ss |
Comments
Comment #1
Alan D. CreditAttribution: Alan D. commentedComment #2
justindodge CreditAttribution: justindodge commentedI'd like to see this unlocked as well - I wanted to mention that I've had similar use cases, and have also changed these field settings programmatically without an adverse affect that I could observe.
In case it helps anyone in the interim, I've used this code to handle these types of changes in the past - this is an example of adding hour and minute granularity to a field called 'field_date'.
Comment #3
justindodge CreditAttribution: justindodge commentedI've also used the method illustrated in the original post, and I think it's a safe change to make.
Comment #4
Alan D. CreditAttribution: Alan D. commentedGuessing that this is "needs review" until till a patch is rolled and tested
Comment #5
Alan D. CreditAttribution: Alan D. commentedComment #6
5t4rdu5t CreditAttribution: 5t4rdu5t commentedI've tested this patch and works great, just what I was looking for. Thank you!
Comment #7
Alan D. CreditAttribution: Alan D. commented@Karen/Tim
And words of wisdom on this? Even if that is: "Should be ok, but I'm worried that I haven't considered something that will blow up somewhere..."
Comment #8
Ken Hawkins CreditAttribution: Ken Hawkins commentedWe were in the same position (needed to stop collection the hour and minute stamp) and this worked fine for us.
Date repeat functionality is supposed to be a more involved change -- has anyone tried that?
Comment #9
haydeniv CreditAttribution: haydeniv commentedWhen I used this patch and added hour and minute granularity it opened up a disabled "Timezone Handling" field. I am wondering if that also should be enabled? In my situation where I am adding granularity, I would need to configure it because it is now relevant where it wasn't when I first created the field.
Before adding hour and minute:
After adding hour and minute:
Comment #10
cr0ss CreditAttribution: cr0ss commentedAlan D, thank you for great patch #4, it helps to solve the problem with extending granularity.
Another thing mentioned in #9 is the situation I've faced to when applied patch and tried to intend the granularity. Due to disable option of a timezone field the validation wasn't passing the field settings to store.
Attached patch is slightly changed version of #4 which helped me to resolve the issue. Please review.
Comment #11
wOOge CreditAttribution: wOOge commentedPatch from #10 tested, and works.
Comment #12
lgomezma CreditAttribution: lgomezma commentedIndeed I had the same problem as cr0ss and his patch at #10 solved it.
Any idea how to 'unlock' the required for 'Collect an end date'? I don't want this to be compulsory anymore but it's locked.
Comment #13
Tilo CreditAttribution: Tilo commentedOne more confimation for patch #10. It works excellent. Many thanks
Comment #14
walidvb CreditAttribution: walidvb commentedIn case someone is trying to change the granularity, here is the code:
(Credit to someone else, can't find the source anymore. sorry)
EDIT-------------------
Oh, it was in this thread.... my bad..
Comment #15
texas-bronius CreditAttribution: texas-bronius commentedNote: To optionally *remove* hours:minutes granularity, change the 'hour' and 'minute' in the code snippet to NULL. This does not actually update any values already in the database, but their display will have the reduced formatting on View, as will the form fields on Edit-- but it's not clear to me on inspection whether merely hitting Save on an existing field will update its dates with that reduced granularity. I think it does.. just don't know why they're not 00:00 instead of 05:00 :)
Comment #16
podarok#10 looks good
let`s RTBC
Comment #17
haydeniv CreditAttribution: haydeniv commented10: date-unlock-field-granularity-1840008-1.patch queued for re-testing.
Comment #18
vijaycs85Thanks! Comitted 66162b8 and pushed to 7.x-2.x
Comment #19
vijaycs85Comment #23
Alan D. CreditAttribution: Alan D. commented@cabplan
The code is already in dev, so there is not need to retest this :)