diff --git a/lib/classes/component.php b/lib/classes/component.php index fb6fc9012b0..65e63a88369 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -1282,4 +1282,22 @@ $cache = '.var_export($cache, true).'; } return $componentnames; } + + /** + * Checks for the presence of monologo icons within a plugin. + * + * Only checks monologo icons in PNG and SVG formats as they are + * formats that can have transparent background. + * + * @param string $plugintype The plugin type. + * @param string $pluginname The plugin name. + * @return bool True if the plugin has a monologo icon + */ + public static function has_monologo_icon(string $plugintype, string $pluginname): bool { + $plugindir = core_component::get_plugin_directory($plugintype, $pluginname); + if ($plugindir === null) { + return false; + } + return file_exists("$plugindir/pix/monologo.svg") || file_exists("$plugindir/pix/monologo.png"); + } } diff --git a/lib/tests/component_test.php b/lib/tests/component_test.php index 2d0cc23632c..03ffe440714 100644 --- a/lib/tests/component_test.php +++ b/lib/tests/component_test.php @@ -861,4 +861,19 @@ class component_test extends advanced_testcase { $this->assertContains('tool_usertours', $componentnames); $this->assertContains('core_favourites', $componentnames); } + + /** + * Test for monologo icons check in plugins. + * + * @covers core_component::has_monologo_icon + * @return void + */ + public function test_has_monologo_icon(): void { + // The Forum activity plugin has monologo icons. + $this->assertTrue(core_component::has_monologo_icon('mod', 'forum')); + // The core H5P subsystem doesn't have monologo icons. + $this->assertFalse(core_component::has_monologo_icon('core', 'h5p')); + // The function will return false for a non-existent component. + $this->assertFalse(core_component::has_monologo_icon('randomcomponent', 'h5p')); + } }