/** * TinyMce initializations * * @param array $options * @return string */ public function tinymceInit($options = array(), $replace = false) { $config = $this->getParameter('stfalcon_tinymce.config'); if ($replace) { $config = array_replace_recursive($config, $options); } else { $config = array_merge_recursive($config, $options); } $tinyMCE_config = $config['tinymce_config']; $this->baseUrl = !isset($tinyMCE_config['base_url']) ? null : $tinyMCE_config['base_url']; // Get path to tinymce script for the jQuery version of the editor if ($config['tinymce_jquery']) { $tinyMCE_config['jquery_script_url'] = $this->getUrl($this->baseUrl . 'bundles/stfalcontinymce/vendor/tinymce/tinymce.jquery.min.js'); } // Get local button's image if (isset($tinyMCE_config['tinymce_buttons']) && is_array($tinyMCE_config['tinymce_buttons'])) { foreach ($tinyMCE_config['tinymce_buttons'] as &$customButton) { if ($customButton['image']) { $customButton['image'] = $this->getAssetsUrl($customButton['image']); } else { unset($customButton['image']); } if ($customButton['icon']) { $customButton['icon'] = $this->getAssetsUrl($customButton['icon']); } else { unset($customButton['icon']); } } } // Update URL to external plugins if (isset($tinyMCE_config['external_plugins']) && is_array($tinyMCE_config['external_plugins'])) { foreach ($tinyMCE_config['external_plugins'] as &$extPlugin) { $extPlugin['url'] = $this->getAssetsUrl($extPlugin['url']); } } // If the language is not set in the config... if (!isset($tinyMCE_config['language']) || empty($tinyMCE_config['language'])) { // get it from the request if ($this->container->has('request_stack')) { $request = $this->getService('request_stack')->getCurrentRequest(); } else { $request = $this->getService('request'); } if ($request) { $tinyMCE_config['language'] = $request->getLocale(); } } $tinyMCE_config['language'] = LocaleHelper::getLanguage($tinyMCE_config['language']); $langDirectory = __DIR__ . '/../../Resources/public/vendor/tinymce-langs/'; // A language code coming from the locale may not match an existing language file if (!file_exists($langDirectory . $tinyMCE_config['language'] . '.js')) { unset($tinyMCE_config['language']); } if (isset($tinyMCE_config['language']) && $tinyMCE_config['language']) { $languageUrl = $this->getUrl($this->baseUrl . 'bundles/stfalcontinymce/vendor/tinymce-langs/' . $tinyMCE_config['language'] . '.js'); // TinyMCE does not allow to set different languages to each instance foreach ($tinyMCE_config['theme'] as $themeName => $themeOptions) { $tinyMCE_config['theme'][$themeName]['language'] = $tinyMCE_config['language']; $tinyMCE_config['theme'][$themeName]['language_url'] = $languageUrl; } $tinyMCE_config['language_url'] = $languageUrl; } if (isset($tinyMCE_config['theme']) && $tinyMCE_config['theme']) { // Parse the content_css of each theme so we can use 'asset[path/to/asset]' in there foreach ($tinyMCE_config['theme'] as $themeName => $themeOptions) { if (isset($themeOptions['content_css'])) { // As there may be multiple CSS Files specified we need to parse each of them individually $cssFiles = explode(',', $themeOptions['content_css']); foreach ($cssFiles as $idx => $file) { $cssFiles[$idx] = $this->getAssetsUrl(trim($file)); // we trim to be sure we get the file without spaces. } // After parsing we add them together again. $tinyMCE_config['theme'][$themeName]['content_css'] = implode(',', $cssFiles); } } } return $this->getService('templating')->render('StfalconTinymceBundle:Script:init.html.twig', array('tinymce_config' => preg_replace('/"(file_browser_callback|file_picker_callback)":"([^"]+)"\\s*/', '$1:$2', json_encode($tinyMCE_config)), 'include_jquery' => $config['include_jquery'], 'tinymce_jquery' => $config['tinymce_jquery'], 'base_url' => $this->baseUrl)); }
/** * TinyMce initializations * * @return string */ public function tinymceInit() { $config = $this->getParameter('stfalcon_tinymce.config'); $this->baseUrl = !isset($config['base_url']) ? null : $config['base_url']; /** @var $assets \Symfony\Component\Templating\Helper\CoreAssetsHelper */ $assets = $this->getService('templating.helper.assets'); // Get path to tinymce script for the jQuery version of the editor if ($config['tinymce_jquery']) { $config['jquery_script_url'] = $assets->getUrl($this->baseUrl . 'bundles/stfalcontinymce/vendor/tinymce/tinymce.jquery.min.js'); } // Get local button's image foreach ($config['tinymce_buttons'] as &$customButton) { if ($customButton['image']) { $customButton['image'] = $this->getAssetsUrl($customButton['image']); } else { unset($customButton['image']); } if ($customButton['icon']) { $customButton['icon'] = $this->getAssetsUrl($customButton['icon']); } else { unset($customButton['icon']); } } // Update URL to external plugins foreach ($config['external_plugins'] as &$extPlugin) { $extPlugin['url'] = $this->getAssetsUrl($extPlugin['url']); } // If the language is not set in the config... if (!isset($config['language']) || empty($config['language'])) { // get it from the request $config['language'] = $this->getService('request')->getLocale(); } $config['language'] = LocaleHelper::getLanguage($config['language']); $langDirectory = __DIR__ . '/../../Resources/public/vendor/tinymce/langs/'; // A language code coming from the locale may not match an existing language file if (!file_exists($langDirectory . $config['language'] . '.js')) { unset($config['language']); } if (isset($config['language']) && $config['language']) { // TinyMCE does not allow to set different languages to each instance foreach ($config['theme'] as $themeName => $themeOptions) { $config['theme'][$themeName]['language'] = $config['language']; } } return $this->getService('templating')->render('StfalconTinymceBundle:Script:init.html.twig', array('tinymce_config' => preg_replace('/"file_browser_callback":"([^"]+)"\\s*/', 'file_browser_callback:$1', json_encode($config)), 'include_jquery' => $config['include_jquery'], 'tinymce_jquery' => $config['tinymce_jquery'], 'base_url' => $this->baseUrl)); }