Abstract Class humhub\modules\content\widgets\richtext\AbstractRichText

Inheritancehumhub\modules\content\widgets\richtext\AbstractRichText » humhub\widgets\JsWidget » humhub\components\Widget » yii\base\Widget
Subclasseshumhub\modules\content\widgets\richtext\HumHubRichText, humhub\modules\content\widgets\richtext\ProsemirrorRichText, humhub\modules\content\widgets\richtext\RichText, humhub\widgets\RichText
Available since version1.3

AbstractRichText serves as the base class for rich text implementations.

A rich text Widget is used for rendering the output of a rich text and usually is related to an humhub\modules\content\widgets\richtext\AbstractRichTextEditor implementation defined by $editorClass and an humhub\modules\content\widgets\richtext\AbstractRichTextProcessor implementation for post-processing rich texts defined by $processorClass.

In order for some features as the Mentionings to work a rich text should only be used for humhub\modules\content\components\ContentActiveRecord or humhub\modules\content\components\ContentAddonActiveRecord models.

A rich text can implement the following core features:

  • $preset defines a preset of plugins and settings
  • $include and exclude specific plugins
  • $pluginOptions configure specific plugins
  • $minimal rendering mode used e.g. for activities and mails, should truncate the input by means of the \humhub\modules\content\widgets\richtext\maxLenght option
  • $edit rendering mode used for rendering the rich text in a format interpretable by the editor

Common rich text plugins are Mentionings, Oembed and text formatting features.

It's up to the implementation which features or plugins are supported.

After saving the related record of a rich text the postProcess() function should be called manually in order to parse the rich text e.g. for Mentionings or other features etc. This usually happens in the humhub\modules\content\components\ContentActiveRecord::afterSave() function of the record.

Furthermore the output() function can be used as convenience function to render a given text.

$richText = RichText::output($text, $options) ?>

Note: Subclasses provided by third party modules should ideally be compatible with the default implementation in order to be able to switch the RichText implementation without loosing the semantic.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$container string Html container element. humhub\widgets\JsWidget
$content string Html content. humhub\widgets\JsWidget
$edit boolean Enables the edit rendering mode humhub\modules\content\widgets\richtext\AbstractRichText
$encode boolean humhub\modules\content\widgets\richtext\AbstractRichText
$events [] humhub\widgets\JsWidget
$exclude array Can be used to exclude specific plugins from the set of defaults (preset) humhub\modules\content\widgets\richtext\AbstractRichText
$fadeIn boolean|string|integer humhub\widgets\JsWidget
$id string humhub\widgets\JsWidget
$include array Can be used to explicitly include specific plugins in addition to the set of defaults (preset) humhub\modules\content\widgets\richtext\AbstractRichText
$init mixed humhub\modules\content\widgets\richtext\AbstractRichText
$jsWidget string humhub\widgets\JsWidget
$markdown boolean Defines if this rich text is also used as client side markdown text. humhub\modules\content\widgets\richtext\AbstractRichText
$maxLength integer Setting used to truncate the rich text content, usually related to $minimal mode and used for previews humhub\modules\content\widgets\richtext\AbstractRichText
$minimal boolean Enables the minimal rendering mode used for example for previews, this mode should take the \humhub\modules\content\widgets\richtext\maxLenght setting into account for truncating the preview content. humhub\modules\content\widgets\richtext\AbstractRichText
$options humhub\widgets\JsWidget
$pluginOptions array Rich text plugin settings. humhub\modules\content\widgets\richtext\AbstractRichText
$preset string Defines a preset of rich text features and settings humhub\modules\content\widgets\richtext\AbstractRichText
$record mixed Can be used to identify the related record humhub\modules\content\widgets\richtext\AbstractRichText
$render boolean If set to false this widget won't be rendered humhub\components\Widget
$text string Text to display humhub\modules\content\widgets\richtext\AbstractRichText
$visible boolean humhub\widgets\JsWidget
$widgetLayout string Defines an optional layout humhub\components\Widget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
editorWidget() humhub\modules\content\widgets\richtext\AbstractRichText
getData() Returns an array of data-* attributes to configure your clientside js widget. humhub\modules\content\widgets\richtext\AbstractRichText
getEditorClass() humhub\modules\content\widgets\richtext\AbstractRichText
getId() Returns the html id of this widget, if no id is set this function will generate an id if $autoGenerate is set to true (default). humhub\widgets\JsWidget
getLayoutViewParams() Returns an array of view parameter used if \humhub\components\layout is set. humhub\components\Widget
getProcessor() humhub\modules\content\widgets\richtext\AbstractRichText
getProcessorClass() humhub\modules\content\widgets\richtext\AbstractRichText
init() humhub\modules\content\widgets\richtext\AbstractRichText
output() Renders the given text by means of the given config. humhub\modules\content\widgets\richtext\AbstractRichText
postProcess() Used for the post-processing of the rich text, normally called within humhub\modules\content\components\ContentActiveRecord::afterSave() of the related humhub\modules\content\components\ContentActiveRecord. humhub\modules\content\widgets\richtext\AbstractRichText
preview() Renders the given text in minimal render mode truncated by the maxLength parameter. humhub\modules\content\widgets\richtext\AbstractRichText
process() Process is a wrapper for the run method humhub\components\Widget
run() Default implementation of JsWidget. humhub\widgets\JsWidget
setDefaultOptions() Sets some default data options required by all widgets as the widget implementation and the widget events and initialization trigger. humhub\widgets\JsWidget
widget() Creates a widget instance and runs it. humhub\components\Widget

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getAttributes() Returns all html attributes for used by this widget and will normally inserted in the widgets root html element. humhub\widgets\JsWidget
getOptions() Assembles all widget attributes and data settings of this widget. humhub\widgets\JsWidget

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_BEFORE_OUTPUT \humhub\modules\search\events\ParameterEvent With parameter 'output' humhub\modules\content\widgets\richtext\AbstractRichText
EVENT_CREATE humhub\libs\WidgetCreateEvent An event raised before creating a widget. humhub\components\Widget
EVENT_POST_PROCESS humhub\components\Event An event raised after the post-process phase of the rich text. humhub\modules\content\widgets\richtext\AbstractRichText

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
PRESET_DOCUMENT 'document' humhub\modules\content\widgets\richtext\AbstractRichText

