Author: martti
Extension Description: This phpBB helper extension provides a basic integration of the CodeMirror code editor for use by other extensions. The extension tries to load all required dependencies by inspecting a configuration set in JSON format.
Extension Version: 0.7.0
Requirements:
- phpBB 3.3+
- PHP 7.1+
ext/marttiphpbb/codemirror
Github repository: https://github.com/marttiphpbb/phpbb-ext-codemirror
Languages: en
Templates: all & ACP
Screenshot:
For extension Developers: How to use in your extension
ACP controller:
First check if this extension is enabled, then get the service
marttiphpbb.codemirror.load
. With this service you set the mode (language) of the editor.
Code: Select all
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.
}
$template->assign_vars([
'CONTENT' => $content, // retrieve or set somewhere above.
'U_ACTION' => $this->u_action,
]);
break;
}
}
}
Code: Select all
<textarea name="content" id="content"{{- marttiphpbb_codemirror.data_attr ?? '' -}}>
{{- CONTENT -}}
</textarea>
<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.