- phpBB 3.3+
- PHP 7.1+
This phpBB extension provides a basic integration of the CodeMirror code editor for use by other extensions. See CodeMirror configuration for the possible options and commands. The extension tries to load all required dependencies by inspecting a configuration set in JSON format.
This extension provides some extra configuration options and commands. All of them are prefixed with "marttiphpbb".
To provide a border around the CodeMirror editor. Helpful for the light themes against the light background of the ACP.
marttiphpbbBorderEnabled: defaults tofalse.marttiphpbbBorderStyle: defaults to1px solid lightgrey
marttiphpbbToggleBordermarttiphpbbEnableBordermarttiphpbbDisableBorder
Commands for the CodeMirror "fullScreen" option:
- marttiphpbbToggleFullScreen
- marttiphpbbDisableFullScreen
- marttiphpbbEnableFullScreen
This command generates a click event on submit buttons:
- marttiphpbbSubmit
- Configuration is in JSON, so no functions can be defined.
- Not all configuration options are working (yet).
- Only one editor can be loaded in one page.
You can install this on the latest release of phpBB by following the steps below:
- Create
marttiphpbb/codemirrorin theextdirectory. - Download and unpack the repository into
ext/marttiphpbb/codemirror - Enable
CodeMirror (helper ext)in the ACP atCustomise -> Manage extensions.
- Disable
CodeMirror (helper ext)in the ACP atCustomise -> Extension Management -> Extensions. - To permanently uninstall, click
Delete Data. Optionally delete the/ext/marttiphpbb/codemirrordirectory.
- Report bugs and other issues to the Issue Tracker.
(in a normal controller likewise)
class main_module
{
var $u_action;
function main($id, $mode)
{
global $phpbb_container;
$ext_manager = $phpbb_container->get('ext.manager');
$template = $phpbb_container->get('template');
// ...
switch($mode)
{
case 'your_mode':
//..
if ($request->is_set_post('submit'))
{
// ...
}
//...
if ($ext_manager->is_enabled('marttiphpbb/codemirror'))
{
$load = $phpbb_container->get('marttiphpbb.codemirror.load');
$load->set_mode('json'); // or javascript, css, html, php, markdown, etc.s
}
$template->assign_vars([
'CONTENT' => $content, // retrieve or set somewhere above.
'U_ACTION' => $this->u_action,
]);
break;
}
}
}<textarea name="content" id="content"{{- marttiphpbb_codemirror.data_attr ?? '' -}}>
{{- CONTENT -}}
</textarea>When this extension is enabled, the <textarea> will be hidden and instead a CodeMirror instance is shown. Note that the dashes in {{- CONTENT -}} are important. Otherwise unwanted whitespace will be inserted.
(CodeMirror is licensed under MIT.)
