Skip to content

Commit

Permalink
Issue backdrop-contrib#507 store date in system.date
Browse files Browse the repository at this point in the history
  • Loading branch information
herbdool committed Dec 12, 2024
1 parent 360ac20 commit 912ba5e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 83 deletions.
2 changes: 1 addition & 1 deletion payment/uc_payment/uc_payment.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function uc_payment_by_order_form($form, &$form_state, $order) {
if ($payments !== FALSE) {
foreach ($payments as $payment) {
$form['payments'][$payment->receipt_id]['received'] = array(
'#markup' => format_date($payment->received, 'custom', config_get('uc_store.settings', 'date_format_uc_store') . '<b\r />H:i:s'),
'#markup' => format_date($payment->received, 'custom', config_get('system.date', 'formats.uc_store.pattern') . '<b\r />H:i:s'),
);
$form['payments'][$payment->receipt_id]['user'] = array(
'#markup' => theme('uc_uid', array('uid' => $payment->uid)),
Expand Down
2 changes: 1 addition & 1 deletion uc_reports/uc_reports.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ function uc_reports_sales_custom() {

// Create the date title for the subreport.
if ($args['length'] == 'day') {
$date = format_date($subreport['start'], 'custom', config_get('uc_store.settings', 'date_format_uc_store') . ' - D');
$date = format_date($subreport['start'], 'custom', config_get('system.date', 'formats.uc_store.pattern') . ' - D');
}
else {
$date = format_date($subreport['start'], 'uc_store') . ' - ' . format_date($subreport['end'], 'uc_store');
Expand Down
1 change: 0 additions & 1 deletion uc_store/config/uc_store.settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"_config_name": "uc_store.settings",
"date_format_uc_store": "m/d/Y",
"uc_store_country": 840,
"uc_store_owner": "",
"uc_store_email_include_name": true,
Expand Down
176 changes: 96 additions & 80 deletions uc_store/uc_store.install
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,90 @@ function uc_store_install() {
_uc_store_add_footer_blocks();
}

/**
* Implements hook_disable().
*/
function uc_store_disable() {
// Remove the footer block from all existing layouts.
_uc_store_remove_footer_blocks();
}

/**
* Implements hook_uninstall().
*/
function uc_store_uninstall() {
// Unset mail handler for all Ubercart modules.
$config = config('system.mail');
$config->clear('uc_cart');
$config->clear('uc_order');
$config->clear('uc_file');
$config->clear('uc_roles');
$config->clear('uc_stock');
$config->clear('uc_store');
$config->save();
}

/**
* Add the Ubercart footer block to the bottom of relevant layouts using the
* specified footer message.
*/
function _uc_store_add_footer_blocks($footer_message = 0) {
$layouts = layout_load_all();
foreach ($layouts as $name => $layout) {
// Only consider default layouts and any layout whose path is 'node/%'
// (which could be a product node).
if (!in_array($name, array('default', 'admin_default')) && $layout->getPath() != 'node/%') {
continue;
}

// Try to find the appropriate region for each layout. If there's no footer
// or bottom region, then skip this layout.
$regions = $layout->positions;
if (isset($regions['footer'])) {
$region = 'footer';
}
elseif (isset($regions['bottom'])) {
$region = 'bottom';
}
else {
continue;
}

// Check whether there's already a UcBlockFooter in this layout. If there
// is, then we won't add another one.
foreach ($layout->content as $block) {
if (get_class($block) == 'UcBlockFooter') {
continue 2;
}
}

// Add our block to the layout.
$block = $layout->addBlock('uc_store', 'uc_store_footer', $region);
$block->settings['uc_footer_message'] = $footer_message;

// Add our visibility condition to the block.
$handler = layout_create_handler('layout_access', 'uc_store_path');
$block->conditions[] = $handler;

$layout->save();
}
}

/**
* Remove the Ubercart footer block from all layouts.
*/
function _uc_store_remove_footer_blocks() {
$layouts = layout_load_all();
foreach ($layouts as $layout) {
foreach ($layout->content as $uuid => $block) {
if (get_class($block) == 'UcBlockFooter') {
$layout->removeBlock($uuid);
}
}
$layout->save();
}
}

/**
* Implements hook_update_last_removed().
*/
Expand Down Expand Up @@ -317,85 +401,17 @@ function uc_store_update_1002() {
}

/**
* Implements hook_disable().
*/
function uc_store_disable() {
// Remove the footer block from all existing layouts.
_uc_store_remove_footer_blocks();
}

/**
* Implements hook_uninstall().
*/
function uc_store_uninstall() {
// Unset mail handler for all Ubercart modules.
$config = config('system.mail');
$config->clear('uc_cart');
$config->clear('uc_order');
$config->clear('uc_file');
$config->clear('uc_roles');
$config->clear('uc_stock');
$config->clear('uc_store');
$config->save();
}

/**
* Add the Ubercart footer block to the bottom of relevant layouts using the
* specified footer message.
*/
function _uc_store_add_footer_blocks($footer_message = 0) {
$layouts = layout_load_all();
foreach ($layouts as $name => $layout) {
// Only consider default layouts and any layout whose path is 'node/%'
// (which could be a product node).
if (!in_array($name, array('default', 'admin_default')) && $layout->getPath() != 'node/%') {
continue;
}

// Try to find the appropriate region for each layout. If there's no footer
// or bottom region, then skip this layout.
$regions = $layout->positions;
if (isset($regions['footer'])) {
$region = 'footer';
}
elseif (isset($regions['bottom'])) {
$region = 'bottom';
}
else {
continue;
}

// Check whether there's already a UcBlockFooter in this layout. If there
// is, then we won't add another one.
foreach ($layout->content as $block) {
if (get_class($block) == 'UcBlockFooter') {
continue 2;
}
}

// Add our block to the layout.
$block = $layout->addBlock('uc_store', 'uc_store_footer', $region);
$block->settings['uc_footer_message'] = $footer_message;

// Add our visibility condition to the block.
$handler = layout_create_handler('layout_access', 'uc_store_path');
$block->conditions[] = $handler;

$layout->save();
}
}

/**
* Remove the Ubercart footer block from all layouts.
* Store date format in date system config.
*/
function _uc_store_remove_footer_blocks() {
$layouts = layout_load_all();
foreach ($layouts as $layout) {
foreach ($layout->content as $uuid => $block) {
if (get_class($block) == 'UcBlockFooter') {
$layout->removeBlock($uuid);
}
}
$layout->save();
}
function uc_store_update_1003() {
$date_format = config_get('uc_store.settings', 'date_format_uc_store');
// @todo delete date_format_uc_store when its easier to make a breaking
// change.
$date_config = config('system.date');
$date_config->set('formats.' . 'uc_store', array(
'label' => 'Ubercart Store',
'pattern' => $date_format,
'module' => 'uc_store',
));
$date_config->save();
}

0 comments on commit 912ba5e

Please sign in to comment.