This module creates a block which displays the current (based on the regional settings) date/time. It allows a designated user to adjust the format of the date/time display using standard PHP date formatting. Although this current functionality is already available using other means (Example: create a block that allows PHP and display the date), this provides a simple interface for beginner users and doesn't require the PHP filter to be turned on. I am not aware of any other modules that perform this exact functionality.

Project Page: https://drupal.org/sandbox/flexman/2141203
GIT Repository: git clone --branch 7.x-1.x http://git.drupal.org/sandbox/flexman/2141203.git date_block

This is the first project that I have completed. Thank you.

Comments

PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

prateekjain’s picture

Status: Needs review » Needs work

Module works fine, block gets created and date is shown on enabling the block.

In the settings at admin/config/date_block, if the textfield is left empty and saved, no date is shown in the block which is right according to the code. It might be good to show a date with default format or put a check that empty value is not supported. Just a suggestion.

There is no version branch in git. Please follow the instructions related to git structure from here - https://drupal.org/node/1127732 and to set a default branch https://drupal.org/node/1659588

flexman’s picture

Status: Needs work » Needs review

Thanks for the suggestions - very valid, I just overlooked these items.

I have now made the admin settings field required. I have also added a default value in the code (somewhat redundant to add both features but you can never be too safe I suppose).

Also, working on branch 7.x-1.x now. Thanks for the tip.

swim’s picture

Status: Needs review » Needs work

Hey Flexman,

data_block.install, line 22.
Don't use db_query for running delete queries; instead use https://api.drupal.org/api/drupal/includes!database!database.inc/functio...

date_block.module, line 82.
hook_block_view will only invoke blocks defined by your module. This means unless you're going to add more blocks you don't need to perform a switch statement.

For a block focused module I wouldn't implement a menu hook & separate form to store the block settings. This creates confusion. Instead have a look at https://api.drupal.org/api/drupal/modules!block!block.api.php/function/h... &
https://api.drupal.org/api/drupal/modules!block!block.api.php/function/h...

Both of the above hooks are much more suited to your module.

Just a suggestion but I wouldn't worry about including a hook_install. Set your default value where you first implement date_block_default_format, which would be in the setting form in this case.

/**
 * Admin settings.
 */
function date_block_admin_settings() {

  $form['date_block_default_format'] = array(
    '#type' => 'textfield',
    '#title' => t('Date Format'),
    '#description' => t('Enter a user-defined date format. See the !url for available options.', array('!url' => l(t('PHP manual'), 'http://php.net/manual/function.date.php'))),
    '#default_value' => variable_get('date_block_default_format', "F j, Y"),
    '#required' => TRUE,
  );

  return system_settings_form($form);
}

Cheers,

drupaldev@assyst’s picture

Getting some fatal errors using the git repository path provided. Use
git clone --branch master http://git.drupal.org/sandbox/flexman/2141203.git date_block

flexman’s picture

Issue summary: View changes
flexman’s picture

Ah shoot,

I forgot to update the GIT Repository to the latest 7.x-1.x version. I've updated it in the issue description now.

git clone --branch 7.x-1.x flexman@git.drupal.org:sandbox/flexman/2141203.git

drupaldev@assyst’s picture

You should change the URL to clone the project to

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/flexman/2141203.git date_block

Your URL is for the maintainer.

Manual Review:

date_block.install line #22
Use variable_del() function to remove variable on uninstall hook would be ideal. So replace
db_query("DELETE FROM {variable} WHERE name LIKE 'date_block_%'");
with
variable_del('date_block_default_format');

date_block.module line #98
It would be good, if you can use Ternary Operator instead of if/else.

So replace below code in _date_block_content() function

if (variable_get('date_block_default_format')) {
    $date_format = variable_get('date_block_default_format');
  }
  else {
    $date_format = 'F j, Y';
  }

with

$date_format = variable_get('date_block_default_format');
$date_format = !empty($date_format) ? $date_format : 'F j, Y';
flexman’s picture

Issue summary: View changes
flexman’s picture

Status: Needs work » Needs review

Several changes made, including:

  1. Updated some function names (I was incorrectly using date_block_view instead of date_block_block_view)
  2. Removed hook_menu and admin settings page and included the settings within the block (hook_block_configure and hook_block_save)
  3. Updated install file to use variable_set and variable_del
  4. Removed unnecessary switch statements
  5. General code cleanup
  6. Readme and help updates

Thanks.

boyan.borisov’s picture

Status: Needs review » Needs work

Hi flexman,

Congrats for the small and tidy module :) See below my comments:

- you should use format_date() Drupal core function instead of date(). format_date takes in consideration the site timezone and the current language. It's a drupal way to format dates.
- it's a recommended to use $delta in the hook_block_configure - see the example hook_block_configure
- have you try to find other modules which could achieve the same functionality? Drupal community encourages collaboration over competition. What are the benefits of your project compared with clock project?
- also I've seen the core reviewers to reject projects with less than 200 rows of code...

flexman’s picture

Status: Needs work » Closed (won't fix)

Well then...

I thought I had searched for similar modules, I somehow missed the "clock" module. You are right, it performs the exact same functionality (and more).

... on to the next module I guess.

Thanks everyone for the valuable feedback!