arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Exercise 2.6: Add a custom text field

For our Government Jobs Portal website, we want to let site visitors filter job offers by full time/part time. In this exercise, we’ll add this value in.

hashtag
Add a field

Let’s start by adding our first field – Terms of employment

  1. Go to Structure → Content types → Job posting → Manage fields (if you have moved away from this page).

  2. Click + Add field.

  3. Under Text, select List (text).

    • Enter “Terms of employment” for Label.

    • For the Machine name, click edit and enter the machine name: jobterms.

  4. Click Save and continue and you’ll go back to the Field settings page for the Terms of employment field.

Review the Field naming conventions section below, before moving to the Field settings.

hashtag
Field naming conventions

When adding a new field, GovCMS automatically suggests a field name. You can edit the field name when you’re adding it but cannot change it later on. When naming the field you should think carefully about a logical name, especially if you’ll be using the field in other content types.

The field name can only contain lowercase letters, numbers 0-9, and the underscore character. It’s a good idea to set up a naming convention early on.

hashtag
Configure field settings

Next we’ll set up the values (items) for our dropdown list.

  1. Add the following options to the Allowed Values list text area:

    • 1|Permanent

    • 2|Temporary

hashtag
Configure default settings

Now you’ll see the Edit tab, with the field’s default settings. Follow these settings:

  • Select Required Field.

  • Help text: “Please select terms of employment” (to be displayed when creating or editing Job Posting content).

  • Default value for Terms of employment: leave this as - None -.

hashtag
Manage Form display

The Manage Form display tab allows you to control fields that will be available in the content creation form, along with widgets. This page is used to make adjustments to the widgets used in content types.

Navigate to the Manage Form display page and review the available fields. Locate the “Terms of employment” field you created and review what widget selection is available.

hashtag
Review your content type

Once you’ve saved your last field, you’ll be taken back to the Job Posting Manage fields page. All the fields you add to your content type will be visible here.

Finally, you should test the content type by adding content to it.

Go to Content → Add content and choose the Job posting option. Check the form and create a test job posting for a full-time job as a Drupal developer. Save the new job posting and note the URL path for the new content.

circle-info

To view the field you’ve created, go to Reports → Field list.

Click Save and continue.

3|Part-time

  • 4|Full-time

  • Note You must include the numbers before each entry because they provide a numerical key for each option, which means you can change the names of the items without losing content.

  • Select “Limited” and “1” in the Allowed number of values dropdown and scrollwheel.

  • Click Save field settings.

  • Click Save settings. You’ll then be returned to the Manage fields page.

    Image of auto suggested field name
    Image of Manage Form display
    Image of Manage Form display
    Image of add Field
    Image of add Field
    Image of allowed values list