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

Comments

robpowell created an issue. See original summary.

robpowell’s picture

After 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.

robpowell’s picture

Status: Active » Needs review
robpowell’s picture

StatusFileSize
new3.68 KB
new913 bytes

made an error on service declaration and saved files in wrong directory. This patch fixes both of those issues.

  • slucero committed c19d9a6 on 2996521--switch-manager
    Issue #2996521: Apply patch from #2996521-4.
    
  • slucero committed f39cd77 on 2996521--switch-manager
    Issue #2996521: Coding style revisions.
    
slucero’s picture

StatusFileSize
new1.76 KB
new4.5 KB

The 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

  • Cleanup todo notes in SwitchEntity::getActivationStatus()
  • Basic tests
  • Merge
robpowell’s picture

StatusFileSize
new4.59 KB
new1.2 KB

Cleaned up todos. Currently $condition_value = $condition_plugin->execute(); is working but may need to dig deeper in evaluate() is needed.

Left todo about determine and/or but for now, I think we should prioritize or logic only as MVP.

Remaining Steps

  • Basic tests
  • Merge
robpowell’s picture

StatusFileSize
new4.47 KB
new565 bytes

slack convo with @slucero,

Regarding the question of how to check the condition plugins, I found the interface documentation for those plugins over the weekend and I'm thinking `evaluate()` is the expected way to use it since that's implemented directly for the `ConditionInterface` instead of just inherited from the `ExecutableInterface`

slucero’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I'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

  • slucero committed b31647d on 2996521--switch-manager
    Merge branch 'master' into 2996521--switch-manager
    
    * master:
    Issue #...
  • slucero committed f8353ae on 2996521--switch-manager authored by robpowell
    Issue #2996521 by robpowell, slucero: Implement a switch manager service...
slucero’s picture

Status: Needs work » Fixed

This has been merged into the 8.x-1.x branch 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.

Status: Fixed » Closed (fixed)

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