Problem/Motivation
I think it's largely gonna be a convenience interface for working with the switches. Most plugins have a Plugin Manager class that might be pretty similar, but since these are created as config entities they don't really create one since they use the Entity Type Manager instead.
So basically we'll want to have a class that's going to handle some of that for us and will likely grow over time to ease the DX of checking and working with the switches. That'll need to inject the EntityTypeManager for sure and that'll handle some of the interfacing logic for loading and checking statuses on a switch entity.
Proposed resolution
Remaining tasks
class SwitchManagerInterface {
/**
* Loads a switch instance.
*
* @param string $switch_id
* The switch machine name.
*
* @return SwitchEntity
* The loaded and configured switch entity.
*/
public function getSwitch($switch_id);
/**
* Returns if a switch is enabled.
*
* @param string $switch_id
* The switch machine name.
*
* @return bool
* The activation status for the specified switch entity.
*/
public function isEnabled($switch_id);
}
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 2996521-8.patch | 4.47 KB | robpowell |
Comments
Comment #2
robpowellAfter working with Stephen, we came up with the attached solution. We did end up changing the method name from getValue() to get getActivationStatus() to make it more clear to developers what the method is doing.
Comment #3
robpowellComment #4
robpowellmade an error on service declaration and saved files in wrong directory. This patch fixes both of those issues.
Comment #6
sluceroThe work in #2996521-4: Implement a switch manager service to simplify and consolidate switch value checking looks good. I've added some coding style revisions, but running this all locally everything seems to be working at this point.
Remaining Items
SwitchEntity::getActivationStatus()Comment #7
robpowellCleaned up todos. Currently
$condition_value = $condition_plugin->execute();is working but may need to dig deeper inevaluate()is needed.Left todo about determine and/or but for now, I think we should prioritize or logic only as MVP.
Remaining Steps
Comment #8
robpowellslack convo with @slucero,
Comment #9
sluceroI've committed the patch from #8 to get us closer to a usable module. Nice work @robpowell!
Remaining steps on this ticket:
Implement automated tests for this functionality
Comment #11
sluceroThis has been merged into the
8.x-1.xbranch and is ready for use. I've tagged the issue with "Needs tests" so it can be found later for implementing automated tests and I'll close out the issue for now.