Our company often uses the Panels module for web portal development. Although this option adds a considerable amount of HTML structures, it provides us with a flexible, user-friendly, and easy-to-operate mechanism. However, sometimes the built-in features of the module are not sufficient (non-standard customer requirements or an in-house desire to perform the same functions as before, but in an even better manner).Ctools content types are like standard blocks in Drupal, but they also have certain advantages:
- ability to display any information - views, forms, HTML
- these entities are well structured - theming, preproсess and the setting form for each ctools content type contains a built-in description.
- they work with contexts panels
- easy-to-implement form of display settings.
Let us look through the process of creating a ctools content type, shall we. We will create a module "ctools_example" for this. The module call hook_ctools_plugin_directory (), which indicates the ctools plugins folder location specified type. The hook has two options:
- $ Plugin_type – the name of the parameter is self explanatory- this is the name of the string type plug-in ('Panels', 'layouts', 'styles', etc.)
- $ Owner - required parameter, because ctools observes namespace plugins depending on what modules they belong to. Usually, the path is "plugins/$ plugin_type".
/* * Implements hook_ctools_plugin_directory - */ function ctools_example_ctools_plugin_directory($owner, $plugin_type) { if ($owner == 'ctools' && $plugin_type == 'content_types') { return 'plugins/content_types'; } }
Then, create a folder "plugins / content_types" and insert the file with our plug-in, such as "ctools_example_content_type.inc". First, describe the plugin in this file. Available options are:
- 'title' - the name of our content type
- 'description' – a detailed description of it
- 'single' - if this is labeled TRUE, then the content type has no subtypes
- 'content_types' - an array that defines the properties of a particular content type or a function that returns this array
- 'render callback' - the name of the function that will be responsible for the display of the block
- 'defaults' - the default context
- 'edit form' - the name of the function which will be responsible for the display of the content type edit form
- 'icon' - the icon displayed in the admin interface. The icon should be placed in the folder with the plugin 'category'
- 'category' - the category to which the newly-created content type will belong