Drupal 7 Drupal页面管理器:我可以在我的模块中提供一个变体吗?

Drupal 7 Drupal页面管理器:我可以在我的模块中提供一个变体吗?,drupal-7,drupal-ctools,Drupal 7,Drupal Ctools,我有一个模块,它使用hook\u default\u Page\u Manager\u pages()为页面管理器模块提供了许多页面。这很好。 但是现在我还想为系统提供一个变体,包括node/%node页面。但是我找不到任何提供变体的钩子 我的问题是,我不能创建我自己的页面来覆盖node/%node,因为这已经由页面管理器模块本身提供,所以我可以创建接管正常节点视图的页面的唯一方法是提供一个变体(据我所知)。 但我如何以编程方式实现这一点? 我可以看出导出变体是可能的,因此我猜也可以通过钩子提供

我有一个模块,它使用
hook\u default\u Page\u Manager\u pages()
为页面管理器模块提供了许多页面。这很好。 但是现在我还想为系统提供一个变体,包括
node/%node页面
。但是我找不到任何提供变体的钩子

我的问题是,我不能创建我自己的页面来覆盖node/%node,因为这已经由页面管理器模块本身提供,所以我可以创建接管正常节点视图的页面的唯一方法是提供一个变体(据我所知)。 但我如何以编程方式实现这一点? 我可以看出导出变体是可能的,因此我猜也可以通过钩子提供它


这有可能吗?

如果我误解了,我很抱歉,但我认为有两种方法可以解决这个问题:

首先,您可以实现覆盖路径的页面回调:

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
}
在这种情况下,您需要确保在
系统
表中,您的模块在
权重
列中的值高于页面管理器模块(因此您的钩子稍后将被调用,并将拥有最终发言权)

其次,您可以实现并完全覆盖内容:

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
  }
}
function hook\u node\u view($node,$view\u mode,$langcode){
如果($view\u mode=='full'){
$node->content=array();
$node->content['title']=array(“#markup'=>”。$node->title'”;
//构建其余的内容
}
}
在这种情况下,需要将内容构建为渲染数组(请参见)


希望这对我有所帮助,我找到了我要找的东西

要在代码中为页面管理器生成的页面提供变体,请在模块文件中调用hook\u ctools\u plugin\u api(),让页面管理器知道它应该侦听您的模块:

/**
 * 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);
  }
}
现在在模块根文件夹中创建一个名为module_NAME.pages_default.inc的新文件。 在此文件中,您现在可以包括以下功能:

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);
 */
和/或

hook_default_page_manager_handlers()
/**
 * This will provide a variant of an existing page, e.g. 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 e.g. system pages or pages
 * added by other modules.
 */
我希望有一天这能帮助另一个需要帮助的人:o) 我唯一要发现的是,我的模块如何以编程方式在页面管理器中启用node/%node页面。
如果有人有线索,请随时与我分享:)

嗨,克莱夫。这不会在页面管理器中提供页面的变体,这是我的目标。通过在页面管理器中提供页面的变体,我的管理员用户将能够通过页面管理器UI更改页面。您是否发现过在页面管理器中启用node/%node的方法?在我自己的模块中,如果不导入变量,我似乎无法让它正常工作,如果变量要存储在代码中,这似乎会适得其反。我在这里提供了一个补丁,解决了一个悬而未决的问题,这为我解决了问题:嗨,Michael,是的-您可以通过设置变量来启用node/%node,因为它是由变量处理的:variable\u set('page_manager_node_view_disabled',0);(请注意,变量名称已禁用,因此请将值设置为0以启用变量)也可以使用功能导出变量:。功能模块在引擎盖下进行与您在回答中描述的相同的更改。