[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!
Get Involved
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: 598
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 by other extensions. The extension tries to load all required dependencies by inspecting a configuration set in JSON format.
Extension Version: 0.2.0
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: all & ACP
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.
Last edited by martti on Wed Aug 15, 2018 5:37 pm, edited 1 time in total.

User avatar
martti
Registered User
Posts: 598
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti » Wed Aug 15, 2018 5:35 pm

Update version 0.2.0
  • The CodeMirror editor can also be used in all templates in the board itself (not only ACP). The way to use it is the same as in the ACP.
  • Upgrade CodeMirror version to 5.39.2
Image

fagbutlil
Registered User
Posts: 23
Joined: Wed Mar 07, 2018 10:56 pm

Re: [3.2][BETA] CodeMirror (helper ext)

Post by fagbutlil » Tue Aug 28, 2018 5:00 pm

Nice thank you.

Post Reply

Return to “Extensions in Development”

Who is online

Users browsing this forum: kinerity and 20 guests