跳转到主要内容
kee 提交于 16 December 2013

View teaser显示中希望去掉一些字段的外围html包裹

查到可以通过重写themename_filed(),这个函数放到template.php里不生效,有什么条件吗?

标签
Drupal 版本

昨天我在调内容类型字段显示方式时(由于长文本不能换行显示,显示格式切换了下)发现bootstrap_field()生效了,后来删掉测试代码,空闲时再去写bootstrap_field()发现无效了,clear all cache也没用。

我只简单的return,也不生效(昨天下午不知什么原因生效了,subtheme里测试bootstrap_sub_field()也生效了)

function bootstrap_field ($variable) {
	return '2323';
}

前提是这个方法已在bootstrap主题里生效了,我想拿到sub theme里方便主题更新

另外,我在bootstrap里加入表单重写,清除缓存不生效:


function bootstrap_customize_comment_form(&$form) {
	$form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE;
	$form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
	//$form[LANGUAGE_NONE][0]['format']['#attributes'] = array('style' => 'display: none;');
	return $form;
}

function bootstrap_field($variables) {
	$output = '';

	// Render the label, if it's not hidden.
	if (!$variables['label_hidden']) {
		$output .= '<div class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . ':&nbsp;</div>';
	}
	if (in_array($variables['element']['#field_name'], array('field_example1', 'field_example2', 'field_example3', 'field_example4'))) {
		// For tags, concatenate into a single, comma-delimitated string.
		foreach ($variables['items'] as $delta => $item) {
			$rendered_tags[] = drupal_render($item);
		}
		$output .= '<span>'.implode(', ', $rendered_tags).'</span>';
		// Render the top-level DIV.
		$output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';
	}
	else {
		$output .= '<div class="field-items"' . $variables['content_attributes'] . '>';
		// Default rendering taken from theme_field().
		foreach ($variables['items'] as $delta => $item) {
			$classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even');
			$output .= '<div class="' . $classes . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</div>';
		}
		$output .= '</div>';
		// Render the top-level DIV.
		$output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';
	}

	// Render the top-level DIV.
	return $output;
}

function bootstrap_form_comment_form_alter(&$form, &$form_state, &$form_id) {
	$form['comment_body']['#after_build'][] = 'bootstrap_customize_comment_form';
}

function bootstrap_customize_comment_form(&$form) {   
  	$form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE;
  	$form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
  	$form[LANGUAGE_NONE][0]['format']['#attributes'] = array('style' => 'display: none;');
  	return $form;
}

现在的疑惑是放到子主题中不生效?字主题文件夹名字是bootstrap_sub