Creating Custom Content Types Programmatically in Drupal 10

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:

  1. A working Drupal 10 or 9 website.
  2. Basic knowledge of Drupal site building and module development.
  3. 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:

  1. In your Drupal installation, navigate to the sites/all/modules directory (or your preferred module location).
  2. Create a new directory for your custom module. Give it a unique and descriptive name, such as my_custom_content_type.
  3. 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:
  - node

This 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.

  1. Create a file named my_custom_content_type.module in your module directory.
  2. 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.

  1. 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

  1. In your Drupal admin interface, navigate to Extend (admin/modules) and enable your custom module, "My Custom Content Type Module."
  2. 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.

Share on social media

Comment

Permalink

An innovative AI generator naked ai free for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!

Permalink

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!

Permalink

An innovative AI generator naked ai app for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!

Permalink

An innovative AI generator naked ai app for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!

Permalink

An innovative AI generator naked ai free for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!

Permalink

An innovative AI generator naked ai for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!

Permalink

An innovative AI generator naked ai generator for removing clothing from photos. High-quality detail, complete privacy, and instant processing. Try it for free!

Permalink
Permalink
Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

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.

Permalink

Нужны духи? топ-10 мужских ароматов с удобным выбором ароматов для мужчин и женщин. Вниманию покупателей представлены свежие, цитрусовые, древесные, цветочные и восточные композиции. Сравните предложения магазинов и найдите парфюм, который соответствует вашим предпочтениям.

Permalink

Нужны духи? как выбрать арабскую парфюмерию с удобным выбором ароматов для мужчин и женщин. Вниманию покупателей представлены свежие, цитрусовые, древесные, цветочные и восточные композиции. Сравните предложения магазинов и найдите парфюм, который соответствует вашим предпочтениям.

Add new comment