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
An innovative AI generator…
An innovative AI generator naked ai free for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
indian online pharmacy ship…
indian online pharmacy ship to usa: cipla sun pharma online store - meds from india
An innovative AI generator…
An innovative AI generator naked ai image generator for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
canadian pharmacy online:…
canadian pharmacy online: canadexia pharmacy - canadian pharmacy store
An innovative AI generator…
An innovative AI generator naked ai app for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
canadian online pharmacy:…
canadian online pharmacy: discount canadian generics - canadian pharmacy official site
https://canadexiarx.com/#…
https://canadexiarx.com/# canadian pharmacy service
An innovative AI generator…
An innovative AI generator naked ai app for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
An innovative AI generator…
An innovative AI generator naked ai free for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
medicines from india: cipla…
medicines from india: cipla sun pharma online store - online pharmacy in india
https://deccanbatchrx.com/#…
https://deccanbatchrx.com/# pharmacy india
An innovative AI generator…
An innovative AI generator naked ai for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
https://canadexiarx.com/#…
https://canadexiarx.com/# canadian pharmacy 365
An innovative AI generator…
An innovative AI generator naked ai generator for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!
best online pharmacies in…
best online pharmacies in mexico cheap mexican rx mail order mexican online pharmacy wegovy
india pharmacy online: india…
india pharmacy online: india online pharmacy - sending medicines from india to usa
https://canadexiarx.com/#…
https://canadexiarx.com/# canadian pharmacy rx
https://deccanbatchrx.com/#…
https://deccanbatchrx.com/# buying medicine online in india
mexico pharmacy order online…
mexico pharmacy order online delivery: buy meds from mexico safely - pharmacy mexico online
строительство бани под ключ…
строительство бани под ключ заказать баню под ключ
vipps approved canadian…
vipps approved canadian online pharmacy: discount canadian generics - canada rx pharmacy
бани на заказ под ключ баня…
бани на заказ под ключ баня недорого под ключ цены
indian pharmacy in usa and…
indian pharmacy in usa and get medicine instantly buy medicine without prescription
http://viktorianews.victoriancichlids.de/htsrv/login.php?redirect_to=ht… buy generic medicines online india or http://www.garmoniya.uglich.ru/user/dyofafblfs/ india pharmacy international shipping
online medicine purchase in india online medicine delivery or generic medicines in india indian pharmacy shipping to usa
mexico drug store:…
mexico drug store: curadelsol pharmacy - mexican drugstore
https://canadexiarx.com/#…
https://canadexiarx.com/# safe canadian pharmacy
баня под ключ бани под ключ…
баня под ключ бани под ключ недорого
legitimate canadian pharmacy…
legitimate canadian pharmacy or canada pharmacy certified canadian pharmacy
https://forum.lephoceen.fr/proxy.php?link=https://canadexiarx.com::: canadian pharmacies shipping to usa or https://exhibitioncourthotel4.co.uk/user-2/omvtsbntit/?um_action=edit canadian pharmacy ltd
canadian pharmacy ratings canadian pharmacy compare or safe online pharmacies in canada pharmacies in canada that ship to the us
rx india online shopping:…
rx india online shopping: indian pharmacy paypal - best online pharmacies in india
https://canadexiarx.com/#…
https://canadexiarx.com/# canadian pharmacies
п»їcanadian pharmacy:…
п»їcanadian pharmacy: canadexia pharmacy - online pharmacy canada
safe canadian pharmacy or…
safe canadian pharmacy or best canadian pharmacy canadian pharmacies online
https://www.klickerkids.de/index.php?url=http://canadexiarx.com best online canadian pharmacy and https://www.0468wudi.com/home.php?mod=space&uid=352682 safe online pharmacies in canada
canada online pharmacy real canadian pharmacy and canadian pharmacy reviews online canadian drugstore
Comparing choices for best…
Comparing choices for best dating sites works best with written criteria for how the user wants conversations to start and when off-platform contact feels appropriate. Apply the same questions to every option, especially around the steps between registration, profile completion, discovery, matching, messaging, and account closure. A transparent method makes it easier to compare options without confusing profile volume with compatibility or safety.
Instead of relying on…
Instead of relying on rankings for ai girlfriend simulator, define which devices, languages, accessibility settings, and notification controls are required. A small controlled test can reveal more about how the system explains moderation boundaries, refused requests, and changes to available features. A documented comparison allows the user to understand the full cost of regular use before purchasing a long subscription.
A structured comparison of…
A structured comparison of best ai girlfriend app should first address how important data deletion, chat export, account closure, and privacy documentation are. Useful evidence should include notification controls, device permissions, login security, and recovery options for account access. A transparent method makes it easier to compare platforms without assuming that more generated media means better conversation.
mexico pharmacy order online…
mexico pharmacy order online prescription: buy meds from mexico safely - farmacia pharmacy mexico delivery to usa
DarLink AI Review https:/…
DarLink AI Review https://darlink-ai.carrd.co a detailed guide to setting up your virtual character and testing your memory within 48 hours. We analyze the creation of a profile, individual communication settings, saving dialogue details and the ability of artificial intelligence to remember information.
To evaluate buy tiktok views…
To evaluate buy tiktok views and likes consistently, use the same brief describing the exact package scope and any difference between standard, gradual, instant, or geo-targeted delivery. The review becomes more reliable when it captures screenshots with timestamps, the order confirmation, payment reference, dashboard status, and support correspondence. This approach keeps the evaluation focused enough to close the review with a clear next action and no unsupported causal claim.
The phrase buy tiktok likes…
The phrase buy tiktok likes and views can represent different options, so clarify the decision rules for repeating, revising, rejecting, or ending the activity. A small controlled test can reveal more about the difference between delivery completion and any unrelated change in reach, sales, or follower growth. Consistent criteria make it possible to use the result as a bounded observation rather than a guaranteed growth strategy.
DarLink AI Review https:/…
DarLink AI Review https://darlink-ai.carrd.co a detailed guide to setting up your virtual character and testing your memory within 48 hours. We analyze the creation of a profile, individual communication settings, saving dialogue details and the ability of artificial intelligence to remember information.
A careful look at buy tiktok…
A careful look at buy tiktok likes should separate preferences from requirements by recording the decision rules for repeating, revising, rejecting, or ending the activity. Review the complete workflow for a fixed review schedule that prevents the team from selecting only a favorable screenshot. A transparent method makes it easier to review the creative context alongside the provider's operational delivery.
Comparing choices for buy…
Comparing choices for buy real tiktok views works best with written criteria for the criteria for repeating, changing, disputing, or ending the test. Useful evidence should include whether a dashboard clearly identifies the service, target, quantity, status, and support reference. The conclusion should understand which promises are written conditions and which are only marketing language.
Instead of relying on…
Instead of relying on rankings for buy tiktok likes, define who owns the account, who approves spending, and who records the result. Any shortlist should show clear differences in how unexpected prompts, account alerts, incorrect links, or unexplained charges trigger a stop condition. The comparison remains useful when it can identify whether another distribution or creative tactic better fits the objective.
DarLink AI Review https:/…
DarLink AI Review https://darlink-ai.carrd.co/ a detailed guide to setting up your virtual character and testing your memory within 48 hours. We analyze the creation of a profile, individual communication settings, saving dialogue details and the ability of artificial intelligence to remember information.
Research into buy tiktok…
Research into buy tiktok views is more useful when the user identifies the information the provider requests and whether any unnecessary account access is involved. Check the available documentation for current TikTok guidance and the account owner's decision about acceptable risk. The user can then handle a support request with exact references instead of a vague complaint.
Instead of relying on…
Instead of relying on rankings for music ai generator, define the importance of model transparency, version changes, generation history, and reproducibility. The comparison should also examine whether the user can regenerate one section without replacing parts of the track that already work. These records support a practical decision and help choose a plan based on realistic generation volume rather than an attractive introductory allowance.
The search for ai song…
The search for ai song generator becomes clearer after defining the degree of control needed over song length, intro, verse, chorus, bridge, outro, and transitions. Keep dated notes about the accuracy of non-English pronunciation, syllable timing, rhyme, and lyrical emphasis in the intended language. Any unresolved issue should remain visible before the user attempts to compare audio quality without letting one strong sample define the entire platform.
order antibiotics from…
order antibiotics from mexico: mexican pharmacy online us shipping - mexican farmacia
Нужны духи? топ-10 мужских…
Нужны духи? топ-10 мужских ароматов с удобным выбором ароматов для мужчин и женщин. Вниманию покупателей представлены свежие, цитрусовые, древесные, цветочные и восточные композиции. Сравните предложения магазинов и найдите парфюм, который соответствует вашим предпочтениям.
Нужны духи? как выбрать…
Нужны духи? как выбрать арабскую парфюмерию с удобным выбором ароматов для мужчин и женщин. Вниманию покупателей представлены свежие, цитрусовые, древесные, цветочные и восточные композиции. Сравните предложения магазинов и найдите парфюм, который соответствует вашим предпочтениям.
cipa canada online pharmacy…
cipa canada online pharmacy and canadian pharmacy king canadian pharmacy comparison
https://www.google.pl/url?q=https://canadexiarx.com top canadian pharmacy and http://dnp-malinovka.ru/user/ayesyhibih/?um_action=edit real canadian pharmacy
canadian online pharmacy online pharmacy canada or canada rx pharmacy canadian pharmacies shipping to usa
Pagination
Add new comment