This course will be retired on February 24, 2020.
Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Extending Your First Module4:29 with Diane Douglas
In this video, we continue to develop our module by making it create a second page to say "Goodbye friend!".
If we are building a module called 'my_module', it needs 3 things to get started.
- A folder called 'my_module' to be located in sites/all/modules
- A file called 'my_module.info' to be located in the 'my_module' folder.
- A file called 'my_module.module' to be located in the 'my_module' folder.
.info file always needs five things defined:
When we enabled our new module, it made a page to say hello to our users.
Now, let's practice some more by having it make a page with a menu item like this.
Which says goodbye to them.
We can modify the items array in our greeting menu function to do this too.
Right now, items only has one key value pair for our hello_friend menu item.
But it could have as many as we like.
Let's add another key value pair to create a menu item.
Which takes us to the good bye page we're going to make.
Then we'll create the good bye page itself
by adding a function named in the menu item's page callback attribute.
We only need to modify the greeting.module file.
No need to change the .info file.
So just as we created items at hello_friend, I'm going to create items
at goodbye, and set that equal to another array.
And just so that I don't forget, I put the semi-colon at the end first.
Now just as in hello_friend, it's going to need the title attribute,
which we will set to Goodbye Friend.
Don't forget the comma.
And then the next attribute is the page callback,
which we want to set to the function name, "say_goodbye." And
don't forget that needs to be in quotes.
Follow it by a comma and then we have the access callback
which we will also set to true.
Just like the last one so that anyone can see our goodbye page.
And then finally we save 'type' is= MENU_NORMAL_ITEM just like the last one.
This is what creates the menu item in our navigation menu.
Now we need actually create the say goodbye function.
So again down here, I will use the keyword
function and then say_goodbye.
Empty parenthesis because it doesn't need any arguments.
Curly brackets and this one will return.
Again, a paragraph tag.
Goodbye my dear friend.
Close the paragraph tag, and that's it.
Remember to hit save.
To see the results of our changes, we must first clear Drupal's caches.
In general, if you change something in your module, and
you don't see a difference in your website, you will have to clear the cache.
It's similar to clearing your browser cache.
Basically, to increase performance, Drupal tries to save information and
to not re-render a page if it doesn't have to.
Clearing the cache before trying out your module ensures that
Drupal loads the newest version of your code, including any recent changes.
So back in the web interface, I'm going to click on configuration in the management
menu, and then, I'm going to find performance under development.
At the top of this page click Clear all caches.
If you do this and you still don't see changes in your
code reflected in your site, you will have to go to the modules page.
And then disable your module, save it.
And then find it again and re-enable it.
And Save configuration one more time.
Now if you click back to Home,
you'll see a second link under Navigation labeled Goodbye Friend.
Click on this link, and you'll be taken to localhost:8888/goodbye.
And you'll see your new text, Goodbye my dear friend!, displayed on this page.
If you click back Home,
the Hello Friend link should also still take you to its page.
You need to sign up for Treehouse in order to download course files.Sign up