Problem/Motivation

The ContextAwarePluginTrait defines the following (source):

  /**
   * {@inheritdoc}
   */
  abstract protected function getPluginDefinition();

But the PluginInspectionInterface defines this as a public function (source):

  /**
   * Gets the definition of the plugin implementation.
   *
   * @return array
   *   The plugin definition, as returned by the discovery object used by the
   *   plugin manager.
   */
  public function getPluginDefinition();

My IDE highlighted this error when creating a plugin that extends the ConditionPluginBase class (which uses the ContextAwarePluginTrait). Changing the function visibility to be public clears the error, but is there a special reason this function was private? Maybe because it was abstract inside the trait?

I tried to search for an existing issue (with this search) but didn't find anything; it seems like this trait was only added recently via: #2273381: Convert ContextAwarePluginBase to traits

In that issue I didn't see any discussion around the visibility of the getPluginDefinition method - it seems like it was recommended as a abstract protected getPluginDefinition in this comment, and that was it: https://www.drupal.org/project/drupal/issues/2273381#comment-13712658

Steps to reproduce

N/A

Proposed resolution

Change the abstract function visibility from protected to public.

Remaining tasks

N/A - I don't think this would be breaking?

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3229714

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

paul121 created an issue. See original summary.

dubs’s picture

+1 to get this added in. The visibility isn't correct and it causes problems further down the chain for some plugins

paul121’s picture

Status: Active » Needs review
longwave’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense to me, I don't see an issue with it being public.

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.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Given the interface this has to be public in anything that implements the trait so let's do this.

Committed and pushed c636d19ce48 to 10.0.x and b4fc8c9be9c to 9.4.x and ed3c0ea4e32 to 9.3.x. Thanks!

  • alexpott committed c636d19 on 10.0.x
    Issue #3229714 by paul121: Correct visibility of getPluginDefinition...

  • alexpott committed b4fc8c9 on 9.4.x
    Issue #3229714 by paul121: Correct visibility of getPluginDefinition...

  • alexpott committed ed3c0ea on 9.3.x
    Issue #3229714 by paul121: Correct visibility of getPluginDefinition...

Status: Fixed » Closed (fixed)

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