这段代码有什么作用?
if (in_array($form['#submit'], 'search_box_form_submit')) {
$key = array_search('search_box_form_submit', $form['#submit']);
unset($form['#submit'][$key]);
}
array_unshift($form['#submit'], 'mymodule_search_box_submit');
代码有什么作用?我不太能理解它;我希望有人可以逐行向我解释。
if (in_array($form['#submit'], 'search_box_form_submit')) {
$key = array_search('search_box_form_submit', $form['#submit']);
unset($form['#submit'][$key]);
}
array_unshift($form['#submit'], 'mymodule_search_box_submit');
What does the code do? I don't follow it well; I expect someone can explain it to me, line by line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果提交的表单包含名为“search_box_form_submit”的变量,请将其删除,然后添加名为“mymodule_search_box_submit”的新变量。
也许有人想要覆盖 drupal 搜索功能,并且根本不希望默认处理器启动。感谢评论中的 kiamlaluno。
If the submitted form contains a variable named "search_box_form_submit", delete it, and then add a new variable called "mymodule_search_box_submit".
Perhaps somebody wanted to override the drupal search function and didn't want the default processor to fire at all. Thanks kiamlaluno in the comments.
if (in_array($form['#submit'], 'search_box_form_submit')) {
如果数组
$form[ 中存在值
'search_box_form_submit'
'#submit']$key = array_search('search_box_form_submit', $form['#submit']);
然后设置变量
$key
为数组$form['#submit']
中值'search_box_form_submit'
的数组键unset($ form['#submit'][$key]);
然后取消设置(删除)该数组元素
array_unshift($form['#submit'], 'mymodule_search_box_submit');
在数组
$form['#submit']
的开头放置一个新元素,其值为'mymodule_search_box_submit'
if (in_array($form['#submit'], 'search_box_form_submit')) {
If the value
'search_box_form_submit'
is present in the array$form['#submit']
$key = array_search('search_box_form_submit', $form['#submit']);
Then set the variable
$key
to the array key for the value'search_box_form_submit'
in the array$form['#submit']
unset($form['#submit'][$key]);
Then unset (delete) that array element
array_unshift($form['#submit'], 'mymodule_search_box_submit');
Put a new element at the beginning of the array
$form['#submit']
with the value'mymodule_search_box_submit'
是数组 $form['#submit'] 中的文本“search_box_form_submit”
如果是这样,找到 search_box_form_submit 的键
然后从数组中删除
将值 mymodule_search_box_submit 放在数组的前面 $form['#submit']
我建议阅读所使用函数的手册页。
is the text "search_box_form_submit" in the array $form['#submit']
if so find the key for search_box_form_submit
then remove from array
put the value mymodule_search_box_submit in the front of the array $form['#submit']
i recommend reading the manual page for the functions used.