Drupal 预处理一个商务功能 [英] Drupal preprocess a commerce function
问题描述
我需要从模块商业定价属性"中预处理一个函数.
I need to preprocess a function from the module "commerce pricing attributes".
这里是函数:
function commerce_pricing_attributes_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {...}
我不知道如何预处理这个(如果可能的话).
I don't know how to preprocess this (if it's possible).
这个函数在后台创建一些元素,我想做的是根据元素的选项类型为这些元素赋予颜色.如果是保险选项,则有一种颜色,如果是房间选项,则另一种颜色.
This function create some element in the back-office and the thing I want to do is to give a color to these elements in function of the type of the option the element is. If it's an insurance option there is a color, if it's a room option another color.
我尝试用这样的改变来做到这一点:function my_module_field_widget_commerce_pricing_attributes_custom_widget_form_alter(&$element, &$form_state, $context) {...}
I try to do this with an alter like this :
function my_module_field_widget_commerce_pricing_attributes_custom_widget_form_alter(&$element, &$form_state, $context) {...}
但我无法获得所需的所有信息(选项的类型).
But I can't have all the information I need (the type of the option).
有什么方法可以预处理函数,以便我可以使用他们在模块中使用的所有值?
Is there any way to preprocess the function so I can use all the values they use in their module ?
推荐答案
我觉得你需要使用这个钩子:hook_field_widget_form_alter
I think you need to use this hook : hook_field_widget_form_alter
它允许您覆盖(或添加)应用于字段的小部件
It allow you to override (or add) widget applied to a field
function my_module_field_widget_form_alter(&$element, &$form_state, $context) {
if ($context['field']['type'] == 'mytype') { // you can use another condition on field name or whatever
// Loop through the element children (there will always be at least one).
foreach (element_children($element) as $key => $child) {
// Add the new process function to the element
$element[$key]['#process'][] = 'my_custom_callback_field_widget_process';
}
}
}
function my_custom_callback_field_widget_process($element, &$form_state, $form){
// do your stuff
return $element;
}
NB : 如果你不知道它们的结构,将变量转储到你想要的目标
NB : dump variables to target exactly you want if you don't know structre of them
这篇关于Drupal 预处理一个商务功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!