Skip to content

Custom field with display

Colby Chiste requested to merge custom_field_with_display into master

Purpose

This exercise has us creating a custom field type and accompanying display option for use with existing product entities. As fields are an important part of Drupal it is important that we gain a strong understanding of their inner workings and how to utilize them.

Approach

  1. Define a custom field type (ingredients) using annotations
  2. Add an instance of the new field type to a product entity (recipe)
  3. Create a display setting that accepts a textfield option
  4. Render a list of ingredients on the product page using the new field type and display setting, wrapping the value of the field in a div with a class of the value set in the textfield option.

How to

As a content manager or administrator add the Ingredients List field to an existing content type. Change the settings under the edit content type page so our new field uses the new bullet-form display setting. Author a new piece of content by entering a comma-separated list of ingredients into the field and publish it. Navigate to the new node and see your comma-separated list displayed in bullet list form.

Review Checklist

  • Sufficient documentation (can others figure out what's going on without context?
  • Sufficient test coverage.
  • All pipelines pass.
  • Added applicable files to code standards and automated test pipelines.
  • No merge conflicts present.
  • Merge request follows deployment requirements.
Edited by Colby Chiste

Merge request reports