Content types are the backbone of content management in Drupal. In Drupal 10, you can create custom content types to structure and organize your content. This blog post will guide you through the process of creating content types programmatically in Drupal 10, allowing you to tailor your website's content structure to your specific needs.
Prerequisites
Before creating custom content types programmatically in Drupal 10, you should have the following:
- A working Drupal 10 or 9 website.
- Basic knowledge of Drupal site building and module development.
- Familiarity with PHP and Drupal's module structure.
Step 1: Define the Custom Module
To create a custom content type programmatically, you need to place the code in a custom module. If you don't already have a custom module, you can create one by following these steps:
- In your Drupal installation, navigate to the sites/all/modules directory (or your preferred module location).
- Create a new directory for your custom module. Give it a unique and descriptive name, such as my_custom_content_type.
- Inside your module directory, create a my_custom_content_type.info.yml file with the following content:
name: 'My Custom Content Type Module'
type: module
description: 'Defines custom content types programmatically.'
core_version_requirement: ^9 || ^10
package: Custom
dependencies:
- nodeThis YAML file defines the basic information about your custom module.
Step 2: Create a Custom Content Type
To create a custom content type, you'll need to implement the hook_entity_type_build and hook_node_type_insert hooks within your custom module.
- Create a file named my_custom_content_type.module in your module directory.
- In this file, implement the hook_entity_type_build hook to define your custom content type. Here's an example:
/**
* Implements hook_entity_type_build().
*/
function my_custom_content_type_entity_type_build(array &$entity_types) {
$entity_types['node']->setClass('Drupal\my_custom_content_type\NodeTypeCustom');
}This code defines a custom class, NodeTypeCustom, to handle the configuration of your custom content type.
- Create the NodeTypeCustom class in a file named NodeTypeCustom.php and place it in your module's directory:
namespace Drupal\my_custom_content_type;
use Drupal\node\NodeTypeBase;
/**
* Provides a custom content type.
*/
class NodeTypeCustom extends NodeTypeBase {
/**
* {@inheritdoc}
*/
public function postSave(NodeTypeInterface $node_type) {
parent::postSave($node_type);
// Define the custom content type settings.
$config = \Drupal::configFactory()->getEditable('node.type.' . $node_type->id());
$config->set('name', 'Custom Content Type');
$config->set('description', 'A custom content type created programmatically.');
$config->set('new_revision', TRUE);
$config->save();
}
}n the NodeTypeCustom class, we extend the NodeTypeBase class to define the custom content type settings, such as the name and description.
Step 3: Enable and Verify Your Custom Content Type
- In your Drupal admin interface, navigate to Extend (admin/modules) and enable your custom module, "My Custom Content Type Module."
- After enabling the module, go to Structure > Content types (admin/structure/types) to see your custom content type listed as "Custom Content Type."
Conclusion
Creating custom content types programmatically in Drupal 10 allows you to define content structures that fit your specific project requirements. By following the steps outlined in this blog post, you can easily create and configure custom content types within your Drupal website, providing a flexible and tailored content management experience.
In Drupal 9 and 10, custom modules should be stored in the "modules/custom" directory rather than "sites/all/modules." Drupal's module directory structure has evolved, and the recommended practice is to place custom modules in the "modules/custom" directory to follow the modern Drupal standards.
So, if you're creating a custom module in Drupal 9 or 10, you should place it in the following directory:
/sites/all/modules/custom/By following this structure, your custom modules will be more organized and adhere to Drupal's best practices, making it easier to manage and maintain your site's codebase.
Comment
mail order levothyroxine…
mail order levothyroxine Levo Care Pharma buy thyroid hormone pills online
https://gabarxdirect.shop/#…
https://gabarxdirect.shop/# cost of gabapentin
https://pulseguarddirect.com…
https://pulseguarddirect.com/# metoprolol tartrate
mail order levothyroxine…
mail order levothyroxine Levo Care Pharma generic synthroid for sale
gabapentin pics: Gaba Rx…
gabapentin pics: Gaba Rx Direct - gabapentin loperamide
https://zpacksupply.shop/#…
https://zpacksupply.shop/# zithromax without prescription
https://dermatretdirect.shop…
https://dermatretdirect.shop/# accutane for sale online
gabapentin dosage epocrates:…
gabapentin dosage epocrates: Gaba Rx Direct - farmaco gabapentin 300
https://pulseguarddirect.com…
https://pulseguarddirect.com/# Lopressor medication dosage
Lopressor brand name…
Lopressor brand name metoprolol: metoprolol tartrate - Lopressor oral solution side effects
can i buy zithromax online…
can i buy zithromax online or zithromax 500 mg lowest price drugstore online zithromax capsules 250mg
http://maps.google.nr/url?q=http://zpacksupply.com buy zithromax without prescor http://clubdetenisalbatera.es/user/gaxcxplatc/ buy cheap generic zithromax
zithromax generic cost zithromax 500 mg lowest price drugstore onlineand zithromax 250 mg where can i purchase zithromax online
http://zpacksupply.com/#…
http://zpacksupply.com/# where to buy zithromax in canada
Clear advice on how to sell…
Clear advice on how to sell products on amazon should compare fulfillment options, explain seller fees, and show how product economics change under different assumptions. Restricted products and intellectual property issues deserve early attention because a promising item is not useful if it cannot be listed compliantly. A cautious launch protects cash while generating useful evidence.
People comparing ai…
People comparing ai girlfriend should consider whether memory can be corrected or deleted, how billing works, and which features require additional credits. Customization is more meaningful when personality, appearance, tone, boundaries, and memory can be adjusted without rebuilding the character. A trustworthy review describes limitations openly instead of promising perfect memory, unlimited features, or genuinely human understanding.
Anyone considering buy…
Anyone considering buy tiktok likes should compare delivery speed, retention, refill terms, privacy practices, payment security, and recent independent feedback. Secure checkout, recognizable billing details, receipts, dispute procedures, and responsive support matter as much as the listed payment method. Organic growth still depends on the video itself, even if a paid service changes the visible like count.
A practical guide to how to…
A practical guide to how to sell on amazon should explain account setup, product selection, sourcing, listing creation, and order fulfillment in a clear sequence. A polished listing still needs accurate claims, clear images, relevant search terms, and inventory that can be replenished without tying up all available cash. Visible risks are easier to understand and manage.
For users planning to buy…
For users planning to buy tiktok likes, price should be weighed against retention, privacy, support quality, delivery controls, and the credibility of customer reviews. Purchased metrics cannot replace content quality, audience research, consistent posting, useful hooks, and genuine interaction with viewers. Clear service terms make value easier to judge without relying on unsupported claims about quality, safety, or future performance.
can you buy zithromax over…
can you buy zithromax over the counter in australia: ZPackSupply - buy zithromax
http://gabarxdirect.com/#…
http://gabarxdirect.com/# yellow capsule identification g 2705 gabapentin
venlafaxine gabapentin and…
venlafaxine gabapentin and zoloft gabapentin interaction gabapentin major side effects
https://www.google.co.ck/url?q=https://gabarxdirect.com gabapentin dosage zoster and http://www.orangepi.org/orangepibbsen/home.php?mod=space&uid=7125268 gabapentin ipotensione
pregabalin gabapentin comparison contraindications gabapentin or gabapentin gastrointestinal side effects can you buy fluoxetine
https://dermatretdirect.com/…
https://dermatretdirect.com/# accutane discount pharmacy
accutane discount pharmacy:…
accutane discount pharmacy: dermatretdirect - cheap accutane online pharmacy
zithromax 250 price:…
zithromax 250 price: zithromax capsules australia - zithromax 250
order roaccutane 20mg:…
order roaccutane 20mg: dermatretdirect - cheap accutane online pharmacy
http://dermatretdirect.com/#…
http://dermatretdirect.com/# indian generic accutane online
order roaccutane 20mg and…
order roaccutane 20mg and isotretinoin 30mg price buy cystic acne medication accutane
http://www.tanadakenzai.co.jp/feed2js/feed2js.php?src=http://dermatretd… generic accutane cost and https://bold-kw.com/user/krohznoxoi/?um_action=edit generic isotretinoin tablets
order isotretinoin without prescription generic accutane cost or indian generic accutane online where to buy accutane online safely
accutane discount pharmacy…
accutane discount pharmacy dermatretdirect accutane for sale online
https://dermatretdirect.com/…
https://dermatretdirect.com/# accutane discount pharmacy
how do i take lopressor oral…
how do i take lopressor oral solution: lopressor oral solution package insert - Lopressor pills pictures
gabapentin vs lyrica for…
gabapentin vs lyrica for diabetic neuropathy or how to buy gabapentin costo gabapentin 100mg
https://maps.google.lk/url?q=https://gabarxdirect.com order gabapentin or https://brueckrachdorf.de/user/himiavvrel/ gabapentin for breast cancer pain
gabapentin results does gabapentin cause blurry vision and what class is gabapentin in fluoxetine without insurance
http://gabarxdirect.com/#…
http://gabarxdirect.com/# gabapentin tablets
buy zithromax 1000 mg online…
buy zithromax 1000 mg online and zithromax antibiotic cost of generic zithromax
https://www.google.hn/url?q=https://zpacksupply.com zithromax prescriptionor http://lenhong.fr/user/uojjylrojr/ zithromax prescription in canada
where can i buy zithromax capsules zithromax 500mg priceor buy generic zithromax no prescription zithromax prescription
http://dermatretdirect.com/#…
http://dermatretdirect.com/# purchase isotretinoin pills
Нужен алкоголь? доставка…
Нужен алкоголь? доставка алкоголя 24 часа Омск удобный способ выбрать напитки для праздника, вечеринки или семейного торжества. Ознакомьтесь с ассортиментом, сравните цены и условия заказа, узнайте о доступных вариантах получения продукции и особенностях обслуживания.
synthroid 150 mcg dosage buy…
synthroid 150 mcg dosage buy Levo Care Pharma synthroid 112 mcg online order
http://dermatretdirect.com/#…
http://dermatretdirect.com/# mail order accutane online
Uncover the details games…
Uncover the details games-steamsub.website.yandexcloud net
Read more on the website…
Read more on the website http://www.games-steamsub.website.yandexcloud.net/
п»їbuy accutane online or…
п»їbuy accutane online or generic isotretinoin tablets accutane for sale online
http://mobielewebsite.inmotiv.nl/16915/?referer=http://dermatretdirect… buy legit accutane online or http://asresin.cn/home.php?mod=space&uid=1314170 isotretinoin online prescription free
order isotretinoin capsules buy cystic acne medication accutane or order isotretinoin capsules п»їbuy accutane online
zithromax for sale online:…
zithromax for sale online: ZPackSupply - buy zithromax without prescription online
how long do gabapentin take…
how long do gabapentin take to work or can i get gabapentin gabapentin controlled drug
https://loopbaan.dezorggroep.nl/redirect.php?from=gabarxdirect.com gabapentin results or https://www.trendyxxx.com/user/swsphppjey/videos gabapentin in verbindung mit alkohol
glenmark gabapentin gluten free gabapentin 300 mg how to take or gabapentin compresse 100 mg gabapentin drug price
https://pulseguarddirect.com…
https://pulseguarddirect.com/# metoprolol tartrate lopressor rxlist
Нужен юрист? бесплатная…
Нужен юрист? бесплатная юридическая помощь населению в Ярославле - отличная возможность получить помощь опытных правозащитников в любой области права: семейные споры, долги и кредиты, недвижимость, трудовые конфликты, защита прав потребителей и многое другое. Задайте вопрос юристу онлайн или обратитесь по телефону горячей линии из любого региона России. Консультация доступна круглосуточно и без регистрации.
purchase generic synthroid…
purchase generic synthroid online synthroid 150 mcg dosage buy order levothyroxine 175 mcg
where can i buy zithromax uk…
where can i buy zithromax uk: Z-Pack Supply - zithromax cost
Best selection of the day…
Best selection of the day https://www.secondary-glazing.me.uk/casino-slot-games-on-mobile-devices…
https://gabarxdirect.com/#…
https://gabarxdirect.com/# can i order gabapentin
Read the extended version…
Read the extended version https://beverleyjamescounselling.co.uk/2026/10/13/understanding-the-tre…
The most interesting click…
The most interesting click https://coral-hedgehog-990663.hostingersite.com/2026/10/13/waliya-bet-b…
Today's summary https:/…
Today's summary https://lawinsight.in/2026/10/13/megapari-%e1%88%b5%e1%8d%96%e1%88%ad%e…
Pagination
Add new comment