[3.2][BETA] CodeMirror (helper ext)

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Anti-Spam Guide
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
Post Reply
User avatar
martti
Registered User
Posts: 572
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

[3.2][BETA] CodeMirror (helper ext)

Post by martti » Sat May 26, 2018 10:05 am

Extension Name: CodeMirror (helper ext)
Author: martti
Extension Description: This phpBB helper extension provides a basic integration of the CodeMirror code editor for use in the ACP by other extensions. The extension tries to load all required dependencies by inspecting a configuration set in JSON format.
Extension Version: 0.1.1
Requirements: PhpBB 3.2.1+ PHP 7+
Extension Download: https://github.com/marttiphpbb/phpbb-ex ... master.zip The files are to be put in ext/marttiphpbb/codemirror
Github repository: https://github.com/marttiphpbb/phpbb-ext-codemirror
Languages: en
Templates: na, ACP only
Screenshot:

Image

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;
		}
	}
}
ACP Template

Code: Select all

		<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.

Post Reply

Return to “Extensions in Development”

Who is online

Users browsing this forum: No registered users and 13 guests