Problem/Motivation
The function system_date_format_save() implements the functionality to save localized date formats in the table {date_format_locale}. Unfortunately, the check whether or not to save a format localized is broken. A list of enabled languages is fetched with the following code:
$languages = language_list('enabled');
$languages = $languages[1];
When checking each date format locale against this list to see if the language is enabled, the function uses if (in_array($langcode, $languages)). However, the langcodes are in the keys of this array. The values are full database records for each language.
Proposed resolution
Correct the function to use if (isset($languages[$langcode])).
Remaining tasks
- The patch in #981524-18: system_date_format_save() doesn't save localized date formats is RTBC and includes tests.
- #1234848: language_list() doc is missing return value has been opened to address the lack of documentation for the return value of language_list().
User interface changes
None.
API changes
None.
Original report by @das-peter
The function system_date_format_save() already implements the functionality to save localized date formats in the table date_format_locale.Unfortunately, the check whether or not to save a format localized is broken.The attached patch fixes this.
Comments
Comment #2
das-peter commentedRemoved path prefix
Comment #3
sunDisabled languages are contained in $languages, too, AFAIK.
Powered by Dreditor.
Comment #4
das-peter commented$languagesis fetched using this code:Thus there should be only the enabled languages in the variable.
Besides that I'm not sure how evil it would be to store the date formats from disabled languages ;)
Comment #5
sunThanks for clarifying!
Comment #6
sunSorry, this needs tests.
Comment #7
das-peter commentedHmm, I'm not sure if the attached tests are sufficient. There is a lot more that could be covered...
But at least the topic of this issue is covered ;)
Comment #8
das-peter commentedComment #9
sunTestbot says invalid patch file.
Comment #10
das-peter commentedComment #12
sunCan you rewrite these queries to:
Powered by Dreditor.
Comment #13
das-peter commentedThx sun - nice hint. Didn't recognized that always the
addFieldkills the chaining.Comment #14
das-peter commentedComment #16
pisco commentedRerolled the patch against the current 7.x branch and verified that the tests run successfully.
Comment #17
sunMissing blank line.
2 days to next Drupal core point release.
Comment #18
pisco commentedSorry for that, should be corrected now.
Comment #19
das-peter commentedThank you sun for the review & thank you Pisco for the updated patch.
Would be nice to get rid of this diff in our own drupal repo. :)
Comment #20
sunThanks! Let's get this in.
Comment #21
xjmIssue summary added. I also opened #1234848: language_list() doc is missing return value to address the (lack of) documentation for
language_list().Comment #21.0
xjmUpdated issue summary.
Comment #22
webchickCommitted and pushed to 8.x and 7.x. Thanks!
Comment #23.0
(not verified) commentedAdded link to latest patch.