Site Tools


Hotfix release available: 2024-02-06a "Kaos". upgrade now! [55.1] (what's this?)
New release available: 2024-02-06 "Kaos". upgrade now! [55] (what's this?)
Hotfix release available: 2023-04-04a "Jack Jackrum". upgrade now! [54.1] (what's this?)
New release available: 2023-04-04 "Jack Jackrum". upgrade now! [54] (what's this?)
Hotfix release available: 2022-07-31b "Igor". upgrade now! [53.1] (what's this?)
Hotfix release available: 2022-07-31a "Igor". upgrade now! [53] (what's this?)
New release available: 2022-07-31 "Igor". upgrade now! [52.2] (what's this?)
New release candidate 2 available: rc2022-06-26 "Igor". upgrade now! [52.1] (what's this?)
New release candidate available: 2022-06-26 "Igor". upgrade now! [52] (what's this?)
Hotfix release available: 2020-07-29a "Hogfather". upgrade now! [51.4] (what's this?)
internal:dev_w:module_creation

Procedure to create a new block

Step-1 :

Create a new folder (new_folder) under sites/all/modules/core/<package_name>/<learner/admin package_name>/modules. Create new_folder.info file in the same folder which contains information about what new module does.
Example : 
sites/all/modules/core/exp_sp_survey/exp_sp_survey_learner/exp_sp_survey_learner.info

Step-2 :

Create new_folder.module file in the same folder (new_folder) to write business logic.
Example:
sites/all/modules/core/exp_sp_survey/exp_sp_survey_learner/exp_sp_survey_learner.module

Step-3 :

Create new_folder.inc file to interact with DB to get data. This file can contain user-defined functions.
Example :
sites/all/modules/core/exp_sp_survey/exp_sp_survey_learner/exp_sp_survey_learner.inc

Step-4 :

hook is new_folder. create hook_block in new_folder.module file. hook_block is used to display the block in admin page and view the content in admin/learner page. The block can be assigned to particular region for corresponding theme.
Example :
function exp_sp_survey_learner_block($op='list', $delta=0) {
	$blocks=array();
	switch($op) {
		case 'list':
			$blocks[0] = array('info' => t("Learner Survey"));
			$blocks[0]['cache'] = BLOCK_NO_CACHE;			
			return $blocks;
			break;
		case 'view':
			require_once('exp_sp_learner_survey.inc');		
			switch ($delta) {
				 case 0:
					$blocks["subject"] = t("Learner Survey");
					$blocks['content'] = getsurveyDetails();
					return $blocks;
				break;    			
			}
		break;
	}
}
In the above example, first case to display the block information in admin page.
The second case to store the content which is retrieved from new_folder.inc file. the content to be passed to block-new_folder.tpl.php of theme_folder.	

Step-5 :

      Use Camel case to define new function.
Example :
function getSurveyDetails(){ 	
	return 'content';
}	

Step-6 :

Create a block-new_folder.tpl.php file under themes/core/expertusone/templates folder.
Example :
themes/core/expertusone/templates/block-exp_sp_survey_learner.tpl.php

Display a block for particular pages.

Step-7 :

After finished the above steps, we should assign the created block to some region in the build/block section.
Browse the below the URL in browser,
	http://<sitename>/?q=admin/build/block/list/expertusone
Here we can find the block info name which we specified in the new_folder.info file.
Assign this module to some region.
Once assigned the module, click on 'configure' link which is near by region dropdown in the same page.
	Example :
	http://www.expertusone.com/?q=admin/build/block/configure/exp_sp_survey_learner/0
In the upcoming page, put the below entry under 'Pages' 
	Example : learning/survey-details
Click on 'Save block' button

Now we can test our module by browsing the below URL.

http:<sitename>/?q=learning/survey-details/

internal/dev_w/module_creation.txt · Last modified: 2022/06/14 10:16 (external edit)