Drupal 7 中自定义表单的依赖关系



我在Drupal 7中为单个内容类型提供了几种形式。这样做的目的是在用户提交表单时启动不同的工作流,具体取决于所包含的信息类型,并由每个工作流的/url 定义。这些表单位于不同的页面上,每个表单上显示的字段在自定义模块中定义。例如:

.../form1 启动工作流 1 并显示字段 A、B、E、F、G

.../form2 启动工作流 2 并显示字段 A、B、C、E、H

.../form3 启动工作流 3 并显示字段 A、B、F、X、Y

在此模块中,它看起来像这样:

function my_custom_module_custom_form() {
// Build Form
$form = getForm('content_type');
switch (strtolower($form['#action'])):
case('/form1'):  
$form['field_some_field']['#access'] = FALSE;
switch (strtolower($form['#action'])):
case('/form2'):
$form['field_other_field']['#access'] = FALSE;

我想为每个表单提供一个页面模板,这样我就可以指定每个表单的内容,而不是显示/隐藏模块中每个字段的每个字段,考虑到字段的数量,这很麻烦。

我可以为每个表单创建一个页面模板并链接提交按钮以触发模块中的特定操作吗?

注意:添加依赖项或使用单独的内容类型不适用于我们的用例。如果上面的代码中有错误,只是我在这里给出了一个快速示例,实际模块可以工作。

感谢您的帮助!

我已经为特定的节点形式创建了主题建议:

Change the function name to THEMENAME_preprocess_node
Change initial value of template_filename to 'node'
Account for dashes in aliases by adding this line below the second if statement: $alias = str_replace('-', '_', $alias);

所以这是它现在的样子:

function THEMENAME_preprocess_node(&$variables, $hook) {
// Node template suggestions based off URL alias
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$alias = str_replace('-', '_', $alias);
$template_filename = 'node';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '__' . $path_part;
$variables['theme_hook_suggestions'][] = $template_filename;
}
}
}
}

如果您需要更多详细信息,请告诉我。

最新更新