In this project, I’m using both Drupal Blocks and Panels Panes. Blocks are used in the overall site layout/theme. Panes are used within the content area. Currently, there are five custom Panels layouts, and 15 custom Pages. Panels has made the content area customization significantly more straightforward.

Note: This is implemented using Panels 7.x-3.0-alpha2 and Chaos Tools 7.x-1.0-alpha4. Check your version.

In most projects, I create Custom Blocks with hook_block(Drupal 6) or hook_block_info(Drupal 7). The primary reason is to reduce the chance of the site maintainer accidentally deleting an important block. A secondary reason is to avoiding enabling the PHP Filter module, which can cause many other issues for the site maintainer. In this project, I’m using both Drupal Blocks and Panels Panes. Blocks are used in the overall site layout/theme. Panes are used within the content area. Currently, there are five custom Panels layouts, and 15 custom Pages. Panels has made the content area customization significantly more straightforward. Panels & Page Manager allow you to use Blocks as Panes, but for consistency, I want to only use Panes with Panels. What follows is the most basic implementation of a custom Panels Pane Content Type. You’ll need to be familiar with creating a custom module. Implementation

  1. Create a new module and info file. I prefer to name them in the form [site-name-acronym]_[purpose].module and place custom modules in /sites/all/modules/custom/[module_name].

  2. Edit the info file and add the minimum information: name = Site Panes description = Creates miscellaneous Panels Panes used by the site. package = Custom core = 7.x php = 5.2

  3. Edit the module file and add an implementation of hook_ctools_plugin_directory(). This tells ctools where to search for your plugins.

  4. Create a directory within your module’s root titled plugins.

  5. Create a directory within plugins titled content_types.

  6. Create a file within content_types named for your new content type: [content_type].inc.

  7. Add the following into the file:

    <?php
    /**
     * Plugins are described by creating a $plugin array which will     be used
     * by the system that includes this file.
     */
    $plugin = array(
      'title' => t('Custom pane'),
      'description' => t('Custom pane for the site.'),
      'category' => t('Custom'),
      'single' => TRUE,
      'content type' => '[content_type]',
    );
    
    /**
    * Output function for the '[content_type]' content type.
    */
    function [site-name-acronym]_[purpose]_[content_type]    _content_type_render($subtype, $conf, $panel_args, $context) {
      $block = new stdClass();
    
      $block->title = "Title";
      $block->content = "Custom pane content";
      return $block;
    }
    
    /**
    * Returns an edit form for the custom type.
    */
    function [site-name-acronym]_[purpose]_[content_type]    _content_type_edit_form(&$form, &$form_state) {
      //Reference
    }
    
    /**
    * Returns an edit form for the custom type.
    */
    function [site-name-acronym]_[purpose]_[content_type]    _content_type_edit_form_submit(&$form, &$form_state) {
      //Reference
    }
    

    The $plugin array is processed by ctools, so the system is aware of what the file provides. [module_name]_[content_type]_content_type_render() is where the pane output is created.

  8. Enable your new custom module.

  9. Add your new Pane to a Page.

There are many more available options and features, but this the minimum to create a new Pane. Thanks to http://shellmultimedia.com/articles/creating-content-type-ctools-panels-3 for the initial information.

Comments

(Statically copied from previous site)

TracKer replied on February 10, 2014 - 12:41pm

Link in the bottom of the page is broken, but it’s available in web archive: https://web.archive.org/web/20130202115132/http://shellmultimedia.com/articles/creating-content-type-ctools-panels-3