Problem/Motivation

There is no documentation or specification about the valid character set or maximum length for a plugin ID.

The api.d.o topic just speaks of "a unique string identifier". (Which doesn't even explain in which domain it has to be unique.)

Proposed resolution

[a-zA-Z0-9_-]+
(alphanumeric, underscore, hyphen)

Remaining tasks

Decide if this is adequate
Document it!

User interface changes

N/A

API changes

Depends on if it is enforced or only documented

Data model changes

N/A

Comments

drunken monkey created an issue. See original summary.

jhodgdon’s picture

Component: documentation » plugin system
Assigned: Unassigned » tim.plunkett
Issue tags: +Needs subsystem maintainer review

Good question. Let's put this into the plugin system component for now to see if we can get an answer. For the moment assigning to tim.plunkett, one of the plugin system maintainers.

xano’s picture

The plugin system only required plugin IDs to be strings. However, you are advised to make sure all IDs are valid machine names (alphanumeric, plus underscores). Note that plugin IDs contain colons when you use core's derivative decorators. This means that such plugin IDs cannot be used as config IDs, for instance, as those are used as filenames and those cannot contain colons.

drunken monkey’s picture

Note that plugin IDs contain colons when you use core's derivative decorators.

I know, sorry, I didn't make that quite clear: I meant that colons would probably cause problems in normal, "underived" plugin IDs since they'd then be mistaken for derived ones.

Anyways, thanks for answering! So should we maybe make "alphanumeric plus underscores" a requirement? (Plus colons only for derived ones.) What exactly would or might break with other IDs? And, are IDs starting with numbers or underscores fine, too?

Also, if we want to document this, where should it be documented? In the api.d.o topic?

cilefen’s picture

Is this something we should throw an exception about in addition to documenting?

tim.plunkett’s picture

Yes, colons should only be in derivatives.
We could document this as matching the rules for function names, variables, and "other labels":

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Still following, just unassigning

drunken monkey’s picture

We currently have the problem in Facets and Search API that we want to create plugins (type A) based on plugins of a different type (type B). The "natural" way would be to use the plugin IDs from type B as the second part of the plugin IDs for type A. But if the plugins from type B are already derivatives, that would make the plugin IDs contain two colons.
Would that cause problems (if the base plugin ID doesn't contain any colon), or should that still be avoided?
In the latter case, does anyone know of a clever way to implement this without that risk?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

drunken monkey’s picture

I just noticed that the block plugins created by Views do not follow the normal machine name format, since they contain a dash (-) between view ID and display ID.
So, if we'd decide that plugin IDs need to be valid machine names (except for a single colon for derived ones), Views would violate that rule (currently).

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Version: 8.4.x-dev » 8.5.x-dev
Issue summary: View changes
Issue tags: -Needs subsystem maintainer review

Updating the IS with a concrete proposal

drunken monkey’s picture

Do we really want to allow uppercase characters? Seems that could potentially make problems with MySQL (which ignores case by default).
Identifiers are usually also forbidden from starting with a digit (or be digits-only) – could also be a problem.
Allowing dashes is unexpected, but I don't see why it would cause problems. (Could even open up possibilities for the problem I mention in #8: If we define display plugin IDs in the Search API as not allowing dashes, we can just replace colons with dashes when re-using them as derivative IDs in Facets. Not sure if that would be clear enough, but still.)
Finally, this would obviously just cover the base ID and derivative ID in the case of a derived plugin – we'd need to document this clearly (if people deal with plugins generically, they have to take into account that IDs can contain a single colon), but it of course makes sense.

My suggestion:
[a-z_][a-z_0-9-]*
I.e.:
- lowercase only
- has to start with letter or underscore

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cilefen’s picture

jayelless’s picture

The use of plugin id strings containing uppercase, spaces or special chars is causing an issue for ultimate_cron - see #2968661: Queue names can contain special characters.

jayelless’s picture

joachim’s picture

> [a-z_][a-z_0-9-]*

This allows hyphens AFAICT.

Are there any cases where a form ID is derived from a plugin ID? If that's the case, then a hyphen would break form alter hooks.

We also have quite a few plugins in core that would violate the lowercase rule, e.g.:

 * @Constraint(
 *   id = "BookOutline",
 *   label = @Translation("Book outline.", context = "Validation"),
 * )

AFAICT the plugins with uppercase IDs are all either Constraint or Archiver plugins.

We can't change plugin names because of BC, so we'd need to devise a way to allow some plugin managers to opt out of the ID format validation.

jayelless’s picture

There are plugins in some contrib modules that violate the "machine_name standards". For instance the SendGrid integration module has a queue worker with an id of "SendGridResendQueue". Also as a test case, I have created a queue worker with an id of "Testbed Queue: #1" which works perfectly well under the core queue subsystem.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chi’s picture

I propose the documentation also suggests prefixing the plugin ID with module machine name to avoid ID clashing.

drunken monkey’s picture

I propose the documentation also suggests prefixing the plugin ID with module machine name to avoid ID clashing.

Ah, yes, definitely!
This should really just be defined for any global identifiers, but apparently we currently list all types individually.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pwolanin’s picture

Looks like a bit of a stale issue?

We already use "." in custom code, and I think some other chars like "+", "|", "/", etc. could be semantically useful, especially for building up combined IDs.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dydave’s picture

Just wanted to mention the use of the slash character '/' in plugin IDs can cause issues when rendering URLs with the plugin ID, see related issue #3426088: InvalidParameterException: Parameter "queueName" for route "queue_ui.inspect" must match "[^/]++" ("queue_unique/mymodule_entity_update" given) to generate a corresponding URL, where naming a queue with the plugin ID prefixed with 'queue_unique/' ends up breaking contrib module Queue UI when it tries generating path with path: admin/config/system/queue-ui/inspect/{queueName}.

The suggestion at #15 certainly makes sense and would help preventing these types of issues.

Thanks in advance for your help and feedbacks !

mxr576’s picture

Issue summary: View changes

What about the maximum length of a plugin id?

mxr576’s picture

IMO it would be awesome if the plugin class's FQCN could be used as a plugin id because the id is just one additional magic string that you have to remember or should not forget updating if you change it in source. But that is not possible currently, the idea falling apart here and there...

mxr576’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.