Purpose

Customize the toolbar of Summernote fields for specific forms. This filter allows developers to define a custom toolbar configuration for the Summernote WYSIWYG editor based on form or field criteria.

Usage

add_action( 'wr_form_field_summernote_editor_toolbar', array( $this, 'customize_toolbar' ), 10, 2 );

Parameters

  • $toolbar (string): The default toolbar configuration for the Summernote editor.
  • $field (Field): The field object, which contains information about the form and field where the editor is used.

Use Case

This functionality is useful when:

  • You want to tailor the toolbar options for specific forms or fields.
  • Simplifying or expanding the editor’s functionality based on user roles or form context is required.

Implementation Example

The following example sets a custom toolbar configuration for a form identified form_identifier.

add_action( 'wr_form_field_summernote_editor_toolbar', array( $this, 'customize_toolbar' ), 10, 2 );
 
public function customize_toolbar( $toolbar, Field $field ) {  
    if ( $field->get_form()->get_identifier() == 'form_identifier' ) {  
       $toolbar = "toolbar: [  
                      [ 'font', [ 'bold'] ],
                      [ 'color', [ 'color' ] ],
					  [ 'para', [ 'ul'  ] ], 
					  [ 'insert', [ 'link', 'emoji'] ], 
					  [ 'view', [  'fullscreen' ] ]  
					]";  
    }  
  
    return $toolbar;  
}