Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin structure #3

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions accessibility_textcolour.php → classes/textcolour.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_accessibility\widgets;
namespace accessibility_textcolour;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__ . '/../../classes/colourwidget.php');
use local_accessibility\widgets\apply_style;
use local_accessibility\widgets\colourwidget;

/**
* Text colour accessibility widget definition
*/
class textcolour extends colourwidget {
class textcolour extends colourwidget implements apply_style {

/**
* Constructor
Expand All @@ -52,7 +51,6 @@ public function init() {
$userconfig = $this->getuserconfig();
if ($userconfig) {
$this->addbodyclass('accessibility-textcolour');
$PAGE->requires->css('/local/accessibility/widgets/textcolour/styles.php');
}

$PAGE->requires->js_call_amd('local_accessibility/colourwidget', 'init', [
Expand All @@ -62,4 +60,20 @@ public function init() {
'accessibility-textcolour',
]);
}

/**
* Apply own css styles, will be served to all users when plugin is enabled.
*
* @return string
*/
public function apply_style(): string {
$userconfig = $this->getuserconfig();
if (!$userconfig) {
return "";
}
// Strip all special characters except # because its needed for hex colors.
// A check for #XX.. could have been used but this would not allow named css colors such as red, or green.
$color = preg_replace("/[^A-Za-z0-9#]/", '', $userconfig);
return "body.accessibility-textcolour, body.accessibility-textcolour * { color: {$color}; }";
}
}
38 changes: 0 additions & 38 deletions styles.php

This file was deleted.

4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

$plugin->component = 'accessibility_textcolour';
$plugin->release = '1.0.1';
$plugin->version = 2023103000;
$plugin->version = 2024051300;
$plugin->requires = 2022041900;
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = [
'local_accessibility' => 2023071300,
'local_accessibility' => 2024050800,
];