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
http://pulsezestrx.com/#…
http://pulsezestrx.com/# over the counter sildenafil
Дані-інфо https://dani-info…
Дані-інфо https://dani-info.com – новинний сайт Балаклії. Тут публікують події міста й громади, новини Харківщини та корисні матеріали для мешканців.
Провінція provintsiya.com.ua…
Провінція provintsiya.com.ua це міський новинний сайт Вінниці. Тут публікують події міста й області, рейтинги закладів та корисні матеріали для мешканців.
An innovative ai undress…
An innovative ai undress online AI generator for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
Дані-інфо https://dani-info…
Дані-інфо https://dani-info.com – новинний сайт Балаклії. Тут публікують події міста й громади, новини Харківщини та корисні матеріали для мешканців.
Провінція https:/…
Провінція https://provintsiya.com.ua/ це міський новинний сайт Вінниці. Тут публікують події міста й області, рейтинги закладів та корисні матеріали для мешканців.
Discover the cutting-edge ai…
Discover the cutting-edge ai naked AI nude generator. Quickly remove clothing from photos using next-generation neural networks. Highly realistic and confidential.
actual payday loan lenders…
actual payday loan lenders online: loans till payday everyone approved - most reliable payday loan company
An innovative undress ai…
An innovative undress ai online AI generator for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
Нужны публикации в сми для…
Нужны публикации в сми для geo? Размещаем экспертные статьи на 200+ трастовых площадках. Нейросети цитируют ваш бренд в ответах ChatGPT и Яндекс Нейро. Публикации в СМИ для GEO дают рост доверия LLM.
Tadalafil Tablet Tada Vora п…
Tadalafil Tablet Tada Vora п»їcialis generic
https://pulsezestrx.com/#…
https://pulsezestrx.com/# over the counter sildenafil
https://shiftcaploans.shop/#…
https://shiftcaploans.shop/# paycheck advance online
Нужен сыр? сыры оптом в…
Нужен сыр? сыры оптом в москве в Москве для магазинов, кафе, ресторанов и предприятий общественного питания. Широкий выбор твёрдых, мягких и полутвёрдых сортов, выгодные условия закупки, оптовые цены и доставка продукции.
баня купить под ключ…
баня купить под ключ недорого баня на участок под ключ
A detailed overview undress…
A detailed overview undress ai of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
cash advance no interest:…
cash advance no interest: ShiftCap - cash advance no interest
глаз бога телеграм бот глаз…
глаз бога телеграм бот глаз бога по номеру телефона
баня под ключ сколько стоит…
баня под ключ сколько стоит баня под ключ
A detailed overview undress…
A detailed overview undress ai of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
баня готовая под ключ с…
баня готовая под ключ с доставкой бани готовые под ключ цены
A detailed overview https:/…
A detailed overview https://undress-tools.carrd.co of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
глаз бога бот глаз бога…
глаз бога бот глаз бога телеграмм бот
глаз бога поиск людей глаз…
глаз бога поиск людей глаз бога телеграмм бот
Нужен сыр? белорусский сыр в…
Нужен сыр? белорусский сыр в россии оптом в Москве для магазинов, кафе, ресторанов и предприятий общественного питания. Широкий выбор твёрдых, мягких и полутвёрдых сортов, выгодные условия закупки, оптовые цены и доставка продукции.
бани готовые под ключ цены…
бани готовые под ключ цены баня под ключ
A detailed overview undress…
A detailed overview undress ai of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
баня под ключ бани готовые…
баня под ключ бани готовые под ключ недорого
A detailed overview https:/…
A detailed overview https://undress-tools.carrd.co of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
глаз бога онлайн глаз бога…
глаз бога онлайн глаз бога найти человека
https://pulsezestrx.shop/#…
https://pulsezestrx.shop/# viagra without prescription
Cialis 20mg price and…
Cialis 20mg price and Generic Tadalafil 20mg price Cialis over the counter
http://www.kuri.ne.jp/game/go_url.cgi?url=https://tadavorarx.shop п»їcialis genericor https://brueckrachdorf.de/user/nwgbnyobjp/ п»їcialis generic
cheapest cialis Tadalafil Tabletand Generic Cialis without a doctor prescription п»їcialis generic
Нужен сыр? поставщик сыров…
Нужен сыр? поставщик сыров оптом в Москве для магазинов, кафе, ресторанов и предприятий общественного питания. Широкий выбор твёрдых, мягких и полутвёрдых сортов, выгодные условия закупки, оптовые цены и доставка продукции.
Нужен сыр? сыр оптом от…
Нужен сыр? сыр оптом от производителя в Москве для магазинов, кафе, ресторанов и предприятий общественного питания. Широкий выбор твёрдых, мягких и полутвёрдых сортов, выгодные условия закупки, оптовые цены и доставка продукции.
A detailed overview https:/…
A detailed overview https://undress-tools.carrd.co of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
Sildenafil Citrate Tablets…
Sildenafil Citrate Tablets 100mg: Pulse Zest viagra - Viagra tablet online
баня купить под ключ цена…
баня купить под ключ цена баня недорого под ключ цены
Нужен сыр? поставщик сыров…
Нужен сыр? поставщик сыров оптом в Москве для магазинов, кафе, ресторанов и предприятий общественного питания. Широкий выбор твёрдых, мягких и полутвёрдых сортов, выгодные условия закупки, оптовые цены и доставка продукции.
A detailed overview https:/…
A detailed overview https://undress-tools.carrd.co of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
баня недорого под ключ цены…
баня недорого под ключ цены баня под ключ с установкой
Нужен сыр? сыр купить оптом…
Нужен сыр? сыр купить оптом от производителя в Москве для магазинов, кафе, ресторанов и предприятий общественного питания. Широкий выбор твёрдых, мягких и полутвёрдых сортов, выгодные условия закупки, оптовые цены и доставка продукции.
Нужен сыр? поставщик сыров…
Нужен сыр? поставщик сыров оптом в Москве для магазинов, кафе, ресторанов и предприятий общественного питания. Широкий выбор твёрдых, мягких и полутвёрдых сортов, выгодные условия закупки, оптовые цены и доставка продукции.
глаз бога в тг бот канал…
глаз бога в тг бот канал глаз бога
готовая баня под ключ https:…
готовая баня под ключ https://banya-pod-klyuch1.ru
A detailed overview https:/…
A detailed overview https://undress-tools.carrd.co of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
A detailed overview https:/…
A detailed overview https://undress-tools.carrd.co of Undress AI and DeepNude technologies. Learn about image generation features, limitations of artificial intelligence, privacy policies, photo upload security, and terms of use.
бани готовые под ключ…
бани готовые под ключ недорого баня под ключ с установкой
глаз бога телеграм бот глаз…
глаз бога телеграм бот глаз бога сайт
глаз бога глаз бога телеграмм
глаз бога глаз бога телеграмм
http://tadavorarx.com/#…
http://tadavorarx.com/# Cialis 20mg price in USA
Pagination
Add new comment