logo

Extra Block Types (EBT) - Nieuwe Layout Builder ervaring❗

Extra Block Types (EBT) - gestileerde, aanpasbare bloktypes: Slideshows, Tabs, Cards, Accordions en vele andere. Ingebouwde instellingen voor achtergrond, DOM Box, javascript-plugins. Ervaar vandaag al de toekomst van layout building.

Demo EBT-modules Download EBT-modules

❗Extra Paragraph Types (EPT) - Nieuwe Paragraphs ervaring

Extra Paragraph Types (EPT) - analoge op paragrafen gebaseerde set modules.

Demo EPT-modules Download EPT-modules

Scroll

Aanmaken van een custom inhoudstype in Drupal

30/09/2025, by Ivan

Deze pagina is een kopie van de configuratie “Enable by default” in de Drupal 8-module. Dit moet worden beschouwd als verouderd.

Het aanmaken van een custom inhoudstype is vrij eenvoudig geworden dankzij de nieuwe configuratie-API die met Drupal 8 wordt geleverd.

Voorwaarden

  • Drupal 8.0.x is geïnstalleerd
  • Een custom module hebben (de modulenaam die in dit voorbeeld wordt gebruikt is foobar)

Aanmaken van een custom inhoudstype

Zoals in de introductie vermeld, wordt het aanmaken van een custom inhoudstype gedaan door enkele YAML-bestanden aan te maken die alle vereiste instellingen bevatten. In dit voorbeeld maken we het inhoudstype Car Brand, dat twee velden (standaard) zal bevatten: body en titel.

foobar/config/install/node.type.car_brand.yml

Dit bestand vertelt Drupal dat het een nieuw inhoudstype moet aanmaken.

Opmerking: houd er rekening mee dat we een verplichte dependency toevoegen aan de foobar-module. Als we deze dependency niet toevoegen, zal Drupal het inhoudstype niet verwijderen wanneer onze module wordt verwijderd. Wanneer de siteontwikkelaar beslist dat deze module niet langer nodig is, willen we ook niet dat dit inhoudstype nog beschikbaar is.

# node.type.car_brand.yml
langcode: en
status: true
dependencies:
  enforced:
    module:
      - foobar # Dit is de naam van de module die we in dit voorbeeld gebruiken
name: 'Car Brand'
type: car_brand
description: 'Content type that can be used to provide additional information on <em>Car Brands</em>'
help: ''
new_revision: false
preview_mode: 1
display_submitted: true

 

foobar/config/install/field.field.node.car_brand.body.yml

Dit bestand voegt het body-veld toe aan ons inhoudstype.

# field.field.node.car_brand.body.yml
langcode: en
status: true
dependencies:
    config:
        - field.storage.node.body
        - node.type.car_brand
    module:
        - text
id: node.car_brand.body
field_name: body
entity_type: node
bundle: car_brand
label: Body
description: 'More specific information about the car brand.'
required: false
translatable: true
default_value: {  }
default_value_callback: ''
settings:
    display_summary: true
field_type: text_with_summary

 

foobar/config/install/core.entity_view_display.node.car_brand.teaser.yml

Dit bestand vertelt Drupal hoe de teaser van ons custom inhoudstype moet worden weergegeven.

# core.entity_view_display.node.car_brand.teaser.yml
langcode: en
status: true
dependencies:
    config:
        - core.entity_view_mode.node.teaser
        - field.field.node.car_brand.body
        - node.type.car_brand
    module:
        - text
        - user
id: node.car_brand.teaser
targetEntityType: node
bundle: car_brand
mode: teaser
content:
    body:
        label: hidden
        type: text_summary_or_trimmed
        weight: 101
        settings:
            trim_length: 600
        third_party_settings: {  }
    links:
        weight: 100
hidden: {  }

 

foobar/config/install/core.entity_view_display.node.car_brand.default.yml

Dit bestand vertelt Drupal hoe de inhoud van ons custom inhoudstype standaard moet worden weergegeven.

# core.entity_view_display.node.car_brand.default.yml
langcode: en
status: true
dependencies:
    config:
        - field.field.node.car_brand.body
        - node.type.car_brand
    module:
        - text
        - user
id: node.car_brand.default
targetEntityType: node
bundle: car_brand
mode: default
content:
    body:
        label: hidden
        type: text_default
        weight: 101
        settings: {  }
        third_party_settings: {  }
    links:
        weight: 100
hidden: {  }

 

foobar/config/install/core.entity_form_display.node.car_brand.default.yml

Dit bestand vertelt Drupal hoe het formulier moet worden weergegeven bij het aanmaken van een nieuwe node van ons custom inhoudstype.

# core.entity_form_display.node.car_brand.default.yml
langcode: en
status: true
dependencies:
    config:
        - field.field.node.car_brand.body
        - node.type.car_brand
    module:
        - text
        - user
id: node.car_brand.default
targetEntityType: node
bundle: car_brand
mode: default
content:
    body:
        label: hidden
        type: text_textarea_with_summary
        weight: 101
        settings: { }
        third_party_settings: { }
    links:
        weight: 100
hidden: { }

Activeer het custom inhoudstype

Nu we onze configuratiebestanden hebben, moeten we Drupal informeren over ons nieuwe custom inhoudstype. Dit gebeurt door de module opnieuw te installeren. Als je module nog niet was ingeschakeld, schakel de module dan in. Als je module al was ingeschakeld, verwijder de module en schakel hem opnieuw in.
Als je nu naar de pagina “Inhoud aanmaken” gaat, zie je dat je een nieuwe node van het inhoudstype “Car Brand” kunt aanmaken.