Skip to main content
Version: Latest
Technical ManualLooking for step-by-step instructions? In the User Manual: Content Fields

Content Fields

Feature NameCrestApps Content Fields
Feature IDCrestApps.OrchardCore.ContentFields

Provides custom Orchard Core content fields maintained by CrestApps.

Overview​

This module adds custom content fields for Orchard Core that extend the built-in field library with additional functionality. Each field ships with its own display driver, settings, edit and display views.

The feature depends on CrestApps.OrchardCore.Resources, CrestApps.OrchardCore.PhoneNumbers, OrchardCore.ContentFields and OrchardCore.ContentTypes.

How administrators add a phone field to a content type, what each setting does, and what editors see is described in the User Manual: Content Fields.

Using the fields from code​

The field classes and their settings (PhoneField, AddressField, PhoneFieldSettings, InitialCountryMode and AddressFieldSettings) live in the CrestApps.OrchardCore.ContentFields.Abstractions package, in the CrestApps.OrchardCore.ContentFields.Fields and CrestApps.OrchardCore.ContentFields.Settings namespaces. Reference that package to read or write the fields from another module or library; the module itself holds the editors, views, drivers and the AddressFieldIndex. Orchard Core resolves content fields and their settings by class name, so the stored content definitions and content items are the same as before the classes moved.

Included fields​

PhoneField​

A content field that stores an international phone number together with its ISO country code so the correct country flag is always displayed when the field is edited again.

The field uses the intl-tel-input library (provided by CrestApps.OrchardCore.Resources) to give editors a country-aware phone number input with flag dropdown and automatic formatting.

Stored properties​

PropertyTypeDescription
PhoneNumberstringThe full phone number in E.164 format (e.g. +14155552671).
CountryCodestringISO 3166-1 alpha-2 country code (e.g. US, CA). Stored separately because some countries share a calling code (e.g. US and CA both use +1).
NationalNumberstringThe national (local) portion of the number without the country calling code (e.g. 4155552671).

Settings​

SettingTypeDefaultDescription
HintstringnullHelp text displayed below the field (admin label Hint).
RequiredboolfalseWhether the field is required.
InitialCountryModeInitialCountryModeGlobe (admin label Initial country)Controls which country flag is pre-selected when the field is empty. See Initial country modes.
SpecificCountryCodestringnullAdmin label Country. ISO country code used when InitialCountryMode is Specific (e.g. US).

Initial country modes​

ModeBehavior
GlobeShows the globe icon without pre-selecting any country. This is the default.
Current cultureResolves the country from the current request culture's region (e.g. en-US resolves to US).
SpecificAlways pre-selects the country configured in the Country dropdown.

Adding PhoneField via migration​

await _contentDefinitionManager.AlterPartDefinitionAsync("MyPart", part => part
.WithField("Phone", field => field
.OfType("PhoneField")
.WithDisplayName("Phone Number")
.WithPosition("1")
.WithSettings(new PhoneFieldSettings
{
Required = true,
InitialCountryMode = InitialCountryMode.Specific,
SpecificCountryCode = "US",
Hint = "Enter a phone number with country code.",
})
)
);

When CrestApps.OrchardCore.Recipes is also enabled, recipe schemas now understand both the PhoneFieldSettings envelope used by ContentDefinition and the PhoneNumber / CountryCode / NationalNumber payload stored on content items.

Server-side validation​

When the field value is submitted, the display driver uses IPhoneNumberService (from CrestApps.OrchardCore.PhoneNumbers) to validate that the entered number is a well-formed phone number. Invalid numbers produce a model-state error and the editor is re-displayed.

AddressField​

Feature Address Field (CrestApps.OrchardCore.ContentFields.Address), depending on Addresses (CrestApps.OrchardCore.Addresses), OrchardCore.ContentFields and OrchardCore.ContentTypes. It is a feature of its own so the CrestApps Content Fields feature does not depend on Addresses.

A content field holding the shared Address value from the Addresses module. A content type can have several, for example a Home and a Work address.

Stored properties​

PropertyTypeDescription
AddressAddressThe address, or null when none was entered: Name, Company, AddressLine1, AddressLine2, DependentLocality, City, Region (the region's ISO 3166-2 code without the country, when the country lists regions), County, District, PostalCode, SortingCode, Country (ISO 3166-1 alpha-2) and Phone.

Settings (AddressFieldSettings)​

SettingTypeDefaultDescription
HintstringnullHelp text shown above the address.
RequiredboolfalseWhether an address must be entered. An optional address left blank is stored as null.
ShowName, ShowCompany, ShowPhonebooltrue, true, falseWhich of the recipient, the company and a phone number the editor asks for.
Countriesstring[]nullThe ISO codes of the countries offered; null or empty offers every country ICountryService lists.
DefaultCountrystringnullThe country a new address starts in.

Editing and display​

The editor is the Addresses module's AddressEditor shape, bound under the field's prefix and checked with IAddressEditorService, so it is laid out for the chosen country and refuses what that country's rules refuse (required parts, postal code pattern, region list, postal code within the region). The display shape AddressField prints the address through IAddressFormatter. AddressField and Address are registered with Liquid's member access strategy.

Index​

AddressFieldIndex (a ContentFieldIndex) has a row per address field, with Country, Region, City and PostalCode, so content can be queried by place:

var venues = await session
.Query<ContentItem, AddressFieldIndex>(index => index.ContentType == "Venue" && index.Country == "CA" && index.Region == "ON" && index.Published)
.ListAsync();

Recipes​

With CrestApps Recipes on, AddressField has a content-definition schema (its settings) and a content schema (the Address object), like PhoneField.

Notes​

  • The shared intl-tel-input script and stylesheet are registered by CrestApps.OrchardCore.Resources.
  • The Omnichannel Management module depends on this feature for PhoneNumberInfoPart.Number.