[[structure-fields]]

=== Adding Basic Fields to a Content Type

[role="summary"]
How to add fields to a content type.

(((Content type,adding field to)))
(((Field,adding to content type)))
(((Image field,adding)))
(((URL field,adding)))

==== Goal

Add a link field and an image field to the Vendor content type.

==== Prerequisite knowledge

<<planning-data-types>>

==== Site prerequisites

The Vendor content type must exist. See <<structure-content-type>>.

==== Steps

Add the fields Vendor URL and Main image to the Vendor content type.

. In the _Manage_ administrative menu, navigate to _Structure_ > _Content
types_ (_admin/structure/types_). Then click _Manage fields_ in the dropdown
button for the Vendor content type. The _Manage fields_ page appears.

. Click _Add field_. The _Add field_ page appears. You can either create a new
field for the content type or re-use an existing field.

. Fill in the fields as shown below.
+
[width="100%",frame="topbot",options="header"]
|================================
| Field name | Explanation | Value
| Add a new field | Field type| Link
| Label | Label that is visible in administration pages | Vendor URL
|================================
+
A machine name is automatically generated, based on the _Label_ value. Click
_Edit_ if you want to override the default name.
+
--
// Initial page for admin/structure/types/manage/vendor/fields/add-field.
image:images/structure-fields-add-field.png["Add field page"]
--

. Click _Save and continue_. The page Vendor URL appears which lets you set
the allowed number of values. Fill in the fields as shown below.
+
[width="100%",frame="topbot",options="header"]
|================================
| Field name | Explanation | Value
| Allowed number of values | The number of values that can be entered | Limited, 1
|================================


. Click _Save field settings_. The page _Vendor URL settings for Vendor_
appears which allows you to configure the field. Fill in the fields as shown
below.
+
[width="100%",frame="topbot",options="header"]
|================================
|Field name | Explanation | Value
| Label  | Label that is visible in the content form | Vendor URL
| Help text | The instruction that is shown below the field | (leave blank)
| Required field | Whether the field is required or not | Unchecked
| Allowed link type | The kind of links that can be entered | External links only
| Allow link text | Whether a link text can be entered | Disabled
|================================
+
--
// Field settings page for adding vendor URL field.
image:images/structure-fields-vendor-url.png["Field settings page for Vendor URL",width="100%"]
--

. Click _Save settings_. The Vendor URL has been added to the content
type. Continue creating the Main image field.

. Click _Add field_. The _Add field_ page appears. Fill in the fields as shown
below.
+
[width="100%",frame="topbot",options="header"]
|================================
| Field name | Explanation | Value
| Add a new field | Field type | Image
| Label | Label that is visible in administration pages | Main image
|================================

. Click _Save and continue_. The page Main image appears. Fill in the fields
as shown below.
+
[width="100%",frame="topbot",options="header"]
|================================
| Field name | Explanation | Value
| Allowed number of values | The number of values that can be entered | Limited, 1
|================================
+
You can set a default image here. This will be used when you do not provide an
image when creating a Vendor content item.

. Click _Save field settings_. The page _Main image settings for Vendor_
appears. Fill in the fields as shown below.
+
[width="100%",frame="topbot",options="header"]
|================================
| Field name | Explanation | Value
| Label  | Label that is visible in the content form | Main image
| Help text | The instruction that is shown below the field | (leave blank)
| Required field | Whether the field is required or not | Checked
| Allowed file extensions | The type of images that can be uploaded | png, gif, jpg, jpeg
| File directory | The directory where the files will be stored. By providing a file directory value, you ensure that all images uploaded via the Main image field will be located in the same directory. | vendors
| Minimum image resolution | The minimum resolution of the uploaded image | 600 x 600
| Maximum upload size | The maximum file size of the uploaded image | 5 MB
| Enable Alt field | Whether an alternative text can be entered | Checked
| Alt field required | Whether an alternative text is required | Checked
|================================
+
--
// Field settings page for adding main image field.
image:images/structure-fields-main-img.png["Field settings page for Main Image",width="100%"]
--

. Click _Save settings_. Main image has been added to the content type.
+
--
// Manage fields page for Vendor, showing two new fields.
image:images/structure-fields-result.png["Manage fields page",width="100%"]
--

. Add a Main image field to the Recipe content type, using similar steps. Start
by navigating to the Recipe content type's _Manage Fields_ page in step 1. Then
skip to step 7 and follow the remaining steps, but reuse the existing Main image
field you created for the Vendor content type rather than creating a new
field. In subsequent steps, some of the configuration screens will not be
available, because of the field reuse.

. Create two Vendor content items (see <<content-create>>) called "Happy Farm"
and "Sweet Honey". Make sure that they include images and URLs.

==== Expand your understanding

* <<structure-image-styles>>
* <<structure-content-display>>
* <<structure-form-editing>>

// ==== Related concepts

==== Additional resources

https://www.drupal.org/node/774742[_Drupal.org_ community documentation page "Add a field to a content type"]


*Attributions*

Written by https://www.drupal.org/u/sree[Sree Veturi] and
https://www.drupal.org/u/batigolix[Boris Doesborg].
