Permalink
Browse files

Added the module for the new tutorial.

Signed-off-by: Amitav Roy - Dell <reachme@amitavroy.com>
  • Loading branch information...
amitavroy committed Jun 20, 2012
1 parent abc085a commit 9afe5c648e3bffa51c3e558ad81315cc2993ff26
Showing with 77 additions and 0 deletions.
  1. +6 −0 demoblock/demoblock.info
  2. +66 −0 demoblock/demoblock.module
  3. +5 −0 demoblock/template/userinfo.tpl.php
View
@@ -0,0 +1,6 @@
+name = Demo Blocks
+description = "This module handles all the demo blocks on the site."
+package = Justread Tutorials
+core = 7.x
+
+files[] = demoblocks.module
View
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * This is the code for the demo block module.
+ * This is just for demo purpose when I was writing the
+ * code for the tutorial.
+ */
+
+/**
+ * Implements hook_block_info().
+ */
+function demoblock_block_info() {
+ $blocks['helloworld'] = array(
+ 'info' => t('Demoblock: Hello world'),
+ 'cache' => DRUPAL_CACHE_GLOBAL
+ );
+ $blocks['userdetails'] = array(
+ 'info' => t('Demoblock: User details'),
+ 'cache' => DRUPAL_NO_CACHE
+ );
+
+ return $blocks;
+}
+
+/**
+ * Implementing hook_theme()
+ */
+function demoblock_theme() {
+ return array(
+ 'userinfo' => array(
+ 'template' => 'template/userinfo',
+ )
+ );
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function demoblock_block_view($delta = '') {
+ $block = array();
+
+ switch ($delta) {
+ case 'helloworld':
+ $block['subject'] = t('Hello World!');
+ $block['content'] = _demoblock_helloworld_content();
+ break;
+
+ case 'userdetails':
+ global $user;
+ $block['subject'] = t('Your profile');
+ $block['content'] = theme('userinfo',array(
+ 'username' => $user->name,
+ 'email' => $user->mail,
+ 'timezone' => $user->timezone,
+ ));
+ break;
+ }
+ return $block;
+}
+
+/**
+ * Adding the content
+ */
+function _demoblock_helloworld_content() {
+ return 'Hello World!';
+}
@@ -0,0 +1,5 @@
+<p>Welcome <strong><?php print $username; ?></strong></p>
+
+<p><strong>Your email:</strong><?php print $email; ?></p>
+
+<p><strong>Timezone that you are following:</strong> <?php print $timezone; ?></p>

0 comments on commit 9afe5c6

Please sign in to comment.