检查字段是否为空,并在呈现数组中隐藏css类


Check if field is empty and hide a css class in render array

我是drupal核心开发的新手,任何帮助都将不胜感激。当选项卡中的字段内容为空时,我有一个来自内容类型的选项卡组对匿名用户隐藏(默认情况下),当登录编辑器查看相同内容时,如何隐藏此选项卡。

到目前为止,这是我在node.inc中使用template_process_node 所做的工作

function template_preprocess_node__event(&$variables, $hook) 
{
//  kpr($variables);
$node = $variables['node'];
//  kpr($node);
$custom_tab = field_get_items('node', $variables['node'], 'field_route_text');
$custom_tab = (!empty($custom_tab)) ? kpr ('not empty from node') :  kpr('empty from node');
// jQuery UI accordion lib
drupal_add_library('system', 'ui.accordion');
}

我通过下面的代码实现了这一点;

function template_preprocess_node__event(&$variables, $hook) {
$node = $variables['node'];
$custom_tab = field_get_items('node', $variables['node'],    'field_override_group_label')
if (! isset($custom_tab[0]['safe_value'])){
    drupal_add_css(drupal_get_path('theme', 'template some') . "/css/customtab.css");
}
// jQuery UI accordion lib
drupal_add_library('system', 'ui.accordion');

}

在customtab.css文件中,我添加了一个css来隐藏类。我认为这可能会对网站的总体性能产生影响。