Drupal Page: Can I provide an option in my module?

I have a module that provides multiple pages in a Page Manager module using hook_default_page_manager_pages() . It's good. But now I would also like to suggest an option for the node/%node page . But I can not find the hooks to provide options.

My problem is that I cannot create my own page to overwrite node /% node, as this is already provided by the Page Manager module itself, so I can create pages that occupy a normal node view, should provide an option (from my understanding ) But how can I do this programmatically? I see that it is possible to export the option, and therefore I assume that this could also be provided via the hook?

Is this possible anyway?

+4
source share
2 answers

I found what I was looking for.

To provide options for creating pages using the page manager in code, hook_ctools_plugin_api () is called in your module file so that the page manager knows that he should listen to your module:

 /** * Implement hook_ctools_plugin_api(). * * Tells ctools, page manager and panels, that we have a template ready */ function mtvideo_ctools_plugin_api($module, $api) { // @todo -- this example should explain how to put it in a different file. if ($module == 'panels_mini' && $api == 'panels_default') { return array('version' => 1); } if ($module == 'page_manager' && $api == 'pages_default') { return array('version' => 1); } } 

Now create a new file in the root folder of the MODULE_NAME.pages_default.inc module. In this file you can now enable the following functions:

 hook_default_page_manager_pages() /** * If you want to put an entire page including its variants in code. * With the export module from ctools, you can export your whole page to code. * Paste that into this function. * (Be aware that the export gives you $page, but you need to return an array, * So let the function return array('page name' => $page); */ 

and / or

 hook_default_page_manager_handlers() /** * This will provide a variant of an existing page, eg a variant of the system * page node/%node * Again, use the export function in Page Manager to export the needed code, * and paste that into the body of this function. * The export gives you $handler, but again you want to return an array, so use: * return array('handler name' => $handler); * * Notice, that if you export a complete page, it will include your variants. * So this function is only to provide variants of eg system pages or pages * added by other modules. */ 

I hope this helps another one who needs it once: o) It remains only to find out how my module can programmatically enable the node /% node page in the Page Manager. If anyone has a key, feel free to share it with me :)

+8
source

Sorry if I misunderstood, but I think there are two ways to attack this:

First, you can implement hook_menu_alter() to override the page callback for the path:

 function mymodule_menu_alter(&$items) { $items['node/%node']['page callback'] = 'mymodule_node_page_callback'; } function mymodule_node_page_callback($node) { // Build up the content and return } 

In this case, you need to make sure that in the system table your module has a higher value in the weight column than the Page Manager module (so that your hook will be called later and will have the last word, as it were).

Secondly, you can implement hook_node_view() and just completely override the contents:

 function hook_node_view($node, $view_mode, $langcode) { if ($view_mode == 'full') { $node->content = array(); $node->content['title'] = array('#markup' => '<h1>' . $node->title . '</h1>'; // Build up the rest of the content } } 

In this case, you will need to create the content as a rendering array (see drupal_render() function ).

Hope that helps

0
source

All Articles