diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 068fb6a..c663b33 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2170,7 +2170,7 @@ function drupal_get_user_timezone() { // Ignore PHP strict notice if time zone has not yet been set in the php.ini // configuration. $config_data_default_timezone = $config->get('timezone.default'); - return isset($config_data_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get(); + return !empty($config_date_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get(); } } diff --git a/core/includes/common.inc b/core/includes/common.inc index 5e242aa..7e9ef75 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1876,7 +1876,7 @@ function format_interval($interval, $granularity = 2, $langcode = NULL) { * A UNIX timestamp to format. * @param $type * (optional) The format to use, one of: - * - One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', + * - One of the built-in formats: 'system_short', 'system_medium', 'system_long', 'html_datetime', * 'html_date', 'html_time', 'html_yearless_date', 'html_week', * 'html_month', 'html_year'. * - The name of a date type defined by a module in hook_date_format_types(), diff --git a/core/modules/system/config/system.date.yml b/core/modules/system/config/system.date.yml new file mode 100644 index 0000000..5446673 --- /dev/null +++ b/core/modules/system/config/system.date.yml @@ -0,0 +1,50 @@ +first_day: '0' +country: + default: '' +timezone: + default: '' + user: + configurable: '1' + default: '0' + warn: '0' +formats: + system_long: + name: "Default Long Date" + pattern: 'l, F j, Y - H:i' + locked: 0 + system_medium: + name: "Default Medium Date" + pattern: 'D, m/d/Y - H:i' + locked: 0 + system_short: + name: "Default Short Date" + pattern: 'm/d/Y - H:i' + locked: 0 + html_datetime: + name: "HTML Datetime" + pattern: 'Y-m-d\TH:i:sO' + locked: 1 + html_date: + name: "HTML Date" + pattern: 'Y-m-d' + locked: 1 + html_time: + name: 'HTML Time' + pattern: 'H:i:s' + locked: 1 + html_yearless_date: + name: 'HTML Yearless date' + pattern: 'm-d' + locked: 1 + html_week: + name: 'HTML Week' + pattern: 'Y-\WW' + locked: 1 + html_month: + name: 'HTML Month' + pattern: 'Y-m' + locked: 1 + html_year: + name: 'HTML Year' + pattern: 'Y' + locked: 1 diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index d9647f3..60e3e9f 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -2021,100 +2021,6 @@ function theme_system_date_time_settings($variables) { return $output; } - -/** - * Add new date type. - * - * @ingroup forms - * @ingroup system_add_date_format_type_form_validate() - * @ingroup system_add_date_format_type_form_submit() - */ -/* -function system_add_date_format_type_form($form, &$form_state) { - $form['date_type'] = array( - '#title' => t('Date type'), - '#type' => 'textfield', - '#required' => TRUE, - ); - $form['machine_name'] = array( - '#type' => 'machine_name', - '#machine_name' => array( - 'exists' => 'system_get_date_types', - 'source' => array('date_type'), - ), - ); - - // Get list of all available date formats. - $formats = array(); - drupal_static_reset('system_get_date_formats'); - $date_formats = system_get_date_formats(); // Call this to rebuild the list, and to have default list. - foreach ($date_formats as $type => $format_info) { - $formats = array_merge($formats, $format_info); - } - $custom_formats = system_get_date_formats('custom'); - if (!empty($custom_formats)) { - $formats = array_merge($formats, $custom_formats); - } - $choices = array(); - foreach ($formats as $f => $format) { - $choices[$f] = format_date(REQUEST_TIME, 'custom', $f); - } - // Show date format select list. - $form['date_format'] = array( - '#type' => 'select', - '#title' => t('Date format'), - '#attributes' => array('class' => array('date-format')), - '#options' => $choices, - '#required' => TRUE, - ); - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Add date type'), - ); - - $form['#validate'][] = 'system_add_date_format_type_form_validate'; - $form['#submit'][] = 'system_add_date_format_type_form_submit'; - - return $form; -} -*/ -/** - * Validate system_add_date_format_type form submissions. - */ -/* -function system_add_date_format_type_form_validate($form, &$form_state) { - if (!empty($form_state['values']['machine_name']) && !empty($form_state['values']['date_type'])) { - if (!preg_match("/^[a-zA-Z0-9_]+$/", trim($form_state['values']['machine_name']))) { - form_set_error('machine_name', t('The date type must contain only alphanumeric characters and underscores.')); - } - $types = system_get_date_types(); - if (in_array(trim($form_state['values']['machine_name']), array_keys($types))) { - form_set_error('machine_name', t('This date type already exists. Enter a unique type.')); - } - } -} -*/ -/** - * Process system_add_date_format_type form submissions. - */ -/* -function system_add_date_format_type_form_submit($form, &$form_state) { - $machine_name = trim($form_state['values']['machine_name']); - - $format_type = array(); - $format_type['title'] = trim($form_state['values']['date_type']); - $format_type['type'] = $machine_name; - $format_type['locked'] = 0; - $format_type['is_new'] = 1; - system_date_format_type_save($format_type); - config('system.date')->set('formats.' . $machine_name . '.pattern', $form_state['values']['date_format'])->save(); - - drupal_set_message(t('New date type added successfully.')); - $form_state['redirect'] = 'admin/config/regional/date-time'; -} -*/ /** * Return the date for a given format string via Ajax. */ @@ -2724,14 +2630,15 @@ function system_date_time_formats() { if (!empty($formats)) { foreach ($formats as $dfid => $format_info) { - - $row = array(); - $row['machine_name'] = array('data' => $dfid); - $row['name'] = array('data' => $format_info['name']); - $row[] = array('data' => format_date(REQUEST_TIME, 'custom', $format_info['pattern'])); - $row[] = array('data' => l(t('edit'), 'admin/config/regional/date-time/formats/' . $dfid . '/edit')); - $row[] = array('data' => l(t('delete'), 'admin/config/regional/date-time/formats/' . $dfid . '/delete')); - $rows[] = $row; + if (empty($format_info['locked'])) { + $row = array(); + $row['machine_name'] = array('data' => $dfid); + $row['name'] = array('data' => $format_info['name']); + $row[] = array('data' => format_date(REQUEST_TIME, 'custom', $format_info['pattern'])); + $row[] = array('data' => l(t('edit'), 'admin/config/regional/date-time/formats/' . $dfid . '/edit')); + $row[] = array('data' => l(t('delete'), 'admin/config/regional/date-time/formats/' . $dfid . '/delete')); + $rows[] = $row; + } } } @@ -2853,6 +2760,8 @@ function system_add_date_formats_form_submit($form, &$form_state) { $format = array(); $format['name'] = check_plain($form_state['values']['date_format_name']); $format['pattern'] = trim($form_state['values']['date_format_pattern']); + // Formats created in the UI are not locked. + $format['locked'] = 0; system_date_format_save($form_state['values']['dfid'], $format); if (!empty($form_state['values']['dfid'])) { diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index b7f242a..259e867 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -3298,143 +3298,6 @@ function hook_archiver_info_alter(&$info) { } /** - * Define additional date types. - * - * Next to the 'long', 'medium' and 'short' date types defined in core, any - * module can define additional types that can be used when displaying dates, - * by implementing this hook. A date type is basically just a name for a date - * format. - * - * Date types are used in the administration interface: a user can assign - * date format types defined in hook_date_formats() to date types defined in - * this hook. Once a format has been assigned by a user, the machine name of a - * type can be used in the format_date() function to format a date using the - * chosen formatting. - * - * To define a date type in a module and make sure a format has been assigned to - * it, without requiring a user to visit the administrative interface, use - * @code config('system.date')->set('formats.' . $type . '.pattern', $format); @endcode - * where $type is the machine-readable name defined here, and $format is a PHP - * date format string. - * - * To avoid namespace collisions with date types defined by other modules, it is - * recommended that each date type starts with the module name. A date type - * can consist of letters, numbers and underscores. - * - * @return - * An array of date types where the keys are the machine-readable names and - * the values are the human-readable labels. - * - * @see hook_date_formats() - * @see format_date() - */ -function hook_date_format_types() { - // Define the core date format types. - return array( - 'long' => t('Long'), - 'medium' => t('Medium'), - 'short' => t('Short'), - ); -} - -/** - * Modify existing date types. - * - * Allows other modules to modify existing date types like 'long'. Called by - * _system_date_format_types_build(). For instance, A module may use this hook - * to apply settings across all date types, such as locking all date types so - * they appear to be provided by the system. - * - * @param $types - * A list of date types. Each date type is keyed by the machine-readable name - * and the values are associative arrays containing: - * - is_new: Set to FALSE to override previous settings. - * - module: The name of the module that created the date type. - * - type: The machine-readable date type name. - * - title: The human-readable date type name. - * - locked: Specifies that the date type is system-provided. - */ -function hook_date_format_types_alter(&$types) { - foreach ($types as $name => $type) { - $types[$name]['locked'] = 1; - } -} - -/** - * Define additional date formats. - * - * This hook is used to define the PHP date format strings that can be assigned - * to date types in the administrative interface. A module can provide date - * format strings for the core-provided date types ('long', 'medium', and - * 'short'), or for date types defined in hook_date_format_types() by itself - * or another module. - * - * Since date formats can be locale-specific, you can specify the locales that - * each date format string applies to. There may be more than one locale for a - * format. There may also be more than one format for the same locale. For - * example d/m/Y and Y/m/d work equally well in some locales. You may wish to - * define some additional date formats that aren't specific to any one locale, - * for example, "Y m". For these cases, the 'locales' component of the return - * value should be omitted. - * - * Providing a date format here does not normally assign the format to be - * used with the associated date type -- a user has to choose a format for each - * date type in the administrative interface. There is one exception: locale - * initialization chooses a locale-specific format for the three core-provided - * types (see system_get_localized_date_format() for details). If your module - * needs to ensure that a date type it defines has a format associated with it, - * call @code config('system.date')->set('format.' . $type, $format); @endcode - * where $type is the machine-readable name defined in hook_date_format_types(), - * and $format is a PHP date format string. - * - * @return - * A list of date formats to offer as choices in the administrative - * interface. Each date format is a keyed array consisting of three elements: - * - 'type': The date type name that this format can be used with, as - * declared in an implementation of hook_date_format_types(). - * - 'format': A PHP date format string to use when formatting dates. It - * can contain any of the formatting options described at - * http://php.net/manual/function.date.php - * - 'locales': (optional) An array of 2 and 5 character locale codes, - * defining which locales this format applies to (for example, 'en', - * 'en-us', etc.). If your date format is not language-specific, leave this - * array empty. - * - * @see hook_date_format_types() - */ -function hook_date_formats() { - return array( - array( - 'type' => 'mymodule_extra_long', - 'format' => 'l jS F Y H:i:s e', - 'locales' => array('en-ie'), - ), - array( - 'type' => 'mymodule_extra_long', - 'format' => 'l jS F Y h:i:sa', - 'locales' => array('en', 'en-us'), - ), - array( - 'type' => 'short', - 'format' => 'F Y', - 'locales' => array(), - ), - ); -} - -/** - * Alter date formats declared by another module. - * - * Called by _system_date_format_types_build() to allow modules to alter the - * return values from implementations of hook_date_formats(). - */ -function hook_date_formats_alter(&$formats) { - foreach ($formats as $id => $format) { - $formats[$id]['locales'][] = 'en-ca'; - } -} - -/** * Alters theme operation links. * * @param $theme_groups diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 9d4140e..c93e7c6 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -522,21 +522,6 @@ function system_install() { config('system.cron') ->set('key', $cron_key) ->save(); - // Set date formats. - config('system.date') - ->set('formats', array( - 'short' => 'm/d/Y - H:i', - 'long' => 'l, F j, Y - H:i', - 'html_datetime' => 'Y-m-d\TH:i:sO', - 'html_date' => 'Y-m-d', - 'html_time' => 'H:i:s', - 'html_yearless_date' => 'm-d', - 'html_week' => 'Y-\WW', - 'html_month' => 'Y-m', - 'html_year' => 'Y', - 'medium' => 'D, m/d/Y - H:i', - )) - ->save(); } /** diff --git a/core/modules/system/system.module b/core/modules/system/system.module index dd389e6..b13346b 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2197,6 +2197,10 @@ function system_init() { */ function system_get_localized_date_format($languages) { $default_formats = system_get_date_formats(); + + // Temporary fix until localized formats are working. + return $default_formats; + // Get list of different format types. foreach ($languages as $language) { $date_formats = config('locale.config.' . $language->langcode . '.system.date')->get('formats');