Hi All,
I have been looking for a way to enable the Ace editor into a tv field within a MIGX.
I have figured out a way (from an old forum post) to enable the Ace editor for specific tvs with a handy plugin [below]
<?php
//Apply ace editor to TV with id 5 and 7
//Found in assets/components/ace/modx.texteditor.js
$tvs = array(
array(
'id' => 22,
'height' => '500px',
'mimeType' => 'text/css'
),
array(
'id' => 23,
'height' => '500px',
'mimeType' => 'application/javascript'
),
array(
'id' => 24,
'height' => '500px',
'mimeType' => 'text/html'
),
array(
'id' => 33,
'height' => '500px',
'mimeType' => 'application/x-php'
),
array(
'id' => 37,
'height' => '500px',
'mimeType' => 'text/css'
)
);
if ($modx->event->name != 'OnDocFormRender') {
return;
}
if ($modx->getOption('which_element_editor', null, 'Ace') !== 'Ace') {
return;
}
$script = '';
foreach ($tvs as $tv) {
$id = is_array($tv) ? $tv['id'] : $tv;
$height = isset($tv['height']) ? $tv['height'] : '';
$mimeType = isset($tv['mimeType']) ? $tv['mimeType'] : '';
$tvId = '#tv' . $id;
$setHeightScript = !empty($height) ? 'this.style.height="' . $height . '";' : '';
$aceScript = 'MODx.ux.Ace.replaceTextAreas([this], "' . $mimeType . '");';
$script .= 'Ext.each(Ext.query("' . $tvId . '"), function() { ' . $setHeightScript . $aceScript . '});' . PHP_EOL;
}
if ($script) {
$modx->controller->addHtml('<script>Ext.onReady(function() {' . $script . '});</script>');
}
But I was wondering if anyone knows a way to enable the Ace editor for specific fields within a MIGX.
Thoughts? Thanks!