Gosh! i never thought that my memory would be this bad. As of today, i was doing my refreshment on array cause drupal use excessive array in its coding and i'm quite not comfortable with arrays, so i though going through a simple PHP program could benefit me. So I typed down some simple codes making use of arrays, then when i want to use a simple iteration command like for, i kinda not sure of correct way of using it. This is bad as for-while and any looping structure are basics in PHP, and how can i have forgotten on how to use them correctly. So i opened up some of my previous codings that i have written. There were a lot of libraries that i have written for my earlier Wordpress projects so i thought i could recall easier by studying previous familiar codes. Well, i'm sort of lost with some of my own PHP commands which i found them as peculiar. It looks like i have lost so much in my programming touch in the past 2 years.
I can only blame myself for being such silly wasting my effort and time on office work!
.
All about the children. It is merely a free flow of thoughts that require no plan of putting it together to make a nice story. This site is never intended to be read by other people nor does it plan to get any followers.
Showing posts with label writing my own drupal module. Show all posts
Showing posts with label writing my own drupal module. Show all posts
Wednesday, April 11, 2012
Tuesday, April 10, 2012
Nuisance in drupal module writing
What i hate most about writing drupal codes and want to see it live is; every time you add/change new codes even if they are short ones you need to disable and enable that specific module. It's not like drupal provides a button or link at each module where you can simply reset, they don't have this simple shortcut. This matter has becoming a nuisance already for me, and it makes worse when your computer like mine is a fucking slow unrealiable-sonnomabitch-machine. It'll take ages if i were to see the complete outcomes based on the final codes.
i wish there is some kind of mechanism or technique that i never need to re-enabling & re-disabling modules each time i update the codes. It should be just live changes onscreen without a need to reset once you have done with your errorless codes
i wish there is some kind of mechanism or technique that i never need to re-enabling & re-disabling modules each time i update the codes. It should be just live changes onscreen without a need to reset once you have done with your errorless codes
Monday, April 9, 2012
How do you write anything on drupal framework page
as of now, what i have learnt in order to type or to display something onscreen are as follows:
SO, the question bungling in my mind currently is; how can i produce any contents without a need to go through help, menu or block? Anyway is this a valid question?
- i can use command hook_help(). Need to pass 2 variables; eg buat_sendiri_help($path, $arg). In order to display something onscreen, i must use return *text*, otherwise nothing will be displayed.
- Use command hook_block_view(). need to pass a variable; eg buat_sendiri_block_view($delta=''). In this hook command, i need to assign the key name 'subject' and 'content'. Any assignments to those keynames (subject & content) will be displayed inside the block region. Same thing as hook_help(), i must return value at the end of the hook_block_view(). Anyway, the earlier step that must declared before using hook_block_view() is to use hook_block_info(); this is for declaration purpose where i assign the unique name of the block & some key name values. Eg of assigning unique block name is $block['buat_sendiri'].
- Use command drupal_get_form() where i need to pass a custom function name inside the brackets; eg drupal_get_form('buat_sendiri_contents'). However, inside my tutorial, the way of the coding calls drupal_get_form() is via another hook function called hook_menu(); eg buat_sendiri_menu(). I create an associative array where some keynames of the array are assigned with values. The keyname to call function drupal_get_form() is 'page callback' => 'drupal_get_form', and 'page arguments' => array('buat_sendiri_contents'). In short, the way of assigning values to keynames 'page callback'=>'drupal_get_form' & 'page arguments' => array('buat_sendiri_contents') is equivalent to triggering function drupal_get_form('buat_sendiri_contents').
Like typical hook functions, i must return the value *form* at the end of line when using drupal_get_form(). Here for more info on drupal_get_form(). How do i return *form* is by using system_settings_form($form).
SO, the question bungling in my mind currently is; how can i produce any contents without a need to go through help, menu or block? Anyway is this a valid question?
variable_set(), variable_get() and system_setting_form()
Some explanations on the use of variable_set(), variable_get() and system_setting_form().


You can get the complete info here.


