This is gonna be a pretty long, but here's my custom
sfWidgetFormTextareaTinyMCE.class.php
It works with TinyMCE 3 and up, and also produces fully XHTML
compatible output.
It also allows for gzip compression; Sample usage:
$this->widgetSchema['content'] = new
sfWidgetFormTextareaTinyMCE(array('tinymce_gzip' => true),array
('size'=>'102x30'));
class sfWidgetFormTextareaTinyMCE extends sfWidgetFormTextarea
{
public function __construct($options = array(), $attributes = array
())
{
/**
* We need to override the constructor in order to be able to remove
keys from the $attributes array;
* if we don't remove the pseudo key 'size', it results in invalid
xhtml markup
*/
if (array_key_exists('size', $attributes))
{
//This code handles textarea size input in 140x30 format
list ($cols, $rows) = explode ('x', $attributes['size']);
unset ($attributes['size']);
$attributes['cols'] = $cols;
$attributes['rows'] = $rows;
$this->setAttributes($attributes);
}
parent::__construct($options, $attributes);
}
/**
* Constructor.
*
* Available options:
*
* ** Options **
* * theme: The Tiny MCE theme
* * width: Width
* * height: Height
* * config: The javascript configuration
* * tinymce_gzip: Wether to use gzip compression for TinyMCE
* * file_browser_callback: a JS callback function for embending a
file browser into TinyMCE
* * content_css: A css file that will be applied to the editor
window; Should be the same css as the one used in the real output
*
* ** Attributes **
* * cols/rows or size: sets the size of the TinyMCE window; size
is used in the format: COLSxROWS (100x30)
*
* @param array $options An array of options
* @param array $attributes An array of default HTML attributes
*
* @see sfWidgetForm
*/
protected function configure($options = array(), $attributes = array
())
{
$this->addOption('theme', 'advanced');
$this->addOption('width');
$this->addOption('height');
$this->addOption('config', '');
$this->addOption('tinymce_gzip');
$this->addOption('file_browser_callback',
'sfAssetsLibrary.fileBrowserCallBack');
$this->addOption('content_css', '/js/tiny_mce/css/
default.css');
/**
* @param string $name The element name
* @param string $value The value selected in this widget
* @param array $attributes An array of HTML attributes to be
merged with the default HTML attributes
* @param array $errors An array of errors for the field
*
* @return string An HTML tag string
*
* @see sfWidgetForm
*/
public function render($name, $value = null, $attributes = array(),
$errors = array())
{
// use tinymce's gzipped js?
$tinymce_file = $this->getOption('tinymce_gzip') ? '/
tiny_mce_gzip.js' : '/tiny_mce.js';
// tinymce installed?
$js_path = sfConfig::get('sf_rich_text_js_dir') ? '/'.sfConfig::get
('sf_rich_text_js_dir').$tinymce_file : '/sf/tinymce/js'.
$tinymce_file;
if (!is_readable(sfConfig::get('sf_web_dir').$js_path))
{
throw new sfConfigurationException('You must install TinyMCE to
use this widget (see rich_text_js_dir in settings.yml).');
}
On Fri, Feb 27, 2009 at 11:58 AM, Crafty_Shadow <vankat...@gmail.com> wrote:
> This is gonna be a pretty long, but here's my custom
> sfWidgetFormTextareaTinyMCE.class.php
> It works with TinyMCE 3 and up, and also produces fully XHTML
> compatible output.
> It also allows for gzip compression; Sample usage:
> $this->widgetSchema['content'] = new
> sfWidgetFormTextareaTinyMCE(array('tinymce_gzip' => true),array
> ('size'=>'102x30'));
> class sfWidgetFormTextareaTinyMCE extends sfWidgetFormTextarea
> {
> public function __construct($options = array(), $attributes = array
> ())
> {
> /**
> * We need to override the constructor in order to be able to remove
> keys from the $attributes array;
> * if we don't remove the pseudo key 'size', it results in invalid
> xhtml markup
> */
> if (array_key_exists('size', $attributes))
> {
> //This code handles textarea size input in 140x30 format
> list ($cols, $rows) = explode ('x', $attributes['size']);
> unset ($attributes['size']);
> $attributes['cols'] = $cols;
> $attributes['rows'] = $rows;
> $this->setAttributes($attributes);
> }
> parent::__construct($options, $attributes);
> }
> /**
> * Constructor.
> *
> * Available options:
> *
> * ** Options **
> * * theme: The Tiny MCE theme
> * * width: Width
> * * height: Height
> * * config: The javascript configuration
> * * tinymce_gzip: Wether to use gzip compression for TinyMCE
> * * file_browser_callback: a JS callback function for embending a
> file browser into TinyMCE
> * * content_css: A css file that will be applied to the editor
> window; Should be the same css as the one used in the real output
> *
> * ** Attributes **
> * * cols/rows or size: sets the size of the TinyMCE window; size
> is used in the format: COLSxROWS (100x30)
> *
> * @param array $options An array of options
> * @param array $attributes An array of default HTML attributes
> *
> * @see sfWidgetForm
> */
> protected function configure($options = array(), $attributes = array
> ())
> {
> $this->addOption('theme', 'advanced');
> $this->addOption('width');
> $this->addOption('height');
> $this->addOption('config', '');
> $this->addOption('tinymce_gzip');
> $this->addOption('file_browser_callback',
> 'sfAssetsLibrary.fileBrowserCallBack');
> $this->addOption('content_css', '/js/tiny_mce/css/
> default.css');
> /**
> * @param string $name The element name
> * @param string $value The value selected in this widget
> * @param array $attributes An array of HTML attributes to be
> merged with the default HTML attributes
> * @param array $errors An array of errors for the field
> *
> * @return string An HTML tag string
> *
> * @see sfWidgetForm
> */
> public function render($name, $value = null, $attributes = array(),
> $errors = array())
> {
> // use tinymce's gzipped js?
> $tinymce_file = $this->getOption('tinymce_gzip') ? '/
> tiny_mce_gzip.js' : '/tiny_mce.js';
> // tinymce installed?
> $js_path = sfConfig::get('sf_rich_text_js_dir') ? '/'.sfConfig::get
> ('sf_rich_text_js_dir').$tinymce_file : '/sf/tinymce/js'.
> $tinymce_file;
> if (!is_readable(sfConfig::get('sf_web_dir').$js_path))
> {
> throw new sfConfigurationException('You must install TinyMCE to
> use this widget (see rich_text_js_dir in settings.yml).');
> }
This one is based off the original, with my custom patches. Original
didn't work for me either and it didn't have some of the functionality
I needed (esp generating XHTML valid code) so I went and created this
one.
There is only one thing I'm not happy with, and that's line 110, the
part of the GZip version that defines which languages to be included.
I should probably just rewrite that with sfContext::getInstance()-
>getUser()->getCulture() instead of the current "en/bg".
Taking into account the way symfony autoloading works, all you need to
do is create a sfWidgetFormTextareaTinyMCE.class.php file with the
widget in your lib folder. It superseeds the one in the
sfFormExtraPlugin. Also, this widget is thoroughly tested and is
working in several of my released applications. I could create
a .patch file for the sfFormExtraPlugin, but I don't think it'd make
it into the plugin. Probably if you guys support the changes ?
On Feb 27, 1:20 pm, Denis Fingonnet <dfingon...@gmail.com> wrote:
> But I wish I could make the original sfWidgetFormTextareaTinyMCE works,
> because it is bundled with the sfFormExtraPlugin.
> I can say you're able to make it works and to provide a patch if there is a
> bug in it.
> Could you have a look or have you done a custom widget because you weren't
> able to make the original widget works ?
> On Fri, Feb 27, 2009 at 11:58 AM, Crafty_Shadow <vankat...@gmail.com> wrote:
> > This is gonna be a pretty long, but here's my custom
> > sfWidgetFormTextareaTinyMCE.class.php
> > It works with TinyMCE 3 and up, and also produces fully XHTML
> > compatible output.
> > It also allows for gzip compression; Sample usage:
> > class sfWidgetFormTextareaTinyMCE extends sfWidgetFormTextarea
> > {
> > public function __construct($options = array(), $attributes = array
> > ())
> > {
> > /**
> > * We need to override the constructor in order to be able to remove
> > keys from the $attributes array;
> > * if we don't remove the pseudo key 'size', it results in invalid
> > xhtml markup
> > */
> > if (array_key_exists('size', $attributes))
> > {
> > //This code handles textarea size input in 140x30 format
> > list ($cols, $rows) = explode ('x', $attributes['size']);
> > unset ($attributes['size']);
> > $attributes['cols'] = $cols;
> > $attributes['rows'] = $rows;
> > $this->setAttributes($attributes);
> > }
> > /**
> > * @param string $name The element name
> > * @param string $value The value selected in this widget
> > * @param array $attributes An array of HTML attributes to be
> > merged with the default HTML attributes
> > * @param array $errors An array of errors for the field
> > *
> > * @return string An HTML tag string
> > *
> > * @see sfWidgetForm
> > */
> > public function render($name, $value = null, $attributes = array(),
> > $errors = array())
> > {
> > // use tinymce's gzipped js?
> > $tinymce_file = $this->getOption('tinymce_gzip') ? '/
> > tiny_mce_gzip.js' : '/tiny_mce.js';
> > // tinymce installed?
> > $js_path = sfConfig::get('sf_rich_text_js_dir') ? '/'.sfConfig::get
> > ('sf_rich_text_js_dir').$tinymce_file : '/sf/tinymce/js'.
> > $tinymce_file;
> > if (!is_readable(sfConfig::get('sf_web_dir').$js_path))
> > {
> > throw new sfConfigurationException('You must install TinyMCE to
> > use this widget (see rich_text_js_dir in settings.yml).');
> > }
Because I managed to make the widget work without changing anything.
I was doing this for a translated field called texte :
$this->widgetSchema['texte'] = new
sfWidgetFormTextareaTinyMCE(array(
'width' => 550,
'height' => 350,
'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
), array(
'class' => 'tinyMCE'
));
But if I do this :
$this->widgetSchema['fr']['texte'] = new
sfWidgetFormTextareaTinyMCE(array(
'width' => 550,
'height' => 350,
'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
), array(
'class' => 'tinyMCE'
));
It works very well.
So it is not a bug but a lack of documentation about I18n and widget or I
didn't get it...
And a bad error message.
On Fri, Feb 27, 2009 at 2:28 PM, Denis Fingonnet <dfingon...@gmail.com>wrote:
For i18n you should edit the representative form class;
that is to say, in the main form, let's call it
StaticPageForm.class.php you need:
$this->embendI18n(array('en','fr')); //embends English and French
//set labels so it's clearer
$this->widgetSchema->setLabel('en', 'English');
$this->widgetSchema->setLabel('fr', 'French');
Then in StaticPageI18nForm.class.php
$this->widgetSchema['content'] = new sfWidgetFormTextareaTinyMCE etc
On Feb 27, 4:29 pm, Denis Fingonnet <dfingon...@gmail.com> wrote:
> Because I managed to make the widget work without changing anything.
> I was doing this for a translated field called texte :
> $this->widgetSchema['texte'] = new
> sfWidgetFormTextareaTinyMCE(array(
> 'width' => 550,
> 'height' => 350,
> 'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
> ), array(
> 'class' => 'tinyMCE'
> ));
> But if I do this :
> $this->widgetSchema['fr']['texte'] = new
> sfWidgetFormTextareaTinyMCE(array(
> 'width' => 550,
> 'height' => 350,
> 'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
> ), array(
> 'class' => 'tinyMCE'
> ));
> It works very well.
> So it is not a bug but a lack of documentation about I18n and widget or I
> didn't get it...
> And a bad error message.
> On Fri, Feb 27, 2009 at 2:28 PM, Denis Fingonnet <dfingon...@gmail.com>wrote:
> > I'll keep an eye on it.
> > Thank you
> > On Fri, Feb 27, 2009 at 1:43 PM, Crafty_Shadow <vankat...@gmail.com>wrote:
> >> Ticket with patch created, the rest is up to fabien:
On Fri, Feb 27, 2009 at 4:23 PM, Crafty_Shadow <vankat...@gmail.com> wrote:
> For i18n you should edit the representative form class;
> that is to say, in the main form, let's call it
> StaticPageForm.class.php you need:
> $this->embendI18n(array('en','fr')); //embends English and French
> //set labels so it's clearer
> $this->widgetSchema->setLabel('en', 'English');
> $this->widgetSchema->setLabel('fr', 'French');
> Then in StaticPageI18nForm.class.php
> $this->widgetSchema['content'] = new sfWidgetFormTextareaTinyMCE etc
> On Feb 27, 4:29 pm, Denis Fingonnet <dfingon...@gmail.com> wrote:
> > Does the tinyMCE widget used for a I18n field ?
> > Because I managed to make the widget work without changing anything.
> > I was doing this for a translated field called texte :
> > $this->widgetSchema['texte'] = new
> > sfWidgetFormTextareaTinyMCE(array(
> > 'width' => 550,
> > 'height' => 350,
> > 'config' => 'theme_advanced_disable:
> "anchor,image,cleanup,help"',
> > ), array(
> > 'class' => 'tinyMCE'
> > ));
> > But if I do this :
> > $this->widgetSchema['fr']['texte'] = new
> > sfWidgetFormTextareaTinyMCE(array(
> > 'width' => 550,
> > 'height' => 350,
> > 'config' => 'theme_advanced_disable:
> "anchor,image,cleanup,help"',
> > ), array(
> > 'class' => 'tinyMCE'
> > ));
> > It works very well.
> > So it is not a bug but a lack of documentation about I18n and widget or I
> > didn't get it...
> > And a bad error message.
> > On Fri, Feb 27, 2009 at 2:28 PM, Denis Fingonnet <dfingon...@gmail.com
> >wrote:
> > > I'll keep an eye on it.
> > > Thank you
> > > On Fri, Feb 27, 2009 at 1:43 PM, Crafty_Shadow <vankat...@gmail.com
> >wrote:
> > >> Ticket with patch created, the rest is up to fabien:
I will assume that this question was directed to me.
And no, the library itself is not included, the insanely-big portion
of the code is dedicated to producing XHTML compliant output.
On Feb 26, 9:00 pm, Jan Schlosser <j...@steffiundjan.de> wrote: