drupal-fields について
drupal-fieldsは、Drupal開発者向けのフィールド開発スキルです。Drushによるフィールド管理、設定のエクスポート、カスタムプラグインの生成、値の取得を扱います。
主な機能
- 01Drushでのフィールド作成
- 02フィールドの一覧表示と削除
- 03CLI変更後の設定エクスポート
- 04フィールド型・フォーマッター・ウィジェットの生成
- 05単一値・参照・複数値の取得
活用シーン
- 01コンテンツタイプへのフィールド追加
- 02既存フィールドの確認や削除
- 03カスタムフィールドプラグインの実装
- 04PHPでのフィールドデータ取得
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ edutrul/ drupal-ai --skill drupal-fieldsインストール後、Claude Code で/drupal-fieldsを入力して読み込まれたか確認します。
同梱ファイルREADME.md
詳細
Drupal フィールド
フィールドの作成(Drush — CLI を優先)
フィールド設定ファイルを手動で作成するのではなく、常に drush field:create を使用してください。
# Interactive (recommended first time)
drush field:create
# Non-interactive
drush field:create node article \
--field-name=field_subtitle \
--field-label="Subtitle" \
--field-type=string \
--field-widget=string_textfield \
--is-required=0 \
--cardinality=1
# Reference field
drush field:create node article \
--field-name=field_tags \
--field-label="Tags" \
--field-type=entity_reference \
--field-widget=entity_reference_autocomplete \
--cardinality=-1 \
--target-type=taxonomy_term
# Image field
drush field:create node article \
--field-name=field_image \
--field-label="Image" \
--field-type=image \
--field-widget=image_image \
--is-required=0 \
--cardinality=1
フィールドの管理
# List all fields on a content type
drush field:info node article
# Delete a field
drush field:delete node.article.field_subtitle
# Discover available types/widgets/formatters
drush field:types
drush field:widgets
drush field:formatters
フィールド作成後のエクスポート
# Always export config after CLI changes
drush config:export -y
カスタムフィールドタイプ(プラグイン)
drush generate plugin:field:type
drush generate plugin:field:formatter
drush generate plugin:field:widget
コードでのフィールド値へのアクセス
// Single value
$value = $entity->get('field_name')->value;
// Entity reference
$referenced = $entity->get('field_ref')->entity;
// Multi-value
foreach ($entity->get('field_multi') as $item) {
$value = $item->value;
}
コメント
Markdown 対応