FestiIDE Plugin

The FestiIDE plugin adds a source code editor to Festi pages and to DGS forms. The editor is the Ace editor. The plugin contains the Ace files in static/ace/.

The plugin gives you:

  • an editor for an HTML form (fetchEditor());
  • a page block with an editor, a form and the buttons Save and Cancel (fetchIDE());
  • the DGS field type ide.

Requirements

  • The Festi Theme package (Festi\Theme\Plugin\DisplayPlugin).
  • jQuery on the page. The plugin templates use jQuery.
  • For fetchIDE(): a theme that has jQuery.SmartMessageBox and Jimbo.lang, for example SmartAdmin.

The plugin has no database tables.

Installation

Use the Festi CLI to install the plugin. Run the command from the project root:

./vendor/bin/festi-plugin --mode install --path ./src/dashboard/ --dump ./dumps/ \
    --plugin FestiIDE --repository [email protected]:FestiPlugins/php_festi_plugin_festiide.git

This example was not run for this page.

The command adds the repository to the plugins directory as a git submodule. The plugin has no install folder. Thus the command makes a migration that only adds the plugin to festi_plugins. Commit the submodule and the new migration together.

The init.php file of the plugin loads the class IdeField. This class is the DGS field type ide.

Configuration

The plugin has no options in the project configuration.

Each call sets the syntax with the parameter mode. A mode is valid when the file static/ace/src-min-noconflict/mode-<mode>.js exists, for example html, php, java, javascript, json, mysql, python and jsx.

Usage

Get the plugin instance:

$idePlugin = Core::getInstance()->getPluginInstance('FestiIDE');

In a plugin, you can also use $this->plugin->festiIDE.

Editor for an HTML form

fetchEditor() returns the HTML code of the editor. Put this code into your form.

$editor = $this->plugin->festiIDE->fetchEditor($value, 'java', 'content');
Parameter Default Description
$source none The source code that the editor shows.
$mode html The syntax of the editor.
$fieldName editor The name of the form field.

The form sends the content of the editor in the field $fieldName.

fetchEditorByPath($path, $mode) reads the source code from a file and calls fetchEditor().

Editor with a form and buttons

fetchIDE() returns a page block with the editor, a form and the buttons Save and Cancel.

$options = array(
    'title'     => __('Template'),
    'mode'      => 'php',
    'actionUrl' => '/templates/save/',
    'cancelUrl' => '/templates/'
);

$content = $this->plugin->festiIDE->fetchIDE($source, $options);

This example was not run for this page.

Option Description
title The title of the block.
mode The syntax of the editor. This option has no default. Always set it.
actionUrl The URL that receives the form.
cancelUrl The URL that the button Cancel opens. Without this option, the block has no button Cancel.

The button Save asks for a confirmation. Then it sends the form with the method POST.

fetchIDEByPath($path, $options) reads the source code from a file and calls fetchIDE().

DGS field

Use the field type ide in a DGS definition:

<field  type="ide"
        caption="<?php echo __('Content'); ?>"
        name="content"
        hide="true"
        mode="php" />

The attribute mode sets the syntax of the editor. The default is html.