Back to EditorField class

Method getEditor

protected \Joomla\CMS\Editor\Editor
getEditor
()
Method to get an Editor object based on the form field.
Returns
  • \Joomla\CMS\Editor\Editor The Editor object.
Since
  • 1.6
Class: EditorField
Project: Joomla

Method getEditor - Source code

/**
 * Method to get an Editor object based on the form field.
 *
 * @return  Editor  The Editor object.
 *
 * @since   1.6
 */
protected function getEditor()
{
    // Only create the editor if it is not already created.
    if (empty($this->editor)) {
        $editor = null;
        if ($this->editorType) {
            // Get the list of editor types.
            $types = $this->editorType;
            // Get the database object.
            $db = Factory::getDbo();
            // Build the query.
            $query = $db->getQuery(true)->select($db->quoteName('element'))->from($db->quoteName('#__extensions'))->where([$db->quoteName('element') . ' = :editor', $db->quoteName('folder') . ' = ' . $db->quote('editors'), $db->quoteName('enabled') . ' = 1']);
            // Declare variable before binding.
            $element = '';
            $query->bind(':editor', $element);
            $query->setLimit(1);
            // Iterate over the types looking for an existing editor.
            foreach ($types as $element) {
                // Check if the editor exists.
                $db->setQuery($query);
                $editor = $db->loadResult();
                // If an editor was found stop looking.
                if ($editor) {
                    break;
                }
            }
        }
        // Create the JEditor instance based on the given editor.
        if ($editor === null) {
            $editor = Factory::getApplication()->get('editor');
        }
        $this->editor = Editor::getInstance($editor);
    }
    return $this->editor;
}