Jet\Form_Renderer_Field_Input_WYSIWYG

Renderer of WYSIWYG editor. Class inherits from Form_Renderer_Field_Input.

Default view scripts

The name of the default view script is field/input/wysiwyg.

The value in the system configuration can be accessed as follows:

$view_script_start SysConf_Jet_Form_DefaultViews::get($field->getType(), 'input'); SysConf_Jet_Form_DefaultViews::set$field_type 'input''my-view-script');

WARNING! WYSIWYG editor is not part of Jet! One particular editor is integrated in the sample application, but you can replace it with another editor. (Of course, it is not a problem to use more than one kind of editor in one application - if you need to).

The renderer itself is not tightly coupled to any particular editor, but merely provides everything needed to integrate the editor.

What the renderer allows is to modify the editor configuration. So you can use one kind of editor, but have it configured differently in different places in the application for different purposes.

Overview of methods

Method Meaning of
public setEditorConfig(
array $editor_config
) : void
Sets the configuration of the editor.
The configuration depends on the editor that has been integrated.
Methods can be called for example in the view showing the form with the editor to set the specific behavior of the editor for its specific use.
public getEditorConfig(
) : array|null
Returns the editor configuration. See the setEditorConfig method.
public appendEditorCSSFile(
string $URI,
string $media='screen'
) : void
Adds an address to the CSS file that the editor needs to work.
public getEditorCSSFiles(
) : array
Returns the addresses of the requested CSS files.
public appendEditorJavaScriptFile(
string $URI
) : void
Adds the address of the JavaScript file that the editor needs to work.
public getEditorJavaScriptFiles(
) : array
Returns the addresses of the requested JavaScript files.
public setEditorInitializeCodeGenerator(
callable $editor_initialize_code_generator
) : void
Sets up a generator whose job is to generate a piece of code (most likely JavaScript) that the additor activates and sets.
public getEditorInitializeCodeGenerator(
) : callable|null
Returns the initialization code generator. See the setEditorInitializeCodeGenerator method.
public requireEditorCSSandJavaScriptFiles(
) : void
It takes care of inserting the required CSS and JS files into the layout.
public generateEditorInitializeCode(
) : string
It takes care of generating the initialization code. Automatically calls the requireEditorCSSandJavaScriptFiles method

Příklad integrace editoru

use Jet\MVC_View;
use 
Jet\Form_Renderer_Field_Input_WYSIWYG;
use 
Jet\Form_Field_WYSIWYG;

/**
 * @var MVC_View $this
 * @var Form_Renderer_Field_Input_WYSIWYG $r
 * @var Form_Field_WYSIWYG $field
 */
$r $this->getRaw'renderer' );
$field $r->getField();

//-----------------------------------------------------------------------------------

//$r->appendEditorCSSFile( '//cdn.tiny.cloud/1/no-api-key/tinymce/5/skins/lightgray/skin.min.css');
$r->appendEditorJavaScriptFile('//cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js',);
$r->setEditorInitializeCodeGenerator( function( Form_Field_WYSIWYG $field, array $editor_config ) : string {
    
    
$editor_config['selector'] = '#' $field->getId();
    
    if( 
$field->getIsReadonly() ) {
        
$editor_config['readonly'] = 1;
    }
    
    return 
'tinymce.init(' json_encode$editor_config ) . ')';
} );

if( !
$r->getEditorConfig() ) {
    
$r->setEditorConfig([
        
        
'mode'                    => 'exact',
        
'apply_source_formatting' => true,
        
'remove_linebreaks'       => false,
        
'entity_encoding'         => 'raw',
        
'convert_urls'            => false,
        
'verify_html'             => true,
        
        
'force_br_newlines' => false,
        
'force_p_newlines'  => false,
        
'forced_root_block' => '',
    
        
'plugins'       => 'advlist autolink lists link image ',
        
'paste_as_text'     => true,
    ]);
}

?>
<textarea <?=$r->renderTagAttributes()?>><?= $field->getValueRaw() ?></textarea>
Previous chapter
Jet\Form_Renderer_Field_Input_Textarea
Next chapter
Determining element widths