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.
我尝试使用这样的修改来做到这一点:$ b $ b 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:如果您不知道structre,则转储变量以精确定位您想要的目标
NB : dump variables to target exactly you want if you don't know structre of them
这篇关于Drupal预处理商务功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!