원클릭으로
drupal-state
Drupal State API — storing and retrieving runtime state that persists across requests but is not configuration.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Drupal State API — storing and retrieving runtime state that persists across requests but is not configuration.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
HTMX in Drupal 11.3+ core — the Htmx PHP fluent builder, dynamic forms with swapOob, partial routes with _htmx_route, response headers, and Drupal.behaviors integration. Use when building interactive UI without full-page reloads using Drupal's native HTMX support.
DDEV local development expertise. Use when working with DDEV projects, containers, configuration, or troubleshooting DDEV environments.
Custom Docker Compose local development patterns. Use when working with Docker-based local environments, container configuration, or troubleshooting Docker setups.
Drupal access control — permissions.yml, access callbacks, AccessResult, custom access checkers, and entity access.
Drupal Cache API — cache tags, contexts, max-age, cache bins, invalidation, and adding cache metadata to render arrays.
Drupal Composer management — requiring modules, updates, patches via composer-patches, and version constraints.
| name | drupal-state |
| description | Drupal State API — storing and retrieving runtime state that persists across requests but is not configuration. |
State is for runtime data that should persist across requests but is NOT configuration. Use Config for user-managed settings. Use State for internal operational data (last cron run, migration status, etc.).
use Drupal\Core\State\StateInterface;
// Inject
public function __construct(
private readonly StateInterface $state,
) {}
// Get
$value = $this->state->get('my_module.last_run');
$value = $this->state->get('my_module.last_run', $default_value);
// Set
$this->state->set('my_module.last_run', \Drupal::time()->getRequestTime());
// Delete
$this->state->delete('my_module.last_run');
// Get multiple
$values = $this->state->getMultiple(['key1', 'key2']);
// Set multiple
$this->state->setMultiple([
'my_module.status' => 'active',
'my_module.count' => 42,
]);
// Delete multiple
$this->state->deleteMultiple(['key1', 'key2']);
Use a namespaced key: module_name.key_name
// Good
$this->state->get('my_module.last_import_time');
$this->state->get('my_module.processed_count');
// Bad
$this->state->get('last_import'); // Not namespaced
| Storage | Use for | Exportable |
|---|---|---|
| State | Runtime operational data (last run times, counters, flags) | No |
| Config | User-managed settings, site configuration | Yes (via cex/cim) |
| Cache | Expensive computed data, invalidated on change | No (temporary) |
| UserData | Per-user preferences/data | No |
// Track last cron run
$this->state->set('my_module.cron_last', \Drupal::time()->getRequestTime());
// Feature flag (internal)
$isEnabled = $this->state->get('my_module.feature_enabled', FALSE);
// Track migration progress
$this->state->set('my_module.migration_offset', $offset);
// Store external API token (not sensitive — use KeyModule for secrets)
$this->state->set('my_module.api_token_expires', $expires);
# Get
drush state:get my_module.last_run
# Set
drush state:set my_module.feature_enabled 1
# Delete
drush state:del my_module.last_run
state