Updated: Comment #N

Problem/Motivation

In #2195753: Changes to config entities that use plugins are not propagated to the plugins, I theorized that traits would serve us well.
Well, now that we have 5.4, I tried it, and it doesn't work at all.

First, I did not know that classes cannot redeclare a property that comes from a trait, which is pretty useless:
http://us3.php.net/language.oop5.traits#language.oop5.traits.properties

I intended to have a default $pluginConfigKey property with a sane value, and let the classes override it if needed. That way we could rely on the property in code...
But that's a fatal!

The second thing I wanted to do was make getPluginBag() protected. But @alexpott said something in IRC about this interface being very useful for finding config entity dependencies, so we want to leave this public.

Proposed resolution

Remove all of the hopeful comments about making this a trait.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Active » Needs review
FileSize
2.33 KB
tim.plunkett’s picture

Assigned: tim.plunkett » alexpott

If I misrepresented @alexpott here, and we don't need getPluginBag() to be public, then we can make $pluginConfigKey into a protected getter and still use a trait.

alexpott’s picture

Assigned: alexpott » tim.plunkett
Status: Needs review » Needs work

I don't think we need getPluginBag() to be public as its usefulness in calculating config entity dependencies is when you call it from calculateDependencies() see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Config%21... - so it is always the entity class calling it.

tim.plunkett’s picture

So there are three problems with class_uses():
1) It only works if the class checked uses the trait, not any parent classes (http://www.php.net/manual/en/function.class-uses.php)
2) PHPUnit doesn't support it (https://github.com/sebastianbergmann/phpunit/issues/767#issuecomment-119...)
3) Apparently class_uses() violates the Flattening Property https://wiki.php.net/rfc/horizontalreuse#the_flattening_property

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Needs work » Needs review
FileSize
2.29 KB

I have no idea what else to do. Just a reroll.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Yeah traits do actually suck in reality. Glad that everyone planned them as a tool to solve all the problems.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed da91e5a and pushed to 8.x. Thanks!

  • Commit da91e5a on 8.x by alexpott:
    Issue #2208015 by tim.plunkett: Remove "convert to trait" comments about...

Status: Fixed » Closed (fixed)

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