Abstract Class humhub\modules\content\widgets\richtext\AbstractRichText
Inheritance | humhub\modules\content\widgets\richtext\AbstractRichText » humhub\widgets\JsWidget » humhub\components\Widget » yii\base\Widget |
---|---|
Subclasses | humhub\modules\content\widgets\richtext\HumHubRichText, humhub\modules\content\widgets\richtext\ProsemirrorRichText, humhub\modules\content\widgets\richtext\RichText, humhub\widgets\RichText |
Available since version | 1.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
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$editorClass | string | humhub\modules\content\widgets\richtext\AbstractRichTextEditor subclass, used for rendering the editor widget. | humhub\modules\content\widgets\richtext\AbstractRichText |
$processorClass | string | humhub\modules\content\widgets\richtext\AbstractRichTextProcessor subclass, used for post-processing the rich text content | humhub\modules\content\widgets\richtext\AbstractRichText |
Public Methods
Protected Methods
Method | Description | Defined 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
Event | Type | Description | Defined 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
Constant | Value | Description | Defined By |
---|---|---|---|
PRESET_DOCUMENT | 'document' | humhub\modules\content\widgets\richtext\AbstractRichText |
Property Details
Enables the edit rendering mode
humhub\modules\content\widgets\richtext\AbstractRichTextEditor subclass, used for rendering the editor widget.
See also editorWidget().
Can be used to exclude specific plugins from the set of defaults (preset)
Can be used to explicitly include specific plugins in addition to the set of defaults (preset)
Defines if this rich text is also used as client side markdown text.
Setting used to truncate the rich text content, usually related to $minimal mode and used for previews
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.
Rich text plugin settings. Note that changes of those settings may require an additional preset.
Defines a preset of rich text features and settings
See also humhub\modules\content\widgets\richtext\AbstractRichTextEditor::$preset.
humhub\modules\content\widgets\richtext\AbstractRichTextProcessor subclass, used for post-processing the rich text content
See also postProcess().
Can be used to identify the related record
Text to display
Method Details
public static string editorWidget ( $config = [] ) | ||
$config | ||
return | string | Renders the related humhub\modules\content\widgets\richtext\AbstractRichTextEditor widget of this rich text implementation |
---|
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 ( ) |
public static string getEditorClass ( ) |
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 |
public static string getProcessorClass ( ) |
public void init ( ) |
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 |
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 |
---|
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
With parameter 'output'
An event raised after the post-process phase of the rich text.