简体   繁体   English

内容类型的条件字段drupal 8

[英]Conditional Field drupal 8 for a content type

I am looking to hide/show some fields depending upon user selection on another field. 我想根据用户在另一个字段上的选择来隐藏/显示某些字段。 So a user can select among four wheeler/two wheeler. 因此,用户可以在四轮车/两轮车中选择。 If user selects four wheeler from a dropdown he is shown different set of fields and for two wheeler different set of fields . 如果用户从下拉列表中选择四轮车,则会显示不同的字段集,而对于两轮车则显示不同的字段集。 As there are many common fields I am looking to use same content type for both content type 由于存在许多常见的字段,因此我希望对两种内容类型使用相同的内容类型

What I have tried so far is 到目前为止,我尝试过的是

  1. Theme_name_form_alter hook in theme_name.theme file theme_name.theme文件中的theme_name_form_alter钩子
  2. As well as hook_form_FORM_ID_alter 以及hook_form_FORM_ID_alter

None seems to be working for me 似乎没有人为我工作

Module conditional fields is still dev for Drupal 8 but should work: 模块条件字段仍然是Drupal 8的开发人员,但应该可以使用:

https://www.drupal.org/project/conditional_fields https://www.drupal.org/project/conditional_fields

while Conditional Field module still is in development on Drupal 8 So Field Formatter Condition Module could be a good choice. 虽然条件字段模块仍在Drupal 8上开发,所以字段格式化程序条件模块可能是一个不错的选择。

Simple conditions and actions 简单的条件和动作

Hide source field when target field is empty. 当目标字段为空时隐藏源字段。 Hide source field when target field is not empty. 当目标字段不为空时隐藏源字段。 Hide source field when the current user has specific roles. 当前用户具有特定角色时,隐藏源字段。 Hide source field on specific pages. 隐藏特定页面上的源字段。 Hide source field when target field contains a specific string. 当目标字段包含特定字符串时,隐藏源字段。 Hide source field when target field doesn't contain a specific string. 当目标字段不包含特定字符串时,隐藏源字段。 Hide link field if title is empty. 如果标题为空,则隐藏链接字段。 Hide date field if smaller/greater then today/custom date. 如果小于/大于今天/自定义日期,则隐藏日期字段。 Hide if content from author Hide if checkbox is checked (in current dev version) 如果作者的内容隐藏,则隐藏如果选中此复选框,则隐藏(在当前开发版本中)

And in case "Conditional fields" is not working for you maybe "Paragraphs" can jump in as replacement. 如果“条件字段”对您不起作用,则“段落”可以作为替换项加入。 It's stable at least. 至少是稳定的。

https://www.drupal.org/project/paragraphs https://www.drupal.org/project/paragraphs

Not exactly what you were asking for, but can do the job. 不完全是您的要求,但是可以完成任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM