在 Drupal 中主题收音机的正确方法?
我尝试在 Drupal 模块中对无线电进行主题化,并覆盖主题函数中的以下代码。为了进行实验,我没有更改以下函数中的任何内容,只是使用不同的名称迁移到我的模块中,这不会与原始 api 函数冲突。
function theme_radios($element) {
$class = 'form-radios';
if (isset($element['#attributes']['class'])) {
$class .= ' ' . $element['#attributes']['class'];
}
$element['#children'] = '<div class="' . $class . '">' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
if ($element['#title'] || $element['#description']) {
unset($element['#id']);
return theme('form_element', $element, $element['#children']);
}
else {
return $element['#children'];
}
}
主题注册一切顺利。不幸的是,我没有得到任何结果。我只能看到表单标签(Radios 的标签)。有什么想法吗?
编辑:我设法解决了它。谢谢大家!
I tried theming of radios in Drupal module overriding the following code in my theme function. For experimental I did not change anything in the below function and just migrated into my module with different name that would not conflict with original api function.
function theme_radios($element) {
$class = 'form-radios';
if (isset($element['#attributes']['class'])) {
$class .= ' ' . $element['#attributes']['class'];
}
$element['#children'] = '<div class="' . $class . '">' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
if ($element['#title'] || $element['#description']) {
unset($element['#id']);
return theme('form_element', $element, $element['#children']);
}
else {
return $element['#children'];
}
}
Theme registration and all fine. Unfortunately, I am getting nothing as result. Only the form label (Radios's Label) I can see. Any idea please?
EDIT: I managed to solve it. Thanks everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 Drupal 7,您必须深入挖掘才能解决此问题。
首先在 template.php 中创建
MY_THEME_form_element()
,复制theme_form_element()
中的所有代码 - 您可以从 api.drupal.org。在switch($element['#element_display')
语句之前添加一个条件来检查该元素是否为单选按钮。然后创建一个新函数来以不同方式处理单选按钮的渲染。从上面我们将单选按钮的渲染传递给函数
form_element_label()
,因此创建MY_THEME_form_element_label()
和form_element_label()
的内容> 进入其中。编辑这个新函数,用以下内容替换 return 语句:这将为您提供一个放置在其标签内而不是其下方或上方的单选按钮。
最后,您可以连接到 theme_radios 来为单选按钮列表的呈现方式添加其他格式。
这个答案可以在此链接找到。它描述了使用复选框的解决方案。
注意 您还可以将其应用于任何元素的格式设置。
For Drupal 7 you'd have to dig a little deeper to fix this.
Start by creating
MY_THEME_form_element()
in your template.php, copy all the codes intheme_form_element()
- you can get that from api.drupal.org. Add a condition to check if the element is a radio button before theswitch($element['#element_display')
statement. Then create a new function to handle rendering the radio button differently.From the above we are passing the rendering of the radio button unto the function
form_element_label()
so createMY_THEME_form_element_label()
and the contents ofform_element_label()
into it. Edit this new function, replacing the return statement with this:This would give you a radio button placed within it's label rather than below or above it.
And finally, you can hook into theme_radios to add additional formatting to the way the list of radio buttons are rendered.
This answer was found at this link. It describes a solution using a checkbox.
NB You can also apply this in formatting any element.
问题解决了。我已经发布了一篇关于如何做到这一点的博客文章。任何需要类似问题帮助的人都可以参考该链接。
http://www.encodez.com/blog/how -to-theme-radio-drupal-1.html
注意:此解决方案适用于 Drupal 6。
The question is solved. I have posted a blog post on how to do it. Any one need help on similar issue can refer to the link.
http://www.encodez.com/blog/how-to-theme-radio-drupal-1.html
NB: This solution is for Drupal 6.