一键导入
drupal-entity-api
Drupal Entity API — loading, creating, updating, and deleting entities using entity_type.manager. Node, User, Term, Media patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Drupal Entity API — loading, creating, updating, and deleting entities using entity_type.manager. Node, User, Term, Media patterns.
用 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-entity-api |
| description | Drupal Entity API — loading, creating, updating, and deleting entities using entity_type.manager. Node, User, Term, Media patterns. |
// Load a single node
$node = $this->entityTypeManager->getStorage('node')->load($nid);
// Load multiple nodes
$nodes = $this->entityTypeManager->getStorage('node')->loadMultiple([1, 2, 3]);
// Load by properties
$nodes = $this->entityTypeManager->getStorage('node')->loadByProperties([
'type' => 'article',
'status' => 1,
'uid' => $uid,
]);
// Load user
$user = $this->entityTypeManager->getStorage('user')->load($uid);
// Load term
$term = $this->entityTypeManager->getStorage('taxonomy_term')->load($tid);
// Load media
$media = $this->entityTypeManager->getStorage('media')->load($mid);
$query = $this->entityTypeManager->getStorage('node')->getQuery()
->accessCheck(TRUE)
->condition('type', 'article')
->condition('status', 1)
->condition('field_tags', $tid)
->sort('created', 'DESC')
->range(0, 10);
$nids = $query->execute();
$nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids);
// Create a node
$node = $this->entityTypeManager->getStorage('node')->create([
'type' => 'article',
'title' => 'My Article',
'status' => 1,
'uid' => $this->currentUser->id(),
'field_body' => [
'value' => 'Content here',
'format' => 'basic_html',
],
]);
$node->save();
// Create a taxonomy term
$term = $this->entityTypeManager->getStorage('taxonomy_term')->create([
'vid' => 'tags',
'name' => 'New Tag',
]);
$term->save();
$node = $this->entityTypeManager->getStorage('node')->load($nid);
if ($node instanceof NodeInterface) {
$node->set('title', 'Updated Title');
$node->set('field_body', ['value' => 'New content', 'format' => 'basic_html']);
$node->save();
}
$node = $this->entityTypeManager->getStorage('node')->load($nid);
if ($node) {
$node->delete();
}
// Delete multiple
$storage = $this->entityTypeManager->getStorage('node');
$nodes = $storage->loadMultiple($nids);
$storage->delete($nodes);
// Simple field
$title = $node->get('title')->value;
$status = $node->get('status')->value;
// Text with format
$body = $node->get('body')->value;
$format = $node->get('body')->format;
// Reference field
$tid = $node->get('field_tags')->target_id;
$term = $node->get('field_tags')->entity;
// Multi-value field
foreach ($node->get('field_images') as $item) {
$fid = $item->target_id;
$file = $item->entity;
}
// Check if field is empty
if (!$node->get('field_image')->isEmpty()) { ... }
// Always add access checks
$query->accessCheck(TRUE);
// Check entity access
if ($node->access('view', $account)) { ... }
if ($node->access('update', $account)) { ... }
public function __construct(
private readonly EntityTypeManagerInterface $entityTypeManager,
) {}