Content types in Drupal 12: building Article and Basic page yourself

Building

On Drupal 10 the Standard profile gave you two content types, Article and Basic page, before you had done anything. On Drupal 12 you get none. The change came in Drupal 11.4, when the two types were removed from the Standard profile and recipe, and Drupal 12 has no core recipes that bring them back. That is deliberate: most sites need their own content model anyway. But it does mean that the first thing you do on a new site is build one.

Plan the fields first

A typical article and page need less than you might think. This is what we use on this site:

FieldField typeArticlePage
Title(built in)yesyes
SummaryText (plain, long)yesyes
BodyText (formatted, long)yesyes
TopicsEntity reference → taxonomy termyesno

Add an image or media field if your articles have a lead image, and a Tags field if you apply the core tags_taxonomy recipe.

The summary: no more "text with summary"

The Body field on old Drupal sites used the field type Text (formatted, long, with summary), which had a built-in summary box. That field type was moved into a separate, deprecated module in Drupal 11.5 and is removed from core in Drupal 12; it continues as a contributed module. For a new site the simplest choice is a separate summary field:

  • Summary: Text (plain, long). Plain text is right for a summary, because it ends up in meta descriptions and cards where HTML does not belong.
  • Body: Text (formatted, long), with your text formats and CKEditor 5.

If you are upgrading a site that uses text with summary, do not delete the field. Update to Drupal 11.5, run the database updates and require the contributed module before you move to Drupal 12. See Upgrading from Drupal 11 to Drupal 12.

In the admin

  1. Go to Structure → Content types → Add content type.
  2. Give it a name (Article) and check the settings under the form: whether new revisions are created by default, whether author and date are shown, and whether the type is Promoted by default. ("Promoted to front page" has been called just "Promoted" since 11.5.)
  3. Save, then Manage fields → Create a new field for Summary and Body as above.
  4. Under Manage form display, put Summary above Body and give it three or four rows.
  5. Under Manage display, show Body in the Default view mode and hide Summary; in the Teaser view mode, show Summary and hide Body. Teasers are what lists of content use.
  6. Repeat for Basic page, without Topics and not promoted.

Then export the configuration (drush config:export) so the content model lives in your repository.

In code

If you build sites from scripts, the same thing takes about 60 lines of PHP run with drush php:script. The core of it:

use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;

NodeType::create([
  'type' => 'article',
  'name' => 'Article',
  'new_revision' => TRUE,
  'display_submitted' => FALSE,
])->save();

FieldStorageConfig::create([
  'field_name' => 'field_summary',
  'entity_type' => 'node',
  'type' => 'string_long',
])->save();

FieldConfig::create([
  'field_name' => 'field_summary',
  'entity_type' => 'node',
  'bundle' => 'article',
  'label' => 'Summary',
])->save();

Do the same for body with the type text_long, then set the form and view displays with \Drupal::service('entity_display.repository'). Check for existing types and fields before creating them, so the script can run twice. When you are happy, export the configuration – from then on, installs use the export and not the script. That is how this site's content types were made.

Or as a recipe

If several sites should share the same content model, turn the exported configuration into a recipe of your own. See Recipes in Drupal 12.

Do not forget the front page

The view that lists promoted content on the front page, Promoted content (machine name promoted_content, formerly frontpage), is disabled on a new site, and the front page points to an admin welcome page. Enable the view under Structure → Views, or build your own, and set the front page path under Configuration → Basic site settings.