Create a way to declare a plugin as deprecated

Created on 11 March 2019, almost 6 years ago
Updated 19 February 2024, 10 months ago

Problem/Motivation

This issue was originally created with the migration yml plugins in mind, it has been expanded to include all plugins. See #39. πŸ“Œ Create a way to declare a plugin as deprecated Needs work

Migrations are plugins and plugins are covered by the core BC policies, specifically :

Particular plugins, whether class based or yaml based, should not be considered part of the public API. References to plugin IDs and settings in default configuration can be relied upon however.

This means that in order to remove migration ymls from core, we must first deprecate them, and then remove them in the next major version. We currently have no means of marking migration ymls as deprecated nor triggering a deprecation error if they are used. This came up for the first time in #3022401: Remove useless config action.settings.recursion_limit β†’ where it was determined that the action_settings migration was no longer needed. The migration was set to a null destination to render it useless but there is currently no mechanism to declare it deprecated and scheduled for removal in Drupal 9.

We are now faced with the prospect of deprecating all the Drupal 6 migration for removal to a contrib project, and we have no means of marking them for removal in D9 either.

Proposed resolution

Add a Trait for checking the deprecation status of a plugin.
Indicate deprecation by the property 'deprecation_message' for a plugin defined by an array or 'deprecationMessage' for a plugin with an object definition. Adding a plugin flag was considered but was deemed redundant, the presence or absence of the message is sufficient.
Make it so other plugin systems in contrib can use this to deprecate as well.

Remaining tasks

Identify a list of relevant places that all need to be updated and create follow-up issues for that.
Update deprecation policy

User interface changes

none

API changes

A means to declare a migration as deprecated and trigger an error will be added

Data model changes

None

Release notes snippet

