Example of writing a node module that lets users add a job posting to a site. A job posting node will include a
title, a body where the details of the job posting will be entered, and a field where the user can enter the
name of the company. For the job posting title and a body, I’ll use the built-in node title and body that
are standard with all Drupal nodes. I’ll need to add a new custom field for the company’s name.
I’ll start by creating a folder named job_post in your sites/all/modules/custom directory.
1. job_post.info file:
name = Job Post description = A job posting content type package = French core = 7.x files[] = job_post.install files[] = job_post.module
2. job_post.install
The install file for the job post module performs all of the set-up operations for things like defining the
node type, creating the fields that make up our new node type, and handling the uninstall process when
an administrator uninstalls the module.
/** * @file * Install file for Job Post module. */ /** * Implements hook_install(). * - Add the body field. * - Configure the body field. * - Create the company name field. */ function job_post_install() { node_types_rebuild(); $types = node_type_get_types(); // add the body field to the node type node_add_body_field($types['job_post']); // Load the instance definition for our content type's body $body_instance = field_info_instance('node', 'body', 'job_post'); // Configure the body field $body_instance['type'] = 'text_summary_or_trimmed'; // Save our changes to the body field instance. field_update_instance($body_instance); // Create all the fields we are adding to our content type. foreach (_job_post_installed_fields() as $field) { field_create_field($field); } // Create all the instances for our fields. foreach (_job_post_installed_instances() as $instance) { $instance['entity_type'] = 'node'; $instance['bundle'] = 'job_post'; field_create_instance($instance); } } /** * Return a structured array defining the fields created by this content type. * For the job post module there is only one additional field – the company name * Other fields could be added by defining them in this function as additional elements * in the array below */ function _job_post_installed_fields() { $t = get_t(); return array( 'job_post_company' => array( 'field_name' => 'job_post_company', 'label' => $t('Company posting the job listing'), 'type' => 'text', ), ); } /** * Return a structured array defining the field instances associated with this content type. */ function _job_post_installed_instances() { $t = get_t(); return array( 'job_post_company' => array( 'field_name' => 'job_post_company', 'type' => 'text', 'label' => $t('Company posting the job listing'), 'widget' => array( 'type' => 'text_textfield', ), 'display' => array( 'example_node_list' => array( 'label' => $t('Company posting the job listing'), 'type' => 'text', ), ), ), ); } /** * Implements hook_uninstall(). */ function job_post_uninstall() { // Gather all the example content that might have been created while this // module was enabled. $sql = 'SELECT nid FROM {node} n WHERE n.type = :type'; $result = db_query($sql, array(':type' => 'job_post')); $nids = array(); foreach ($result as $row) { $nids[] = $row->nid; } // Delete all the nodes at once node_delete_multiple($nids); // Loop over each of the fields defined by this module and delete // all instances of the field, their data, and the field itself. foreach (array_keys(_job_post_installed_fields()) as $field) { field_delete_field($field); } // Loop over any remaining field instances attached to the job_post // content type (such as the body field) and delete them individually. $instances = field_info_instances('node', 'job_post'); foreach ($instances as $instance_name => $instance) { field_delete_instance($instance); } // Delete our content type node_type_delete('job_post'); // Purge all field infromation field_purge_batch(1000); }
3.job_post.module
Last, you need the module file itself. Create a file named job_post.module, After you’ve completed the module, you can enable the module
on the module listings page (Modules). You begin with the opening PHP tag and Doxygen comments.
/** * @file * This module provides a node type called job post */ /** * Implements hook_node_info() to provide our job_post type. */ function job_post_node_info() { return array( 'job_post' => array( 'name' => t('Job Post'), 'base' => 'job_post', 'description' => t('Use this content type to post a job.'), 'has_title' => TRUE, 'title_label' => t('Job Title'), 'help' => t('Enter the job title, job description, and the name of the company that posted the job'), ), ); }
A single module can define multiple node types, so the return value should be an array. Here’s the
breakdown of metadata values that may be provided in the node_info() hook:
"name": The human-readable name of the node type. Required.
"base": The base string used to construct callbacks corresponding to this node
type (i.e., if base is defined as example_foo, then example_foo_insert will be
called when inserting a node of that type). This string is usually the name of the
module, but not always. Required.
"description": A brief description of the node type. Required.
"help": Help information shown to the user when creating a node of this type.
Optional (defaults to '').
"has_title": Boolean indicating whether this node type has a title field. Optional
(defaults to TRUE).
"title_label": The label for the title field of this content type. Optional (defaults
to “Title”).
"locked": Boolean indicating whether the administrator can change the
machine name of this type. FALSE = changeable (not locked), TRUE =
unchangeable (locked). Optional (defaults to TRUE).
Comments
AlfredoLow (not verified)
Sun, 2020-02-02 01:51
Permalink
northwest pharmacies
http://tribtaiti.webcindario.com/ good canadian online pharmacies
canadian online pharmacies legitimate http://tribtaiti.webcindario.com/
canada online pharmacy http://tribtaiti.webcindario.com/
Elisha (not verified)
Fri, 2020-08-07 05:33
Permalink
Add new comment | Moi Verhole
It's a shame you don't have a donate button! I'd most certainly donate
to this brilliant blog! I guess for now i'll settle for book-marking and adding your
RSS feed to my Google account. I look forward to new updates and will talk about this website with my Facebook group.
Talk soon!
Also visit my site hosting services
Kami (not verified)
Mon, 2020-08-31 13:52
Permalink
Add new comment | Moi Verhole
Wonderful, what a website it is! This webpage gives valuable data to us, keep it up.
Also visit my website; best web hosting 2020
AlfredoLow (not verified)
Sun, 2020-02-02 20:31
Permalink
canadian cialis
https://canadianhpharmacy.com/ trust pharmacy of canada
canadian pharmacies without an rx https://canadianhpharmacy.com/
canada medication list https://canadianhpharmacy.com/
AlfredoLow (not verified)
Sun, 2020-02-02 22:40
Permalink
canadian online pharmacies reviews
https://canadianhpharmacy.com/ canada medications cheap
canadian pharmacy king https://canadianhpharmacy.com/
canadian drug https://canadianhpharmacy.com/
Deena (not verified)
Mon, 2020-08-24 03:25
Permalink
Add new comment | Moi Verhole
Highly descriptive article, I enjoyed that a lot.
Will there be a part 2?
My blog post cheap flights
AlfredoLow (not verified)
Sun, 2020-02-02 23:50
Permalink
canadian pharcharmy online
https://viagrawwithoutdoctor.com/ online canadian pharmacy
the best canadian online pharmacies https://viagrawwithoutdoctor.com/
drugstore online shopping reviews https://viagrawwithoutdoctor.com/
Kerstin (not verified)
Fri, 2020-08-28 12:09
Permalink
Add new comment | Moi Verhole
I love what you guys are usually up too. This type of clever work and coverage!
Keep up the great works guys I've included you guys to blogroll.
Feel free to surf to my web-site - black mass
AlfredoLow (not verified)
Mon, 2020-02-03 02:04
Permalink
reputable canadian prescriptions online
https://viagracwithoutdoctor.com/ canada drug pharmacy
canadian pharmacies-24h https://viagracwithoutdoctor.com/
drugs for sale usa https://viagracwithoutdoctor.com/
AlfredoLow (not verified)
Mon, 2020-02-03 04:12
Permalink
canada online pharmacies medication
https://viagracwithoutdoctor.com/ canadian pharmacies stendra
canadian pharmacys https://viagracwithoutdoctor.com/
canadian drug store https://viagracwithoutdoctor.com/
Felicia (not verified)
Tue, 2020-07-28 02:11
Permalink
Add new comment | Moi Verhole
Great web site you have got here.. It's difficult cheap flights to hawaii find high quality writing like yours these days.
I seriously appreciate individuals like you! Take care!!
Jim (not verified)
Tue, 2020-08-25 01:10
Permalink
Add new comment | Moi Verhole
Thanks for finally talking about > Add new comment
| Moi Verhole < Liked it!
Look into my site :: v bucks free
AlfredoLow (not verified)
Mon, 2020-02-03 05:22
Permalink
online pharmacies tech school
https://canadianlpharmacy.com/ canadian pharmacy
discount canadian pharmacies https://canadianlpharmacy.com/
drugs for sale https://canadianlpharmacy.com/
Barb (not verified)
Tue, 2020-08-25 03:47
Permalink
Add new comment | Moi Verhole
Wonderful work! That is the type of info that
are supposed to be shared across the net.
Shame on the search engines for now not positioning this submit higher!
Come on over and seek advice from my website .
Thanks =)
Feel free to surf to my web site - free v bucks
AlfredoLow (not verified)
Mon, 2020-02-03 07:32
Permalink
prescriptions from canada without
https://viagracwithoutdoctor.com/ trust pharmacy canadian
drugs for sale online https://viagracwithoutdoctor.com/
canada online pharmacies legitimate https://viagracwithoutdoctor.com/
AlfredoLow (not verified)
Mon, 2020-02-03 09:41
Permalink
canadian rx world pharmacy
https://canadianlpharmacy.com/ buy viagra 25mg
canada drug pharmacy https://canadianlpharmacy.com/
canadian pharmacys https://canadianlpharmacy.com/
AlfredoLow (not verified)
Mon, 2020-02-03 10:52
Permalink
canadian pharmacies that ship to us
https://canadianhpharmacy.com/ canada pharmacies online prescriptions
canada medication list https://canadianhpharmacy.com/
northwest pharmacy canada https://canadianhpharmacy.com/
Marshall (not verified)
Mon, 2020-08-31 01:28
Permalink
Add new comment | Moi Verhole
You are so cool! I do not believe I've truly read through a single thing like this
before. So nice to find another person with original thoughts on this
topic. Really.. thanks for starting this up. This website is something that's needed on the
web, someone with some originality!
my page :: black mass
AlfredoLow (not verified)
Mon, 2020-02-03 11:58
Permalink
canadian online pharmacies
https://viagracwithoutdoctor.com/ canadian government approved pharmacies
how safe are canadian online pharmacies https://viagracwithoutdoctor.com/
canadian pharmacys https://viagracwithoutdoctor.com/
AlfredoLow (not verified)
Mon, 2020-02-03 13:04
Permalink
canadian pharmacy king
https://canadianhpharmacy.com/ canadian medications list
canada pharmacies account https://canadianhpharmacy.com/
canadian online pharmacies https://canadianhpharmacy.com/
AlfredoLow (not verified)
Mon, 2020-02-03 14:00
Permalink
candida viagra
https://viagrawwithoutdoctor.com/ canada pharmaceuticals online
pharmacy canada online prescriptions https://viagrawwithoutdoctor.com/
canadian pharmacies shipping to usa https://viagrawwithoutdoctor.com/
AlfredoLow (not verified)
Mon, 2020-02-03 14:48
Permalink
best canadian pharmacy
https://viagracwithoutdoctor.com/ most reliable canadian online pharmacies
pharmacy https://viagracwithoutdoctor.com/
aarp recommended canadian pharmacies https://viagracwithoutdoctor.com/
Joy (not verified)
Tue, 2020-08-25 05:51
Permalink
Add new comment | Moi Verhole
Magnificent items from you, man. I've consider your stuff previous to and you are simply too excellent.
I really like what you've got here, certainly like what you're saying and the way by which you are saying it.
You make it enjoyable and you continue to care for to stay it wise.
I can not wait to learn much more from you.
This is actually a terrific site.
Feel free to visit my web-site ... v bucks free
AlfredoLow (not verified)
Mon, 2020-02-03 15:38
Permalink
canadian drugstore
https://viagrawwithoutdoctor.com/ online pharmacy canada
no 1 canadian pharcharmy online https://viagrawwithoutdoctor.com/
canada vagra https://viagrawwithoutdoctor.com/
Dorthy (not verified)
Tue, 2020-08-25 01:27
Permalink
Add new comment | Moi Verhole
Nice replies in return of this issue with genuine arguments and describing everything concerning that.
My web site free the vbucks
AlfredoLow (not verified)
Mon, 2020-02-03 16:11
Permalink
canada drug
https://canadianlpharmacy.com/ northwest pharmacies mail order
order canadian prescriptions online https://canadianlpharmacy.com/
drugs for sale usa https://canadianlpharmacy.com/
Mitzi (not verified)
Fri, 2020-07-31 02:01
Permalink
Add new comment | Moi Verhole
Nice post. I was checking continuously this blog and I
am impressed! Very helpful information specially the ultimate section :)
I maintain such information much. I used to be seeking this particular info for a very long time.
Thank you and good luck.
my page: find cheap flights
Tahlia (not verified)
Tue, 2020-08-25 01:28
Permalink
Add new comment | Moi Verhole
If some one desires expert view about blogging
and site-building after that i recommend him/her to visit this webpage, Keep up
the good work.
Visit my web blog v bucks free generator
AlfredoLow (not verified)
Mon, 2020-02-03 16:48
Permalink
pharmacy canada
https://viagracwithoutdoctor.com/ buy viagra usa
good canadian online pharmacies https://viagracwithoutdoctor.com/
canadianpharmacyusa24h https://viagracwithoutdoctor.com/
AlfredoLow (not verified)
Mon, 2020-02-03 17:28
Permalink
online canadian discount pharmacies
https://viagrawwithoutdoctor.com/ canadian prescription drugstore
canadian government approved pharmacies https://viagrawwithoutdoctor.com/
canada medication prices https://viagrawwithoutdoctor.com/
Gonzalo (not verified)
Tue, 2020-08-25 03:41
Permalink
Add new comment | Moi Verhole
Do you mind if I quote a few of your posts as long as
I provide credit and sources back to your weblog?
My blog site is in the exact same area of interest
as yours and my visitors would certainly benefit from a lot of the information you present here.
Please let me know if this ok with you. Thanks a lot!
Feel free to visit my web site: free vbucks generator
AlfredoLow (not verified)
Mon, 2020-02-03 18:11
Permalink
online drug store
https://canadianhpharmacy.com/ canadian discount pharmacies in canada
pharmacy https://canadianhpharmacy.com/
canadian pharmaceuticals reviews https://canadianhpharmacy.com/
Precious (not verified)
Sun, 2020-06-21 19:11
Permalink
Add new comment | Moi Verhole
That is very attention-grabbing, You're an overly professional blogger.
I have joined your rss feed and stay up for in search of extra of your wonderful post.
Additionally, I have shared your web site in my social networks
Feel free to surf to my webpage many g
Marguerite (not verified)
Tue, 2020-08-25 02:40
Permalink
Add new comment | Moi Verhole
I think what you published made a lot of sense.
But, what about this? suppose you were to create a killer headline?
I ain't saying your information isn't good, however what if you added a
post title that makes people desire more? I mean Add new comment
| Moi Verhole is kinda vanilla. You ought to peek at Yahoo's home page and watch how they
create post headlines to grab people interested. You might
add a video or a picture or two to get people excited about what you've written.
Just my opinion, it would bring your blog a little
bit more interesting.
Also visit my web-site :: free vbucks
AlfredoLow (not verified)
Mon, 2020-02-03 18:55
Permalink
viagra canadiense
https://viagracwithoutdoctor.com/ canada drugs online
drugstore online india https://viagracwithoutdoctor.com/
pharmacy onesource https://viagracwithoutdoctor.com/
Marie (not verified)
Mon, 2020-08-24 23:45
Permalink
Add new comment | Moi Verhole
Yesterday, while I was at work, my sister stole my iPad and tested to see if it can survive a 25 foot
drop, just so she can be a youtube sensation. My apple ipad is now broken and she has
83 views. I know this is entirely off topic but I had to share it with someone!
Visit my web page - senzori pescuit
Liam (not verified)
Tue, 2020-08-25 05:31
Permalink
Add new comment | Moi Verhole
Hey terrific blog! Does running a blog like this require a
lot of work? I've absolutely no expertise in coding
however I was hoping to start my own blog in the near future.
Anyways, should you have any suggestions or tips for new blog owners please share.
I know this is off topic however I simply had to ask.
Appreciate it!
Review my web blog: v bucks free
Vallie (not verified)
Mon, 2020-08-31 01:57
Permalink
Add new comment | Moi Verhole
If some one needs expert view concerning blogging and site-building after that
i suggest him/her to pay a visit this web site,
Keep up the fastidious job.
Have a look at my blog post: black mass
AlfredoLow (not verified)
Mon, 2020-02-03 19:42
Permalink
canadian pharmaceuticals nafta
https://viagracwithoutdoctor.com/ canadian mail order pharmacies
drugs for sale in mexico https://viagracwithoutdoctor.com/
top rated canadian pharmacies online https://viagracwithoutdoctor.com/
Kourtney (not verified)
Mon, 2020-08-24 03:14
Permalink
Add new comment | Moi Verhole
My brother recommended I might like this website.
He was entirely right. This post actually made my day. You cann't imagine simply how
much time I had spent for this info! Thanks!
my blog cheap flights
AlfredoLow (not verified)
Mon, 2020-02-03 20:32
Permalink
pharmacy canada
https://viagracwithoutdoctor.com/ canadian pharmaceuticals companies
canadian medications 247 https://viagracwithoutdoctor.com/
canada medication list https://viagracwithoutdoctor.com/
AlfredoLow (not verified)
Mon, 2020-02-03 21:25
Permalink
northwest pharmacies mail order
https://canadianlpharmacy.com/ canadian rx world pharmacy
canadian pharcharmy online https://canadianlpharmacy.com/
drugs for sale https://canadianlpharmacy.com/
Merissa (not verified)
Mon, 2020-08-24 03:03
Permalink
Add new comment | Moi Verhole
I couldn't refrain from commenting. Well written!
Take a look at my site; cheap flights
AlfredoLow (not verified)
Mon, 2020-02-03 23:49
Permalink
canada online pharmacies
https://viagrawwithoutdoctor.com/ canadian pharmacy meds
drugs for sale on internet https://viagrawwithoutdoctor.com/
drugs for sale deep web https://viagrawwithoutdoctor.com/
AlfredoLow (not verified)
Tue, 2020-02-04 00:44
Permalink
canadian online pharmacy
https://canadianlpharmacy.com/ Canadian Pharmacy USA
online pharmacy https://canadianlpharmacy.com/
online pharmacies india https://canadianlpharmacy.com/
Glinda (not verified)
Mon, 2020-08-24 23:33
Permalink
Add new comment | Moi Verhole
Wonderful, what a weblog it is! This website gives valuable facts to us,
keep it up.
Feel free to visit my homepage ... bigfish
AlfredoLow (not verified)
Tue, 2020-02-04 01:28
Permalink
cialis from canada
https://viagrawwithoutdoctor.com/ canadian pharmacies stendra
canadian drug https://viagrawwithoutdoctor.com/
drugstore online shopping reviews https://viagrawwithoutdoctor.com/
AlfredoLow (not verified)
Tue, 2020-02-04 02:18
Permalink
canada vagra
https://canadianhpharmacy.com/ pharmacy canada reviews
canadian discount pharmacies in ocala fl https://canadianhpharmacy.com/
safe canadian online pharmacies https://canadianhpharmacy.com/
Isobel (not verified)
Tue, 2020-08-25 04:16
Permalink
Add new comment | Moi Verhole
fantastic points altogether, you just won a new reader. What may you recommend in regards to your post that you
made a few days ago? Any positive?
My blog :: free vbucks generator
AlfredoLow (not verified)
Tue, 2020-02-04 03:01
Permalink
canadianpharmacyusa24h is it legal
https://viagracwithoutdoctor.com/ canadian pharcharmy online24
online pharmacy https://viagracwithoutdoctor.com/
canadian pharmacy uk delivery https://viagracwithoutdoctor.com/
Pages
Add new comment