diff --git a/src/View/Helper/BakeHelper.php b/src/View/Helper/BakeHelper.php index 431405b3..3f87c325 100644 --- a/src/View/Helper/BakeHelper.php +++ b/src/View/Helper/BakeHelper.php @@ -8,6 +8,7 @@ use Brick\VarExporter\VarExporter; use Cake\Core\Configure; use Cake\Core\ConventionsTrait; +use Cake\Core\Plugin; use Cake\Database\Schema\TableSchema; use Cake\Database\Type\EnumType; use Cake\Database\TypeFactory; @@ -167,6 +168,16 @@ public function classInfo(string $class, string $type, string $suffix): array ]; } + /** + * Check if the current application has a plugin installed + * + * @param string $plugin The plugin name to check for. + */ + public function hasPlugin(string $plugin): bool + { + return Plugin::isLoaded($plugin); + } + /** * Return list of fields to generate controls for. * diff --git a/tests/TestCase/View/Helper/BakeHelperTest.php b/tests/TestCase/View/Helper/BakeHelperTest.php index d2d6d6ed..696be931 100644 --- a/tests/TestCase/View/Helper/BakeHelperTest.php +++ b/tests/TestCase/View/Helper/BakeHelperTest.php @@ -179,4 +179,10 @@ public function testConcat(): void $code ); } + + public function testHasPlugin(): void + { + $this->assertTrue($this->BakeHelper->hasPlugin('Bake')); + $this->assertFalse($this->BakeHelper->hasPlugin('Authentication')); + } }