Creating a custom content type manually
Video: Creating a custom content type manuallyPreviously, I demonstrated how to add persistent variables to module, then how to remove them cleanly using hook install and hook uninstall. When creating and destroying a content type the same hooks are used, which is logical. Open the IDE and navigate the windfarms. install file and navigate to hook_install following the message to the user. I'm going to define the content type itself using an associative array. Start with the variable definition named content type, Content type definition, content_type = array. The order of the keys is unimportant, but I'll use a logical progression.
- Creating a custom permission
Viewers: in countries Watching now:
Extend your Drupal 7 sites with custom modules, which allow you to create everything from admin interfaces to forms. Author Jon Peck describes how modules extend your base Drupal installation, then walks through how to write your own module with a practical example featuring geo-positioned alternative energy centers. The course also describes how to control access to site features, create new content types, build forms, understand data persistence, embrace coding standards, and much more.
- Creating your first module
- Interacting with hooks
- Working with permissions and roles
- Controlling access
- Adding a menu item to an admin interface
- Using the Form API (FAPI) to quickly create a form
- Creating custom form validation
- Manually creating a custom content type
- Validating user input
- Importing content using feeds
- Creating a block
- Understanding best practices and coding standards
Creating a custom content type manually
Previously, I demonstrated how to add persistent variables to module, then how to remove them cleanly using hook install and hook uninstall. When creating and destroying a content type the same hooks are used, which is logical. Open the IDE and navigate the windfarms. install file and navigate to hook_install following the message to the user. I'm going to define the content type itself using an associative array. Start with the variable definition named content type, Content type definition, content_type = array. The order of the keys is unimportant, but I'll use a logical progression.
First, the type of content. This is a machine name. All lower case with spaces instead of underscores. In this case, I will use windfarm as the name of the content type. Next, a human readable name for the content type. I will use the T variable for the Translation function, since hook installed for a module can be called during site installation. Name is Wind Farm, following the name a brief description.
A Wind Farm, including location. The next key is for the title label, title_label. This is shown on the edit page. Usually it's just title. This is used as the heading of the page. In the case of a wind farm it doesn't have a title, it has a name. Based on the data set that I'll import later, I'll use a more generic label of facility name to cover the different types of wind farms.
A content type has a base which refers to the source of hooks that are used for various events such as loading and saving. Drupal provides a number of these by default with nodes. To use them, I must explicitly declare that I'm going to use node content as the base, base, node_content. Finally, there is a flag that needs to be set that indicates with this custom type was added via the add content type interface.
This isn't actually true, but it gives site administrators at additional flexibility if they like to manipulate the content type, custom TRUE. There are a large number of settings for a content type, but most of them can be left on their defaults. Drupal offers a function that will go through the settings and only set the ones that are missing and I'll use that to complete the content type definition for a node. Set remaining definitions with defaults.
Node_type = node_type_set_defaults which takes the parameter of the content type. Now that the base structure is complete, save the content type using the function node_type_save which takes the array structure that I defined as the parameter. Save the content type, node_type_save, node_type. Later on, I will fully define how to remove the content type and everything associated with it.
For now, just save the windfarm.install file. At this time the base content type has been added with only a title. If I were to uninstall the module then reinstall the content type for wind farm would be created, but it wouldn't be very useful in that it would only have one editable field, the facility name. I'll cover adding custom fields in the next segment.
Find answers to the most frequently asked questions about Drupal 7 Custom Module Development .
Here are the FAQs that matched your search "" :
- Q: gmap3_tools is not working the way I expected it to. What version of gmap3_tools should I be using?
- A: Use the free exercise file containing the version of gmap3_tools used for recording; the published version of the module on drupal.org has changed since recording and is not backwards compatible.
- Q: I attempted to run the Drupal site root from the project files, but the site isn't loading. Why not?
- A: The Drupal configuration file in sites/default/settings.php contains database configuration specific to the environment used to record the movie. This may be different than your environment. Edit the file and search for "windfarms" - you may need to change the database host, username, password, db name and port to match your specific environment.
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.