Skip to content

extension create plugin-class generates or updates the Shopware plugin entry class #1291

Description

User story

As a plugin developer adding lifecycle behavior to an existing Shopware plugin, I want the plugin entry class and lifecycle hooks generated correctly, so that the plugin remains valid and discoverable.

Problem

Shopware plugins do not use a conventional Bootstrap.php. The plugin entry class is normally src/<PluginName>.php. It must:

  • extend Shopware\Core\Framework\Plugin
  • use the correct namespace
  • match Composer PSR-4 autoloading
  • be registered under extra.shopware-plugin-class
  • use the correct context types for lifecycle hooks

The generator must create a missing class or safely add missing lifecycle methods to an existing class without overwriting existing logic.

Example

shopware-cli extension create plugin-class \
  --hooks install,activate,deactivate,update,uninstall

Possible updated files:

src/AcmePlugin.php
composer.json

Example generated class:

<?php declare(strict_types=1);

namespace Acme\Plugin;

use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;

class AcmePlugin extends Plugin
{
    public function activate(ActivateContext $activateContext): void
    {
    }

    public function deactivate(DeactivateContext $deactivateContext): void
    {
    }

    public function update(UpdateContext $updateContext): void
    {
    }
}

Out of scope

  • implementing plugin-specific lifecycle behavior
  • executing plugin installation or activation
  • generating migrations or other plugin components

Why it matters

The value is keeping the plugin class, lifecycle signatures, file path, namespace, and Composer registration consistent when modifying an existing plugin.

Acceptance criteria

  • Provides extension create plugin-class
  • Does not generate Bootstrap.php
  • Locates the plugin class through extra.shopware-plugin-class
  • Creates the class at the path resolved from extra.shopware-plugin-class and composer.json autoload.psr-4; it does not hard-code src/<PluginName>.php.
  • Generates the correct namespace and class name
  • Extends Shopware\Core\Framework\Plugin
  • Supports install, postInstall, update, postUpdate, activate, deactivate, and uninstall. A generated uninstall() calls parent::uninstall() and returns without deleting data when UninstallContext::keepUserData() is true.
  • Uses the correct Shopware context class for each lifecycle method
  • Generates only the lifecycle hooks requested through --hooks
  • Adds missing lifecycle methods to an existing plugin class
  • Does not duplicate or overwrite existing lifecycle methods
  • Adds missing imports without duplicating existing imports
  • Registers the generated class under extra.shopware-plugin-class
  • Verifies that the class matches Composer PSR-4 autoloading
  • Does not modify unrelated Composer configuration
  • Detects file, class, and Composer-registration conflicts
  • Performs validation before writing files
  • Re-running the command is safe and predictable
  • Generated code passes shopware-cli extension validate

Readiness checklist

  • Acceptance criteria are clearly defined.
  • Backward compatibility impact addressed.
  • Documentation written.
  • Tests added or adjusted accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Story.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions