-
-
Save cole007/1ffa5036f8b79516ca34406d7b6833bf to your computer and use it in GitHub Desktop.
Fieldtype and fieldtype template code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* CK Editor plugin for Craft CMS | |
* | |
* CkEditor_Editor FieldType | |
* | |
* @author @cole007 | |
*/ | |
namespace Craft; | |
class CkEditor_EditorFieldType extends BaseFieldType | |
{ | |
/** | |
* @return mixed | |
*/ | |
public function getName() | |
{ | |
return Craft::t('CKEditor (tables)'); | |
} | |
/** | |
* @return mixed | |
*/ | |
public function defineContentAttribute() | |
{ | |
return AttributeType::Mixed; | |
} | |
/** | |
* @param string $name | |
* @param mixed $value | |
* @return string | |
*/ | |
public function getInputHtml($name, $value) | |
{ | |
if (!$value) | |
$value = new CkEditor_EditorModel(); | |
$id = craft()->templates->formatInputId($name); | |
$namespacedId = craft()->templates->namespaceInputId($id); | |
/* -- Include our Javascript & CSS */ | |
// craft()->templates->includeCssResource('ckeditor/ckeditor/css/fields/CkEditor_EditorFieldType.css'); | |
craft()->templates->includeJsResource('ckeditor/ckeditor/ckeditor.js'); | |
/* -- Variables to pass down to our field.js */ | |
$jsonVars = array( | |
'id' => $id, | |
'name' => $name, | |
'namespace' => $namespacedId, | |
'prefix' => craft()->templates->namespaceInputId(""), | |
); | |
$jsonVars = json_encode($jsonVars); | |
// craft()->templates->includeJs("$('#{$namespacedId}').CkEditor_EditorFieldType(" . $jsonVars . ");"); | |
craft()->templates->includeJs("CKEDITOR.on( 'dialogDefinition', function( ev ) { | |
var dialogName = ev.data.name; | |
var dialogDefinition = ev.data.definition; | |
if ( dialogName == 'table' ) { | |
var infoTab = dialogDefinition.getContents( 'info' ); | |
infoTab.remove( 'txtWidth'); | |
infoTab.remove( 'txtHeight'); | |
infoTab.remove( 'txtBorder'); | |
infoTab.remove( 'txtCellSpace'); | |
infoTab.remove( 'txtCellPad'); | |
} | |
});"); | |
craft()->templates->includeJs("CKEDITOR.replace( '{$namespacedId}ckeditor' );"); | |
/* -- Variables to pass down to our rendered template */ | |
if (isset($value['ckeditor'])) $value = $value['ckeditor']; | |
$variables = array( | |
'id' => $id, | |
'name' => $name, | |
'namespaceId' => $namespacedId, | |
'values' => $value | |
); | |
return craft()->templates->render('ckeditor/fields/CkEditor_EditorFieldType.twig', $variables); | |
} | |
/** | |
* @param mixed $value | |
* @return mixed | |
*/ | |
public function prepValueFromPost($value) | |
{ | |
return $value; | |
} | |
/** | |
* @param mixed $value | |
* @return mixed | |
*/ | |
public function prepValue($value) | |
{ | |
return $value['ckeditor']; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
/** | |
* CK Editor plugin for Craft CMS | |
* | |
* CkEditor_EditorFieldType HTML | |
* | |
* @author @cole007 | |
*/ | |
#} | |
{% import "_includes/forms" as forms %} | |
{{ forms.textareaField({ | |
id: id ~ 'ckeditor', | |
class: 'ckeditor', | |
name: name ~ '[ckeditor]', | |
value: values, | |
required: false, | |
}) }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment