| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | <?php namespace TierPricingTable\Addons; |
| 2 | 2 | |
| 3 | 3 | use TierPricingTable\Core\ServiceContainerTrait; |
| 4 | +use TierPricingTable\Settings\CustomOptions\TPTFeatureFlagOption; | |
| 4 | 5 | use TierPricingTable\Settings\CustomOptions\TPTSwitchOption; |
| 5 | 6 | use TierPricingTable\Settings\Settings; |
| 6 | 7 | |
| 7 | 8 | abstract class AbstractAddon { |
| @@ -20,9 +21,10 @@ | ||
| 20 | 21 | 'title' => $this->getName(), |
| 21 | 22 | 'id' => Settings::SETTINGS_PREFIX . '_addon_' . $this->getSlug(), |
| 22 | 23 | 'default' => $this->isActiveByDefault() ? 'yes' : 'no', |
| 23 | 24 | 'desc' => $this->getDescription(), |
| 24 | - 'type' => TPTSwitchOption::FIELD_TYPE, | |
| 25 | + 'icon' => $this->getIcon(), | |
| 26 | + 'type' => TPTFeatureFlagOption::FIELD_TYPE, | |
| 25 | 27 | ); |
| 26 | 28 | |
| 27 | 29 | return $addons; |
| 28 | 30 | } |
| @@ -38,11 +40,22 @@ | ||
| 38 | 40 | protected function isActiveByDefault(): bool { |
| 39 | 41 | return true; |
| 40 | 42 | } |
| 41 | 43 | |
| 44 | + /** | |
| 45 | + * Whether the add-on with this slug is switched on, without needing its instance. | |
| 46 | + */ | |
| 47 | + public static function isAddonEnabled( string $slug, bool $activeByDefault = true ): bool { | |
| 48 | + $settings = \TierPricingTable\Core\ServiceContainer::getInstance()->getSettings(); | |
| 49 | + | |
| 50 | + return 'yes' === $settings->get( '_addon_' . $slug, $activeByDefault ? 'yes' : 'no' ); | |
| 51 | + } | |
| 52 | + | |
| 42 | 53 | abstract public function getName(); |
| 43 | 54 | |
| 44 | 55 | abstract public function getDescription(); |
| 56 | + | |
| 57 | + abstract public function getIcon(): string; | |
| 45 | 58 | |
| 46 | 59 | abstract public function getSlug(); |
| 47 | 60 | |
| 48 | 61 | abstract public function run(); |