- Drupal 8 Blueprints
- Alex Burrows
- 478字
- 2021-07-03 00:03:25
Adding our fields
For our Post to show content, we need to add some fields so that the user can input content. For this, we will have three fields:
- Post content: This will be Text (formatted long, with summary)
- Post comment: This will be a comment field that utilizes the comment core module
- Post category: This will be a taxonomy term reference, which will look up our terms inside our taxonomy
Let's add our first field, Post content.
To do this, we click on + Add field; we are then redirected to a page that allows us to configure the field and its type. We are shown Add a new field and Re-use an existing field. We want to add a new field entirely, so from the drop-down list, let's select Text (formatted long, with summary). As you'll see, when we select this, we are greeted with a new field, Label. This field is the name of our field, so we shall use Post content as our label. When we enter this into the textfield, we see Machine name: field_post_content to the right:

In Fig 1.5, we can see the field settings all filled in; we are now ready to proceed to the second part of the field configuration:

The Field API allows us to set as many for a field as we like. If we were to set unlimited, an Add another action button appears, and then another field is loaded.
After doing this, when we click on Save field settings, we will be taken to another settings page; depending on the type of field, there may be multiple fields for configuration on this field:

In Fig 1.7, we can see the following fields:
- Label: This appears above the field and will show on the display by default.
- Help text: This allows a description to appear beneath the field, and it is used as instructions to the user on what the field requires.
- Required field: This allows us to make the field required and use the standard Drupal validation for this type of field; however, we can amend this later, if needed, just by editing the field settings from the Manage fields page.
- Default value: This will show the same value that can be overridden by the user.
- Summary input: This allows authors to show a specific summary of text instead of the basic trim function.
As we have created our content field for our post, we now need to add a category selection to this content type. So now, it's time to add our taxonomy; firstly, we need to create a taxonomy vocabulary, and then we can associate our terms to this vocabulary. For this site, we will call our vocabulary "Post category".
- Unity 2020 By Example
- Web程序設(shè)計(jì)及應(yīng)用
- Reporting with Visual Studio and Crystal Reports
- C++程序設(shè)計(jì)(第3版)
- ASP.NET MVC4框架揭秘
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程
- ASP.NET Core 5.0開發(fā)入門與實(shí)戰(zhàn)
- NLTK基礎(chǔ)教程:用NLTK和Python庫構(gòu)建機(jī)器學(xué)習(xí)應(yīng)用
- 小學(xué)生C++創(chuàng)意編程(視頻教學(xué)版)
- 精通Linux(第2版)
- MySQL從入門到精通(軟件開發(fā)視頻大講堂)
- 現(xiàn)代C++編程實(shí)戰(zhàn):132個(gè)核心技巧示例(原書第2版)
- PHP編程基礎(chǔ)與實(shí)踐教程
- 運(yùn)維前線:一線運(yùn)維專家的運(yùn)維方法、技巧與實(shí)踐
- Hands-On Kubernetes on Windows