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)) {
return;
}
$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?