Property Details

$edit public property

Enables the edit rendering mode

public boolean $edit false
$editorClass protected static property

humhub\modules\content\widgets\richtext\AbstractRichTextEditor subclass, used for rendering the editor widget.

See also editorWidget().

protected static string $editorClass null
$encode public property
public boolean $encode true
$exclude public property

Can be used to exclude specific plugins from the set of defaults (preset)

public array $exclude = []
$include public property

Can be used to explicitly include specific plugins in addition to the set of defaults (preset)

public array $include = []
$init public property
public mixed $init true
$markdown public property
Deprecated since 1.3

Defines if this rich text is also used as client side markdown text.

public boolean $markdown false
$maxLength public property

Setting used to truncate the rich text content, usually related to $minimal mode and used for previews

public integer $maxLength 0
$minimal public property

Enables the minimal rendering mode used for example for previews, this mode should take the \humhub\modules\content\widgets\richtext\maxLenght setting into account for truncating the preview content.

public boolean $minimal false
$pluginOptions public property

Rich text plugin settings. Note that changes of those settings may require an additional preset.

public array $pluginOptions = []
$preset public property

Defines a preset of rich text features and settings

See also humhub\modules\content\widgets\richtext\AbstractRichTextEditor::$preset.

public string $preset null
$processorClass protected static property

humhub\modules\content\widgets\richtext\AbstractRichTextProcessor subclass, used for post-processing the rich text content

See also postProcess().

protected static string $processorClass null
$record public property

Can be used to identify the related record

public mixed $record null
$text public property

Text to display

public string $text ""

Method Details

editorWidget() public static method

public static string editorWidget ( $config = [] )
$config
return string

Renders the related humhub\modules\content\widgets\richtext\AbstractRichTextEditor widget of this rich text implementation

getData() public method

Returns an array of data-* attributes to configure your clientside js widget.

Note that this function does not require to add the data- prefix. This will be done by Yii.

The data-* attributes should be inserted to the widgets root element.

public [] getData ( )
getEditorClass() public static method

public static string getEditorClass ( )
getProcessor() public static method

public static humhub\modules\content\widgets\richtext\AbstractRichTextProcessor getProcessor ( $text, $record )
$text

String rich text content to be processed

$record

ActiveRecord related model holding the rich text

return humhub\modules\content\widgets\richtext\AbstractRichTextProcessor

The related post-processor

throws \yii\base\InvalidConfigException
getProcessorClass() public static method

public static string getProcessorClass ( )
init() public method

public void init ( )
output() public static method

Renders the given text by means of the given config.

This acts as convenience method for widget().

public static string output ( $text, $config = [] )
$text

String rich text content to be rendered

$config array

Rich text widget options

return string

Render result

throws Exception
postProcess() public static method

Used for the post-processing of the rich text, normally called within humhub\modules\content\components\ContentActiveRecord::afterSave() of the related humhub\modules\content\components\ContentActiveRecord.

public static array postProcess ( $text, $record )
$text

String RichText content

$record \yii\db\ActiveRecord
throws \yii\base\InvalidConfigException
preview() public static method

Renders the given text in minimal render mode truncated by the maxLength parameter.

This acts as convenience method for widget().

public static string preview ( $text, $maxLength 0 )
$text

String rich text content to be rendered

$maxLength

Int max length of the preview

return string

Render result

throws Exception

Event Details

EVENT_BEFORE_OUTPUT event of type \humhub\modules\search\events\ParameterEvent

With parameter 'output'

EVENT_POST_PROCESS event of type humhub\components\Event

An event raised after the post-process phase of the rich text.