Entity Usage

Track usage of entities referenced by other entities in Drupal, showing where content is being used across your site.

entity_usage
53,600 sites
156
drupal.org

概要

Entity Usageは、Drupalにおけるエンティティ間の関係を追跡・表示する強力なモジュールです。様々なフィールドタイプや埋め込み方法を通じてエンティティが互いにどのように参照しているかを監視し、各エンティティがどこで使用されているかを示すレポートを提供します。

このモジュールは、ソースエンティティが作成、更新、削除されたときに自動的に追跡を行い、すべてのエンティティ関係の正確な記録を維持します。ユーザーはエンティティページで「Usage」タブを表示して、現在のエンティティを参照している他のエンティティを確認できます。参照元のエンティティタイプ、フィールド名、言語、公開ステータス、リビジョンコンテキストに関する情報が表示されます。

Entity Usageは、エンティティ参照フィールド、リンクフィールド、テキストフィールド内のHTMLリンク、メディア埋め込み、Layout Builderコンポーネント、およびEntity Embed、LinkIt、Block Field、Dynamic Entity Referenceなどのコントリビュートモジュールとの連携を含む、複数の追跡方法をサポートしています。サイト管理者は、ソースおよびターゲットとして追跡するエンティティタイプ、特定の追跡プラグインの有効化/無効化、他の場所で参照されているエンティティを編集または削除する際に表示される警告メッセージを設定できます。

Features

  • entity_reference、entity_reference_revisions、file、image、webformフィールドを通じたエンティティ間の関係を追跡
  • 内部エンティティURLを指すLinkフィールド経由で参照されるエンティティを追跡
  • エンティティURLを指すフォーマット済みテキストフィールド内の標準HTMLリンクを検出・追跡
  • WYSIWYGエディターでDrupal Coreのメディア埋め込みフィルターを使用して埋め込まれたメディアエンティティを追跡
  • Entity Embedコントリビュートモジュールを使用して埋め込まれたエンティティを追跡
  • WYSIWYGエディターでLinkItコントリビュートモジュールを使用してリンクされたエンティティを追跡
  • CKEditor Image ウィジェット経由で埋め込まれたファイルエンティティを追跡
  • インラインコンテンツブロック、再利用可能ブロック、Entity Browser Block選択を含むLayout Builderレイアウトで参照されるエンティティを追跡
  • block_fieldフィールドで参照されるブロックを追跡するBlock Fieldモジュールをサポート
  • 複数のエンティティタイプへの参照を追跡するDynamic Entity Referenceモジュールをサポート
  • そのエンティティへのすべての参照を表示するエンティティのcanonicalまたは編集ページでの設定可能な「Usage」タブ(ローカルタスク)を提供
  • エンティティが他の場所でアクティブな参照を持っている場合、編集フォームに警告メッセージを表示
  • エンティティが他のコンテンツで使用されている場合、削除フォームに警告メッセージを表示
  • 既存コンテンツのすべての使用統計を再生成するバッチ更新ツール
  • 使用統計のバッチ再作成用Drushコマンド
  • 追跡対象を制御するための設定可能なソースおよびターゲットエンティティタイプフィルタリング
  • 設定可能フィールドに加えてベースフィールドの追跡をサポート
  • サイトを指す絶対URLを追跡するためのドメイン設定
  • デフォルト、保留中、古いリビジョンでの使用状況を表示するリビジョン対応追跡
  • 言語情報を表示する翻訳対応追跡
  • ゴミ箱に入れられたソースエンティティを適切に表示するTrashモジュールとの連携
  • カスタム追跡方法を追加できる拡張可能なプラグインシステム

Use Cases

Preventing broken references when deleting content

Enable delete warning messages for content types like Media, Taxonomy Terms, or custom entities. When an editor tries to delete an entity, they'll see a warning showing where it's currently being used, helping prevent broken references across the site.

Auditing media usage across the site

Use the Usage tab on media entities to see everywhere a particular image, video, or document is being used. This helps identify orphaned media files, understand content dependencies, and plan content updates that affect multiple pages.

Managing content dependencies during migrations

Before migrating or restructuring content, use Entity Usage to understand relationship dependencies. This helps plan migration order and identify content that needs special handling due to cross-references.

Tracking where reusable content blocks appear

For reusable block_content entities used across multiple pages via Layout Builder or Block Field, the Usage tab shows every page where the block appears. This is valuable when updating shared content.

Finding all pages linking to a specific internal page

The HTML link tracking plugin detects standard links in WYSIWYG content. Combined with the Usage tab, editors can find every page that links to a specific piece of content, useful for link audits and content restructuring.

Coordinating content updates across translations

Usage listings show the language context of references. When updating multilingual content, editors can see which translations reference an entity and coordinate updates accordingly.

Identifying content referenced only in old revisions

The 'Used in' column distinguishes between default revisions, pending drafts, and old revisions. This helps identify when content is no longer actively used but may still exist in revision history.

Tips

  • Run the batch update after initial installation to populate usage data for existing content
  • Enable warning messages gradually, starting with the most critical content types to avoid overwhelming editors
  • Configure site domains if your content contains absolute URLs - this enables tracking for links that include the full domain
  • Use the Drush command for batch updates on large sites to avoid browser timeouts
  • The module tracks all revisions and translations - usage data reflects the complete history of references
  • Custom tracking plugins can be created by implementing EntityUsageTrackInterface for specialized reference types
  • Usage data is automatically cleaned up when source or target entities are deleted
  • The hook_entity_usage_block_tracking hook allows fine-grained control over what gets tracked

Technical Details

Admin Pages 3
Entity Usage Settings /admin/config/entity-usage/settings

Configure entity usage tracking settings including which entity types to track, which tracking plugins to enable, and display options for usage information.

Batch Update /admin/config/entity-usage/batch-update

Delete and regenerate all entity usage statistics. Use this after initial installation or when tracking configuration has changed significantly.

Entity usage information for [Entity Label] /admin/content/entity-usage/{entity_type}/{entity_id}

Displays a table of all entities that reference the specified target entity. Shows the referencing entity, its type and bundle, language, field name, publication status, and revision context (default, pending, or old revision).

権限 3
Access entity usage statistics

Users with this permission will be able to see statistics of entity usage including viewing the Usage tab on entities and the usage list pages.

Access the form to launch batch updates on existing entities

Users with this permission will be able to reset/relaunch the statistics counts on all existing entities in the system. This is a restricted permission as batch operations can be resource-intensive.

Administer Entity Usage

Users with this permission will be able to administer the Entity usage module settings including configuring which entity types and plugins to track. This is a restricted permission.

Hooks 1
hook_entity_usage_block_tracking

Allows modules to block specific usage tracking records from being written to the database. Return TRUE to prevent the record from being saved.

Drush Commands 1
drush entity-usage:recreate

Recreate all entity usage statistics by processing all configured source entity types and regenerating their usage records.

Troubleshooting 7
Usage tab doesn't appear on entity pages

Navigate to Entity Usage Settings and ensure the entity type is selected under 'Enabled local tasks'. After saving, routes will be rebuilt. Clear caches if the tab still doesn't appear.

Existing content doesn't show usage information

Entity Usage only tracks changes made after the module is installed. Run the batch update at /admin/config/entity-usage/batch-update to scan all existing content and populate usage data.

Some relationship types aren't being tracked

Check Entity Usage Settings to ensure the appropriate tracking plugin is enabled. Also verify that both the source and target entity types are enabled in the respective configuration sections.

Absolute URLs in content aren't being tracked

Configure the 'Domains for this website' setting with all domains where your site is accessible. Include variations like www and non-www versions, and any staging domains.

Usage shows references that no longer exist in content

The usage database may be out of sync. Run the batch update with existing records deleted to regenerate fresh usage data from current content.

Warning messages don't appear on edit/delete forms

Ensure the entity type is enabled under 'Warning message on edit form' or 'Warning message on delete form' in settings. The entity must also be enabled as a target entity type.

Performance issues with large amounts of content

The batch update process is optimized for large sites but may take time. Run via Drush (drush entity-usage:recreate) for better performance and to avoid browser timeouts.