-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created a cg_core module with a settings form for homepage blocks #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = cg_core | ||
description = This module contains our custom code, as well as dependencies, ideally allowing us to 'rebuild the site' simply by enabling this module. It also contains a settings form so that the client can edit the homepage blocks. | ||
core = 7.x | ||
version = 7.x-1.x |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
function cg_core_enable() { | ||
drupal_set_message($message = t('The cg_core module was successfully enabled.'), $type = 'status'); | ||
|
||
$enable = array( | ||
'theme_default' => 'cg_theme', | ||
//'zen' | ||
); | ||
theme_enable($enable); | ||
|
||
foreach ($enable as $var => $theme) { | ||
if (!is_numeric($var)) { | ||
variable_set($var, $theme); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* Implementation of hook_menu() | ||
*/ | ||
function cg_core_menu(){ | ||
// desired path location: http://www.oursite.com/our/form | ||
$items['admin/config/system/cg_settings'] = array( | ||
// page title | ||
'title' => 'Homepage Settings', | ||
// describe the page for the menu system. site visitors will not see this | ||
'description' => 'Staff configurable page with custom settings form.', | ||
// function that is called when visiting the new path to generate the page's content | ||
'page callback' => 'cg_core_settings_form', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lesson 075 was updated during class when we created the settings form for HA. There was an issue with the 'page callback' line - we instead need to set the page callback as 'drupal_get_form', and the 'page arguments' as your function's name. Check the updated lesson for exact differences: |
||
// permissions required to view page | ||
'access arguments' => array('administer site configuration'), | ||
); | ||
return $items; | ||
} | ||
|
||
/** | ||
* Page callback: Custom settings form | ||
*/ | ||
function cg_core_settings_form($form, &$form_state) { | ||
$form['my_custom_blocks1'] = array( | ||
'#type' => 'textarea', | ||
'#title' => t('Block 1'), | ||
'#default_value' => variable_get('mycustom_blocks', 'Welcome to our site'), | ||
'#size' => 50, | ||
'#maxlength' => 200, | ||
'#description' => t('The content inside Block 1'), | ||
'#required' => TRUE, | ||
); | ||
|
||
$form['my_custom_blocks2'] = array( | ||
'#type' => 'textarea', | ||
'#title' => t('Block 2'), | ||
'#default_value' => variable_get('mycustom_blocks', 'Welcome to our site'), | ||
'#size' => 50, | ||
'#maxlength' => 200, | ||
'#description' => t('The content inside Block 2'), | ||
'#required' => TRUE, | ||
); | ||
|
||
$form['my_custom_blocks3'] = array( | ||
'#type' => 'textarea', | ||
'#title' => t('Block 3'), | ||
'#default_value' => variable_get('my_custom_blocks', 'Welcome to our site'), | ||
'#size' => 50, | ||
'#maxlength' => 200, | ||
'#description' => t('The content inside Block 3'), | ||
'#required' => TRUE, | ||
); | ||
|
||
return system_settings_form($form); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI This comment // zen is considered 'cruft' from an example. i.e. extra code that doesn't benefit us. This line should be removed. Comments should only be there to simplify our ability to understand the code. Even then, the less comments the better - you want your code to explain itself by being well-spaced and well-written.