Core migrations can now declare themselves deprecated

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
PluginΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mikelutz Michigan, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Skimmed.

    But seems to be a failure in the MR 2821 for D10.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡«πŸ‡·France andypost

    rebased, failure looks unrelated

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This seems like a big change.

    The 2 open threads seem to be resolved as @quietone changed to "some deprecation message"

    The two remaining tasks

    Identify a list of relevant places that all need to be updated and create follow-up issues for that.
    Update deprecation policy

    Have those been completed?

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    For the 2 remaining tasks if they can be identified.

  • heddn Nicaragua

    We have some old layouts (in my_module.layouts.yml) that we want to deprecate and use a more general use case layout instead. It would be nice to make the IS more explicit that this will cover those yaml plugins as well.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    The CR has an example of deprecating a YAML plugin.

    But the CR leaves a lot unsaid and is confusing in other ways:

    > Methods are added to check for the deprecation when a plugin is constructed, to determine if a plugin is deprecated and to get the deprecation messaged.

    Whose responsibility is it to check for a plugin being deprecated? Will core's plugin managers take care of checking their plugins, or is it up to the code that gets a plugin instance?

  • Merge request !6074Resolve #3039240 "11.0 plugin deprecation" β†’ (Open) created by andypost
  • Pipeline finished with Failed
    12 months ago
    Total: 198s
    #73853
  • Status changed to Needs review 12 months ago
  • πŸ‡«πŸ‡·France andypost

    Created new MR for meaningful 7 commits against 11.x branch by cherry-picking and fixed PHP 8.3 compatibility in test

    ATM mostly migration plugins awaiting this deprecation
    Also attributes conversion may need it πŸ“Œ Triggering deprecations for plugins using annotations when core plugin type has been converted to attributes Needs work

    RE #151

    at least 2 blocked
    - πŸ“Œ Deprecate tracker migration Postponed
    - #3209220: Deprecate and remove action settings migration β†’

    updates has policy issue #2922451: [policy no patch] Make it possible to mark plugins as deprecated β†’

    PS: probably makes sense to file follow-up to introduce #Deprecated attribute like https://wiki.php.net/rfc/deprecated_attribute but for classes

  • Pipeline finished with Success
    12 months ago
    #73919
  • πŸ‡«πŸ‡·France andypost

    Attempt to use the current code for migration https://git.drupalcode.org/project/drupal/-/merge_requests/6075

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    smustgrave β†’ changed the visibility of the branch 9.3.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    smustgrave β†’ changed the visibility of the branch 3039240-create-a-way to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    smustgrave β†’ changed the visibility of the branch 3039240-plugin_deprecation to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    smustgrave β†’ changed the visibility of the branch 3039240-9.5-plugin_deprecation to hidden.

  • Status changed to Needs work 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Left some small comments.

    Hid the old branches for clarity.

  • Pipeline finished with Skipped
    11 months ago
    #92260
  • Pipeline finished with Skipped
    11 months ago
    #92261
  • Status changed to Needs review 11 months ago
  • πŸ‡«πŸ‡·France andypost

    rebased and addressed feedback

  • Pipeline finished with Failed
    11 months ago
    Total: 559s
    #92262
  • Pipeline finished with Success
    11 months ago
    Total: 929s
    #92266
  • Status changed to RTBC 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Feedback appears to be addressed! Thanks!

  • Status changed to Needs work 10 months ago
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    This seems to only add support for annotations and it relies on undocumented, undefined annotation properties to do so.

    We need to make sure this works on attributes as well, which in its current state, I believe it does not, because for example the just committed Mail attribute class in πŸ“Œ Convert Mail plugin discovery to attributes Fixed has a fixed, hardcoded set of properties defined in its constructor and it is not possible to just pass in additional stuff the way this expects it to.

    I think we need to do either or both of:

    a) Standardize on using ...$var to pass all extra constructor arguments through to the parent. See for example ConfigEntityBase in πŸ“Œ Convert entity type discovery to PHP attributes Needs review , so that the attribute base class can introduce and define the deprecated_message property and it works an all child classes too.
    b) Support an explicit additional key, which is considered here in the trait in the parent class, so that extra stuff can be put there. We discussed that a bit in the original issue but postponed its introduction on having use cases for it, more or less defining that it would be done for specific plugin types that are likely to be extended.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    I agree with #166. While PluginDefinition declares AllowDynamicProperties we should not be relying on that for deprecations and should be introducing specific properties, and I think AttributeBase and AnnotationBase also need properties and setters adding to match.

    To me option A from #166 seems simpler, as it means we have to explicitly declare all our properties and we will not be tempted just to dump extra keys into the "additional" property unless absolutely necessary (e.g. in the case of entity types, at least to start with).

    I also tried prototyping a separate attribute, e.g.

    #[Mail(
      id: 'php_mail',
      label: new TranslatableMarkup('Default PHP Mailer'),
      description: new TranslatableMarkup("Sends the message as plain text, using PHP's native mail() function."),
    )]
    #[Deprecated('php_mail is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. Use the symfony_mailer plugin instead.')]
    

    but this doesn't really seem to gain us much - static analysis could find all deprecated things more easily if they all shared one attribute, but it complicates discovery as we have to check the second attribute and doesn't map well to YAML plugin definitions.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Is this going to be extensible by specific plugin types?

    For example, in the menu system, we need to be able to not just say plugin 'foo' is deprecated, but to use plugin 'bar' *instead*.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    @joachim in a way that needs to be understood by code and handled automatically, or only in a message to be read by humans?

  • πŸ‡¬πŸ‡§United Kingdom joachim

    > In a way that needs to be understood by code and handled automatically, or only in a message to be read by humans?

    By code.

    Suppose node module defines a menu link 'foo'. It wants to replace that with 'bar'.

    Contrib and custom code declare their own menu link items and say 'parent: foo' because they want to place their pages within Node module's admin UI.

    The menu system needs to be able to go 'Oh, I'm going to use 'bar' as a parent for that item instead because 'foo' is deprecated'.

    The use case is πŸ“Œ add an entity Links handler, to provide menu links/tasks/actions for entity types Needs work , where we need to deprecate hardcoded menu links/tasks/actions and replace then with automatically-created ones.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    In services this can be done with aliases; you create the new service and alias the old service name to it. Aliases can be deprecated too. Do we need this concept in plugins too?

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    A specific plugin system can always define additional keys on top of this, like a replaced_by or something. For most other plugins that's likely not needed or more complex, as plugins usually have configuration and the configuration of the replacement might not apply 1:1 and so on. So I'm not sure if that we need to build this into the base functionality.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    The more I think about it the more I wonder what is a plugin manager, if not much more than a service container/locator that only contains a subset of services that conform to a specific interface?

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    @longwave: Plugins aren't (single-instance) services. Every node you load is a plugin object, so are fields and blocks and so on.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    > A specific plugin system can always define additional keys on top of this, like a replaced_by or something. For most other plugins that's likely not needed or more complex

    Agreed - this is not going to be needed for most plugin types. I just wanted to make sure it'll be possible to add that on top of what's being done here. This issue is the last blocker to the entity links handler issue :)

  • πŸ‡«πŸ‡·France andypost

    Maybe better to address Attribute and "attribution-discovery" deprecations in follow-up as ATM core needs deprecation for annotation discovery

    Additionally to #167 there's PHP RFC for the #[Deprecated] attribute which has stuck
    - https://github.com/php/php-src/pull/11293
    - https://wiki.php.net/rfc/deprecated_attribute

    But PhpStorm has implementation which has growing adoption
    - https://packagist.org/packages/jetbrains/phpstorm-attributes/stats
    - https://github.com/JetBrains/phpstorm-attributes

Production build 0.71.5 2024