Problem/Motivation

Instead of plain PHP, we should use Drupal plugins system.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

alex.skrypnyk created an issue. See original summary.

  • alex.skrypnyk committed 165e20a7 on 2.x
    feat: #3556829 2.x Convert generators to plugins
    
    By: alex.skrypnyk
    
alex.skrypnyk’s picture

Status: Active » Fixed

By: alex.skrypnyk

Summary

This pull request converts the generated content system from a hook-based architecture to a Drupal plugin-based system (#3556829). Generators are now discovered as PHP classes with a #[GeneratedContent] attribute in src/Plugin/GeneratedContent/ directories.

Key Changes

Core Infrastructure

  • New plugin system: Introduces GeneratedContent attribute class for marking generator plugins and GeneratedContentPluginManager for discovering and managing plugins.
  • Plugin interface and base class: Adds GeneratedContentPluginInterface and GeneratedContentPluginBase to standardize plugin implementations with methods for generate(), getEntityType(), getBundle(), getWeight(), and getTracking().
  • Service registration: Registers plugin.manager.generated_content service in generated_content.services.yml.
  • Repository refactoring: Updates GeneratedContentRepository to use the plugin manager instead of scanning module hooks and loading .inc files. Removes ModuleHandlerInterface and EntityTypeBundleInfoInterface dependencies.
  • Form updates: Updates GeneratedContentForm to guide users toward the plugin-based approach.

Example Module Migrations

All hook-based generators in example modules (generated_content_example1 and generated_content_example2) are converted to plugin classes:

Example 1:

  • Removed hook implementations: generated_content_create_file_file, generated_content_create_media_image, generated_content_create_taxonomy_term_tags, generated_content_create_user_user
  • Added plugins: File, MediaImage, TaxonomyTermTags, User

Example 2:

  • Removed hook implementations: generated_content_create_node_article, generated_content_create_node_page (with variations), generated_content_create_media_document, generated_content_create_taxonomy_term_tags
  • Added plugins: NodeArticle, NodePage (with variation support), MediaDocument, TaxonomyTermTags

Removed Files

All procedural hook files have been deleted:

  • generated_content.api.php (main hook documentation)
  • Multiple .inc files from example modules defining weight, tracking, and creation hooks

Runtime Plugin Alteration

Support for hook_generated_content_plugin_alter() is now documented, enabling runtime modification of plugin definitions.

Migration Impact

This change represents a significant architectural shift from hook-based to plugin-based content generation, aligning with modern Drupal practices. All existing generators must be refactored as plugin classes to continue functioning.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.