You can get the complete info here.
mental note on drupal form coding
This is a mental note for me to do. I need to make a summary of what are the things that i've learnt when developing form in drupal. Until now, i can only summarise that there are too many complex commands that require me to understand. So it's better if i can summarise them all in a single illustration so that it's easier to mentally digest.
.
.
Friday, April 6, 2012
Writing drupal module - Form creation
After 3 days have passed, i finally able to continue my drupal module coding. Today, what i did is creating form elements inside drupal site.
The order of creating form in drupal is like this:
And the following videolog is the output from the new codes
The order of creating form in drupal is like this:
- use command 'page callback' where its value is the key function in drupal called drupal_get_form()
- use command 'page arguments' whose value is an array that contains a value referring to a name of function (must use underscore in a single word, eg: nama_saya_shahrul. this value - nama_saya_shahrul will be passed to key function drupal_get_form() for drupal to process the form.
- Create function nama_saya_shahrul($form, &$form_state), this is just an example.
- use variable array that has the followings (make sure you never miss out the hash)
- #type
- #title
- #description
- #default_value
- #size
- #maxlength
- #required
- #type
- Need to use another drupal-specific function called variable_get('nama_textfield',default-value). I think variable_get() is similar to session() or assigning value to hidden form field where we can retrieve them later on.
- last but not least is using system_settings_form($form) function.
And the following videolog is the output from the new codes
Monday, April 2, 2012
Trouble shoot drupal menu module - successful
There is something not that clear about the explanation on using the function hook_menu() and its associative array keyname as in the drupal doc site. There is one particular passing variable that i do not understand how it's used and how does it pass values to other created custom function namely current_posts_form(). The key function used here is drupal_get_form(), it is only used once in the hook_menu() but does not have its own function declared in my codes.
Below is videolog that shows how i managed to point out the error i made. Anyway, frankly speaking it is actually not a programmatical errors but it is simply because of the function callback declared inside the associative array that is not declared inside my codes. So, whenever drupal core program searches for the callback function and it cannot find one, that's when it produces such error.
in a nutshell what i did to rectify the error was; i create an empty function content_posts_form() so that drupal core program can pick it up although it does nothing, so when reset the module (deactivate & reactivate) the content shows no error but with empty content body.
.
Below is videolog that shows how i managed to point out the error i made. Anyway, frankly speaking it is actually not a programmatical errors but it is simply because of the function callback declared inside the associative array that is not declared inside my codes. So, whenever drupal core program searches for the callback function and it cannot find one, that's when it produces such error.
in a nutshell what i did to rectify the error was; i create an empty function content_posts_form() so that drupal core program can pick it up although it does nothing, so when reset the module (deactivate & reactivate) the content shows no error but with empty content body.
.
Labels:
debugging,
drupal,
menu,
writing my own drupal module
Writing drupal Module - Menu
Today i managed to make an uninterrupted time solely to write another drupal module. This is specifically to create a link at the menu region on the LHS of the site.
However, since there are still errors that require me to debug; i still do not where and what it is, so i just upload the so-called first part of the videolog writing a menu module. This is quite long video with 10min duration.
the following is the error produced from the module that i wrote:
However, since there are still errors that require me to debug; i still do not where and what it is, so i just upload the so-called first part of the videolog writing a menu module. This is quite long video with 10min duration.
the following is the error produced from the module that i wrote:

Saturday, March 31, 2012
PDO php in drupal
When i was reading about connection to dB in drupal, i come across a lot of unsual & unfamiliar connection method in drupal that has something to do with PDO. So ichecked in php.net & google it. So, this is what i found; PDO is one of php techniques in connecting to database regardless of its type (MySql, Oracle, Postgress). Anyway there is not much doc about it in php.net. there are few references in other links though as follows:
Labels:
database,
drupal,
PDO,
writing my own drupal module
Thursday, March 29, 2012
Downloading module Devel
I'm still searching for one page that tells me about a good practice of installing 3 modules in drupal for debugging purpose. Until now, i have no clue where i have read the page.
Damn!
Wednesday, March 28, 2012
Writing drupal module - displaying the block on page
As of now, i've completed my codes on the entire module for displaying a block at RHS region of my drupal framework. However, i haven't enabled it and see the results. On my 3rd attempt of coding (this is a continuation of the series of writing drupal module of block) i have encountered few things, one of which is the use of array in drupal. I realise that drupal is overusing arrays in every function it has in particular is associative array. As i'm not really fond of using array in my past PHP experience, i find it rather not-comfortable.
Anyway, in short, here are some new things wrt coding tutorial:

Anyway, in short, here are some new things wrt coding tutorial:
- Using hook() function called hook_block_view(). This function is used to display out the block content onto the page. the function has passing variable, i name it as $param where it stores the unique id (aka name) of the block.
- Use of switch to filter only id=buat_sendiri. This means, there could be a lot other blocks in any regions that carry their own IDs or names.
- The use of array variable where i must assign at least 2 key name; (1) subject (2) content. I need to assign 'subject' and 'content' with appropriate names and content values.
- using the custom function that i've written earlier, namely buat_sendiri_content(). This function passes the result in array format to a new defined array parameter called $result.
- create one array that will store all iterated data from $result. This can be achieved using foreach(). Here i call the new array as $item
- assigning the iterated data like this -> $item[] = array ('data' => iterated-data);
- After completing foreach(), need to assign 'content' with values from $item[].
- Using theme() <------ This one aku kurang faham lagi!!!


Writing drupal module - block with database connection
this is a continuation of my codes done previously to create a block region on right hand side of drupal framesite where it shall display list of contents. This videolog in particular shows the code for database connection via command db_select()->...
In summary, what i've learnt from this exercise are:
Below is the doc on getdate() that i extracted from php.net. The values return are used in mktime().


.
In summary, what i've learnt from this exercise are:
- writing custom function for buat_sendiri module; this has nothing to do with hook() functions.
- Using php time functions; such as getDate(), mktime(hr, min, sec, month, day, year), time()
- *** most important command - Using db_select() class. the usage is => db_select('table_name','alias')->fields('alias',array('table_field')->condition('table_field',value)->orderBy('table_field','ASC/DESC')->execute(). an array variable should be assigned to db_select()
Below is the doc on getdate() that i extracted from php.net. The values return are used in mktime().


.
Labels:
drupal,
writing block,
writing my own drupal module
Tuesday, March 27, 2012
Writing drupal module - block
I finally completed making a videolog of a tutorial on writing drupal module that i've re-did this for the 3rd time. The earlier 2 videos that i have produced are lengthy so it's difficult for me to produce a nice watchable video for Youtube. So i made few attempts just to ensure that the outcome of the video is short enough for viewers to watch and requires reasoanably short time to upload to YouTube.
Anyway, the complete codes are still not enough because it still require the retrival of info from drupal dB and codes on presenting the content inside a block.
.
This is the summary of what i've learnt

Labels:
drupal,
writing block,
writing my own drupal module
Monday, March 26, 2012
Wednesday, March 21, 2012
How-to links on Drupal Doc
I find it helpful when Drupal Doc lists down some howto topics. It shows some links on writing own module starting from the beginner level to more complicated areas.
Module HowTos

Module HowTos


Thursday, March 15, 2012
Wednesday, March 14, 2012
Yess, my drupal module works!
Based on my 1st attempt last nite before going to sleep on writing my own custome drupal module, i rewrite the same coding of drupal module. But this time, when i encountered the error which i've already expected it beforehand, i did some tweaking on the filenames as well as the directory name. it looks like the error was due to a very silly mistake; drupal or PHP in drupal does not understand the dash use in filename/directory or the function names.
So my next mission is to create a simple form template in drupal and by keying some values with some validations, drupal will insert the data into the database. Well, i could not wait and eager to see the wonders i can achieve from this learning curve and experience.
Mind the noisy surrounding background, i could not able to set up the sound recording properly. So at the end after giving up i settled down with my notebook's internal microphone. My apology.
..
So my next mission is to create a simple form template in drupal and by keying some values with some validations, drupal will insert the data into the database. Well, i could not wait and eager to see the wonders i can achieve from this learning curve and experience.
Mind the noisy surrounding background, i could not able to set up the sound recording properly. So at the end after giving up i settled down with my notebook's internal microphone. My apology.
..
Labels:
drupal,
first attempt,
writing my own drupal module
Subscribe to:
Posts (Atom)