Source of file CodeEditorField.php
Size: 2,390 Bytes - Last Modified: 2021-12-23T10:05:49+00:00
/var/www/docs.ssmods.com/process/src/code/CodeEditorField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | <?php class CodeEditorField extends TextareaField { private static $allowed_actions = array ( 'iframe' ); /** * @var string default_mode */ private static $default_mode = 'html'; /** * @var string default_theme */ private static $default_theme = null; /** * @var string default_dark_theme */ private static $default_dark_theme = 'monokai'; /** * @var string default_light_theme */ private static $default_light_theme = 'github'; /** * @var string mode */ protected $mode; /** * @var string dark_theme */ protected $dark_theme; /** * @var string light_theme */ protected $light_theme; /** * @var string theme */ protected $theme; /** * @var int Visible number of text lines. */ protected $rows = 8; public function getAttributes() { return array_merge( parent::getAttributes(), array( 'data-mode' => $this->getMode(), 'data-ace-path' => $this->getAcePath(), 'data-theme' => $this->getTheme(), 'data-dark' => $this->getDarkTheme(), 'data-light' => $this->getLightTheme() ) ); } function Field($properties = array()) { $acePath = $this->getAcePath(); Requirements::javascript($acePath . "ace.js"); Requirements::javascript($acePath . "mode-" . $this->getMode() . ".js"); Requirements::javascript("codeeditorfield/javascript/CodeEditorField.js"); Requirements::css("codeeditorfield/css/CodeEditorField.css"); return parent::Field($properties); } function setMode($mode) { $this->mode = $mode; return $this; } function getMode() { return $this->mode ? $this->mode : $this->config()->get('default_mode'); } function setTheme($theme) { $this->theme = $theme; return $this; } function getTheme() { if ($this->getDefaultTheme()){ return $this->theme ? $this->theme : $this->config()->get('default_theme'); } else { return $this->theme ? $this->theme : $this->config()->get('default_dark_theme'); } } function getDefaultTheme() { return $this->config()->get('default_theme'); } function getDarkTheme() { return $this->dark_theme ? $this->dark_theme : $this->config()->get('default_dark_theme'); } function getLightTheme() { return $this->light_theme ? $this->light_theme : $this->config()->get('default_light_theme'); } function getAcePath() { return basename(dirname(__DIR__)) . '/thirdparty/ace/src-min-noconflict/'; } } |