4

我创建了一个内容类型,它有大约 5 个组,它们都是垂直选项卡。

由于某种原因,字段组标签不适用于垂直选项卡。<h2>标签总是:<h2 class="element-invisible">Vertical Tabs</h2>. 标题始终Vertical Tabs与设置的内容无关,manage fields并且始终具有类element-invisible

我注意到在某些使用垂直标签的主题中完全相同。

我还注意到这些主题在每个垂直选项卡上方都有一个额外的标题标签,用于显示该组的标题。( adaptivetheme ) 就是一个很好的例子。

无论如何,对于实际问题....

如何为我的内容类型中的每个分组部分(垂直选项卡)添加标题?

注意:这是用于添加内容的实际表单,而不是创建的内容的显示。

对此的任何帮助都非常感谢。

4

3 回答 3

1

您可以在主题的 template.php 或自定义模块中自定义内容类型表单。这 在此处记录。例如,如果您的主题 MYMODULE 中有一个使用自定义内容类型文章的自定义模块,那么您可以像这样自定义:

<?php
/**
* Implements hook_theme().
*/
function MYMODULE_theme($existing, $type, $theme, $path) {
  return array(
    'article_node_form' => array(
      'render element' => 'form',
      'template' => 'article-node-form',
      // this will set to module/theme path by default:
      'path' => drupal_get_path('module', 'MYMODULE'),
    ),
  );
}
?>

输出自定义数据:

<?php
/**
* Preprocessor for theme('article_node_form').
*/
function template_preprocess_article_node_form(&$variables) {
  // nodeformcols is an alternative for this solution.
  if (!module_exists('nodeformcols')) {
    $variables['sidebar'] = array();   // Put taxonomy fields in sidebar.
    $variables['sidebar'][] = $variables['form']['field_tags'];
    hide($variables['form']['field_tags']);
    // Extract the form buttons, and put them in independent variable.
    $variables['buttons'] = $variables['form']['actions'];
    hide($variables['form']['actions']);
  }
}
?>
于 2014-03-18T17:16:42.850 回答
1

使用Drupal 7 内容主题为您的内容类型添加标题。例如,如果您的内容类型被命名为mycontent,那么在您的主题文件夹中创建以下脚本:

{theme path}/page--node--mycontent.tpl.php

要预处理内容类型,请使用以下函数:

function mycontent_preprocess_page(&$vars) {
    if (isset($vars['node']->type)) { 
        $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
    }
}

有关 template_preprocess_page 函数的更多信息,请参见此处

于 2014-03-17T17:37:10.170 回答
1

The other answers to this question were on the right track. The code responsible for the vertical tab heading is the theme_vertical_tabs function in the includes/form.inc file.

If you have your own theme, you can copy and alter this function in your theme's template.php file to override it:

function YOUR_THEME_NAME_vertical_tabs($variables) {
  $element = $variables['element'];

  // Add required JavaScript and Stylesheet.
  drupal_add_library('system', 'drupal.vertical-tabs');

  // Following line changed to use title set in field settings and remove class="element-invisible
  $output = '<h2>' . t($element['#title']) . '</h2>';  
  $output .= '<div class="vertical-tabs-panes">' . $element['#children'] . '</div>';

  return $output;
}

If you are looking to make the vertical tab heading appear in the content editing screens and you have an admin theme set, then the above modifications need to be done to the admin theme.

于 2014-05-01T17:39:44.450 回答