Build full-stack Drupal modules with backend services and frontend JavaScript. Covers services, REST APIs, database schema, Vite builds, Drupal behaviors, and block plugins. Use when creating Drupal 10 modules that need both PHP services and JavaScript integration.
Complete technical patterns for building Drupal 10 modules with both backend services and frontend JavaScript integration.
Use this skill when you need to:
Trigger phrases:
File: src/Service/YourService.php
<?php
declare(strict_types=1);
namespace Drupal\your_module\Service;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Session\AccountProxyInterface;
use Psr\Log\LoggerInterface;
/**
* Your service description.
*
* @todo Add detailed service documentation.
*/
class YourService {
/**
* The database connection.
*/
protected readonly Connection $database;
/**
* The configuration factory.
*/
protected readonly ConfigFactoryInterface $configFactory;
/**
* The logger.
*/
protected readonly LoggerInterface $logger;
/**
* The current user.
*/
protected readonly AccountProxyInterface $currentUser;
/**
* Constructs a new YourService object.
*/
public function __construct(
Connection $database,
ConfigFactoryInterface $config_factory,
LoggerChannelFactoryInterface $logger_factory,
AccountProxyInterface $current_user
) {
$this->database = $database;
$this->configFactory = $config_factory;
$this->logger = $logger_factory->get('your_module');
$this->currentUser = $current_user;
}
/**
* Example method: Do something useful.
*
* @param string $input
* The input parameter.
*
* @return array
* The result.
*/
public function doSomething(string $input): array {
$this->logger->info('Processing input: @input', ['@input' => $input]);
// Your logic here
$result = ['processed' => TRUE, 'data' => $input];
return $result;
}
}
File: your_module.services.yml