[英]Drupal 8: How do I create a content reference/textarea compound field?
I have a company content type being used on a website-in-progress. 我在进行中的网站上使用的公司内容类型。 Companies consist of a company name, name sorting mechanism, logo image and URL. 公司由公司名称,名称排序机制,徽标图像和URL组成。 I have a requirement to show companies taking part in different use cases in various parts of the website. 我有必要向公司展示网站各个部分中使用情况不同的公司。
Challenge: 挑战:
In the past I used a company content type for a "corporate members" list on a page, also assigning a "member level" field. 过去,我在页面上的“公司成员”列表中使用公司内容类型,还分配了“成员级别”字段。 But then, companies started being listed as event sponsors with specifics for what they were sponsoring, also with different membership levels in a "corporate giving club". 但是随后,公司开始被列为活动赞助商,其中包含其赞助商的详细信息,并且在“企业捐赠俱乐部”中具有不同的会员级别。 It was messy while added/included in the old company content type. 在旧公司内容类型中添加/包含时,情况比较混乱。 It caused confusion for content editors and developers. 这引起了内容编辑人员和开发人员的困惑。
Possible Solution: 可能的解决方案:
In other content types, create compound fields such as "Sponsors", "Corporate members", "Donors", select lists with company entities, or sponsorship detail text areas with company entities. 在其他内容类型中,创建复合字段,例如“赞助者”,“公司成员”,“捐助者”,选择带有公司实体的列表,或带有公司实体的赞助细节文本区域。 That may keep companies flexible and not messy (keeping company just a company). 这可以使公司保持灵活而不凌乱(使公司仅仅是一家公司)。
Progress: 进展:
I found the Double field module, splitting core fields up into two separate parts. 我找到了Double field模块,将核心字段分为两个单独的部分。 This is almost what I'm looking for, providing compound field sets. 提供复合字段集几乎就是我想要的。 However, it won't allow references to be selected and is out of the scope of this project per this issue . 但是,它不允许选择引用,并且在本期中超出了该项目的范围。 I'm finding a lot of Drupal 7 examples, but not much Drupal 8 yet. 我发现了很多Drupal 7示例,但还没有很多。
I'm starting to dig into the examples for developers module for inspiration and will post a solution unless you beat me to it. 我将开始研究开发人员模块的示例以获取启发,并将发布解决方案,除非您击败了我。 I'm also open to alternative ideas. 我也欢迎其他想法。
What is the best way to proceed? 最好的进行方法是什么? Specific code examples are not required. 不需要特定的代码示例。 I would accept clues that lead me to a final working solution. 我会接受一些线索,这些线索使我找到了最终可行的解决方案。
The solution turned out to be simpler than creating a custom module. 事实证明,该解决方案比创建自定义模块更简单。
The Field Collection module allowed for the simple creation of compound fields containing any number and most (if not all) field types, including reference fields. 字段收集模块允许简单地创建包含任意数量和大多数(如果不是全部)字段类型(包括参考字段)的复合字段。 It's also available as a Drupal 8 module (alpha at the time of writing, seems to work fine). 它也可以作为Drupal 8模块使用(在撰写本文时为alpha,看起来工作正常)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.