Basically, I want to port a custom ctools plugin created for content type from Drupal 7 to Drupal 8. This is the code I want to port.

function my_module_ctools_plugin_directory($module, $plugin) {
  if (($module == 'ctools') && ($plugin == 'content_types')) {
    return 'plugins/content_types';

In my_module/plugins/content_types/my_module.inc file i have following code:

 * Plugin array() of ctools plugin.
$plugin = array(
  'title' => t('My Module'),
  'single' => TRUE,
  'content_types' => array('my_module_custom_content_type'),
  'render callback' => 'my_module_render',
  'required context' => new ctools_context_required(t('Node'), 'node'),
  'edit form' => 'my_module_settings_form',
  'edit form validation' => 'my_module_settings_form_submit',
  'category' => 'Widgets',

 * Render callback function.
function my_module_render($subtype, $conf, $args, $context) {
  $node = $context->data;
  if (empty($node)) {
  $data = \Drupal::formBuilder()->getForm('my_module_form', $context, $conf);
  $block = new stdClass();
  $block->content = $data;
  $block->title = '';
  $block->id = 'my_module_form';
  return $block;

How do I port the plugin to Drupal 8?


There are no ctools plugins anymore in Drupal 8. There's just the Drupal 8 plugin API.

Page Manager, Panels and so on use standard block plugins now in 8.x, so you basically have to port this to a block an then it should work fine.

Also, the "code" you posted only defines that you have such a plugin in your module, nothing else. If you need more specific support, you will need to post your actual code, and ask specific questions (which are probably better as a follow-up question).

  • I have updated the code. Can you elaborate how to do it now. I know how to create block plugin in D8, but not sure of this scenario. – neha Jan 15 '17 at 12:37
  • 1
    What exactly is "this scenario", that's still only the plugin definition. I can see it uses contexts, those are supported for Blocks too, see \Drupal\block_test\Plugin\Block\TestContextAwareBlock for an example that uses entity:user, yours would be entity:node. Otherwise that looks like standard block functionality to me, but I don't really know the 7.x API. If that's not it, then as written, create a new, specific question and make sure all relevant code is there – Berdir Jan 15 '17 at 13:38
  • I have also update render_callback function. I guess plugins are replaced by blocks in D8 and those blocks can be added in panels. I thinks i have understood the working. Let me correct if i am wrong. – neha Jan 15 '17 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.