Articles


How to Create a Custom Content Type Pane

How to Create a Custom Content Type Pane



Posted byJibin Jose,12th Aug 2015

How to Create a Custom Panels Pane to list a drupal block. For creating the custom pane and using inside the panel, We need to download and enable ctools and panel modules. For downloading and enabling the module we can use drush command or download and paste inside the modules folder also

For creating the custom pane we need to add a custom module for the same. Also enable the custom module. We can add whatever dependencies we required inside the info file itself. It will enable the required module along with the custom module

name =  custom_pane

description = Custom content type pane

core = 7.x

package = Custom

dependencies[] = ctools

dependencies[] = panels

For keeping the files organised create a directory inside our module folder called 'plugins'. Inside the plugin folder create a directory called 'contentypes'. This folder will contain our plugin files (the files where the actual plugin functionality is defined).

Ctools, like Views, needs a hook to declare the fact that you have custom code. To do this we’ll use hook_ctools_plugin_directory. This hook is invoked for all Ctools plugin types, and includes the module name as a variable. This way you can avoid eating up memory for anything except the targeted module. You also have to declare where your custom code will live. Add the below code inside the custom module:


/**
 *
 */
Implements hook_ctools_plugin_directory().

function user_last_login_ctools_plugin_directory($owner, $plugin_type) {
  $modules = array('panels', 'ctools');
  if (in_array($owner, $modules) && !empty($plugin_type) && ($plugin_type == 'content_types' || $plugin_type == 'access' || $plugin_type == 'layouts')) {
    return 'plugins/' . $plugin_type;
  }
}

Create a file inside the plugin contet type folder custom_pane_plugin.inc


/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
  $plugin = array(
    'single' = TRUE,
    'title' => t('User last login Pane'),
    'description' => t('The last login time of the loggedin user.'),
    'category' => 'Custom Panes', // A category to put this under.
    'edit form' => 'user_last_login_pane_edit_form',
    'render callback' => 'user_last_login_block_pane_render',
    'admin info' => 'user_last_login_admin_info',
    'defaults' => array( // Array of defaults for the settings form.
      'text' => '',
    ),
    'all contexts' => TRUE
  );


/**
 * 'admin info' callback for panel pane.
 */
function user_last_login_admin_info($subtype, $conf, $contexts) {
  if (!empty($conf)) {
    $block = new stdClass;
    $block->title = $conf['override_title'] ? $conf['override_title_text'] : '';
    return $block;
  }
}

/**
 * Form constructor for the custom pane edit form.
 */
function user_last_login_pane_edit_form($form, &$form_state) {
  // provide a blank form so we have a place to have context setting.
  return $form;
}

/**
 * Run-time rendering of the body of the block (content type)
 *
 * @see ctools_plugin_examples for more advanced info
 */
function user_last_login_block_pane_render($subtype, $conf, $panel_args, $context) {

  $block = new stdClass();
  $block->module = 'user_last_login';
  $block->title = _custom_block_info_subject();
  $block->content = _custom_block_info_content();
  $block->delta = 'custom_block_info_pane';

  return $block;
}

We can easily create a custom pane with the above steps.

Related Articles