show phpcsfixer config in modules conf page (using themes user pref synthax highlight)

master
Jean-Christian Paul Denis 2021-11-06 01:43:06 +01:00
parent 997096b9bc
commit a2c3f05c36
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,7 @@
/*global CodeMirror, dotclear */
'use strict';
window.CodeMirror.defineMode('dotclear', function (config) {
config.readOnly = true;
return CodeMirror.getMode(config, 'php');
});

View File

@ -21,6 +21,8 @@ class ImproveActionPhpcsfixer extends ImproveAction
32 => 'Configuration error of a Fixer.', 32 => 'Configuration error of a Fixer.',
64 => 'Exception raised within the application' 64 => 'Exception raised within the application'
]; ];
protected static $user_ui_colorsyntax = false;
protected static $user_ui_colorsyntax_theme = 'default';
protected function init(): bool protected function init(): bool
{ {
@ -33,6 +35,10 @@ class ImproveActionPhpcsfixer extends ImproveAction
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
$this->core->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme;
return true; return true;
} }
@ -41,6 +47,15 @@ class ImproveActionPhpcsfixer extends ImproveAction
return true; return true;
} }
public function header(): ?string
{
if (self::$user_ui_colorsyntax) {
return dcPage::jsLoadCodeMirror(self::$user_ui_colorsyntax_theme);
}
return null;
}
public function configure($url): ?string public function configure($url): ?string
{ {
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
@ -49,6 +64,7 @@ class ImproveActionPhpcsfixer extends ImproveAction
]); ]);
$this->redirect($url); $this->redirect($url);
} }
$content = file_get_contents(dirname(__FILE__) . '/libs/dc.phpcsfixer.rules.php');
return return
'<p><label class="classic" for="phpexe_path">' . '<p><label class="classic" for="phpexe_path">' .
@ -57,7 +73,19 @@ class ImproveActionPhpcsfixer extends ImproveAction
'</p>' . '</p>' .
'<p class="form-note">' . '<p class="form-note">' .
__('If this module does not work you can try to put here directory to php executable (without executable file name).') . __('If this module does not work you can try to put here directory to php executable (without executable file name).') .
' C:\path_to\php</p>'; ' C:\path_to\php</p>' .
'<p><label for="file_content">' . __('PHP CS Fixer configuration file:') . '</strong></label></p>' .
'<p>' . form::textarea('file_content', 120, 60, [
'default' => html::escapeHTML($content),
'class' => 'maximal',
'extra_html' => 'readonly="true"'
]) . '</p>' .
(
!self::$user_ui_colorsyntax ? '' :
dcPage::jsLoad(dcPage::getPF('improve/inc/lib.improve.action.phpcsfixer.js')) .
dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', self::$user_ui_colorsyntax_theme)
);
} }
public function closeModule(): ?bool public function closeModule(): ?bool

View File

@ -3,6 +3,7 @@
$finder = PhpCsFixer\Finder::create() $finder = PhpCsFixer\Finder::create()
->exclude('node_modules') ->exclude('node_modules')
->exclude('vendor') ->exclude('vendor')
->exclude('libs')
->in(__DIR__); ->in(__DIR__);
$config = new PhpCsFixer\Config(); $config = new PhpCsFixer\Config();