通过表单 API 主题化 Drupal 添加块表单

发布于 2024-08-31 09:00:33 字数 468 浏览 6 评论 0原文

谁能建议我定制“添加块”表单? (/admin/build/block/add)

我想对用户隐藏“用户特定的可见性设置”和“角色特定的可见性设置”。这是我到目前为止所得到的,但显然这是不正确的,我无法弄清楚数组是什么。有人有这方面的经验吗?

function theme_add_block_form($form) {
    $form['roles']['#prefix'] = '<div class="hidden">';
    $form['roles']['#suffix'] = '</div>';
    return drupal_render($form);
}

谢谢, H

编辑 - 也许我不清楚 - 我很舒服地使用 API 中的各种表单挂钩,但在这种情况下我的问题是我无法识别要在我的函数中使用的数组元素。开发模块似乎没有在块页面上起作用,并且主题弹出块的事情也不太清楚。

Can anyone advise me on customising the Add Block form? (/admin/build/block/add)

I want to hide the "User specific visibility settings" and "Role specific visibility settings" from users. This is what i've got so far, but obviously it's not right and I can't figure out what the array is. Anyone got the experience on this?

function theme_add_block_form($form) {
    $form['roles']['#prefix'] = '<div class="hidden">';
    $form['roles']['#suffix'] = '</div>';
    return drupal_render($form);
}

Thanks,
H

EDIT - perhaps I wasn't clear - I'm comforable using the various form hooks from the API, but my problem in this case is that I can't identify the array elements to use in my function. The devel module doesn't seem to act on the blocks page, and the themer popup block thing is less than clear.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

度的依靠╰つ 2024-09-07 09:00:33

modules/block/block.admin.inc 中,函数 block_admin_configure

$form['user_vis_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('User specific visibility settings'),
    '#collapsible' => TRUE,
  );

(...)

$form['role_vis_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Role specific visibility settings'),
    '#collapsible' => TRUE,
  );

尝试隐藏 $form['user_vis_settings']$form['role_vis_settings']

编辑:

不要碰modules/block/block.admin.inc! (我只是指出我找到表单字段名称的位置)。隐藏 theme_add_block_form 中的字段。您可以编写 $form['user_vis_settings']['#access'] = false; ,而不是将字段包装在 div 内

In modules/block/block.admin.inc, function block_admin_configure:

$form['user_vis_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('User specific visibility settings'),
    '#collapsible' => TRUE,
  );

(...)

$form['role_vis_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Role specific visibility settings'),
    '#collapsible' => TRUE,
  );

Just try to hide $form['user_vis_settings'] and $form['role_vis_settings'].

EDIT:

Don't touch modules/block/block.admin.inc!! (I only was pointing where I found the form fields' names ). Hide the fields in your theme_add_block_form. Instead of wrapping the fields inside a div, you can write $form['user_vis_settings']['#access'] = false;

誰ツ都不明白 2024-09-07 09:00:33

这是要走的路。使用 http://api.drupal.org/api/function/hook_form_alter/6< /a> 正如另一个答案中所说。您需要在 Costum 模块中编写此代码。

<?php   
 function module_name_form_alter(&$form, $form_state, $form_id) {
      if ($form_id == 'block_admin_configure') {
       $form['user_vis_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('User specific visibility settings'),
        '#collapsible' => TRUE,
        '#access' = FALSE,
       );
       $form['role_vis_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Role specific visibility settings'),
        '#collapsible' => TRUE,
        '#access' = FALSE,
       );
      }
    }

This is the way to go. Using the http://api.drupal.org/api/function/hook_form_alter/6 as say in an other answer. You need to write this code in a costum module.

<?php   
 function module_name_form_alter(&$form, $form_state, $form_id) {
      if ($form_id == 'block_admin_configure') {
       $form['user_vis_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('User specific visibility settings'),
        '#collapsible' => TRUE,
        '#access' = FALSE,
       );
       $form['role_vis_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Role specific visibility settings'),
        '#collapsible' => TRUE,
        '#access' = FALSE,
       );
      }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文