public function configure() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'Tinymce', AccessManager::UPDATE))) { return $response; } // Initialize the potential exception $ex = null; // Create the Form from the request $configurationForm = new ConfigurationForm($this->getRequest()); try { // Check the form against constraints violations $form = $this->validateForm($configurationForm, "POST"); // Get the form field values $data = $form->getData(); Tinymce::setConfigValue('product_summary', $data['product_summary']); Tinymce::setConfigValue('product_conclusion', $data['product_conclusion']); Tinymce::setConfigValue('content_summary', $data['content_summary']); Tinymce::setConfigValue('content_conclusion', $data['content_conclusion']); Tinymce::setConfigValue('category_summary', $data['category_summary']); Tinymce::setConfigValue('category_conclusion', $data['category_conclusion']); Tinymce::setConfigValue('folder_summary', $data['folder_summary']); Tinymce::setConfigValue('folder_conclusion', $data['folder_conclusion']); Tinymce::setConfigValue('brand_summary', $data['brand_summary']); Tinymce::setConfigValue('brand_conclusion', $data['brand_conclusion']); Tinymce::setConfigValue('show_menu_bar', $data['show_menu_bar']); Tinymce::setConfigValue('force_pasting_as_text', $data['force_pasting_as_text']); Tinymce::setConfigValue('editor_height', $data['editor_height']); Tinymce::setConfigValue('custom_css', $data['custom_css']); // Save Custom CSS in default assets $customCss = __DIR__ . DS . '..' . DS . 'templates' . DS . 'backOffice' . DS . 'default' . DS . 'assets' . DS . 'css' . DS . 'custom-css.less'; if (1 || false === file_put_contents($customCss, $data['custom_css'])) { throw new TheliaProcessException($this->getTranslator()->trans("Failed to update custom CSS file \"%file\". Please check this file or parent folder write permissions.", ['%file' => $customCss])); } // Log configuration modification $this->adminLogAppend("tinymce.configuration.message", AccessManager::UPDATE, sprintf("Tinymce configuration updated")); // Everything is OK. return new RedirectResponse(URL::getInstance()->absoluteUrl('/admin/module/Tinymce')); } catch (FormValidationException $ex) { // Form cannot be validated. Create the error message using // the BaseAdminController helper method. $error_msg = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $error_msg = $ex->getMessage(); } // At this point, the form has errors, and should be redisplayed. We don not redirect, // just redisplay the same template. // Setup the Form error context, to make error information available in the template. $this->setupFormErrorContext($this->getTranslator()->trans("Tinymce configuration", [], Tinymce::MODULE_DOMAIN), $error_msg, $configurationForm, $ex); // Do not redirect at this point, or the error context will be lost. // Just redisplay the current template. return $this->render('module-configure', array('module_code' => 'Tinymce')); }
protected function buildForm() { $this->formBuilder->add('editor_height', 'integer', ['required' => false, 'data' => Tinymce::getConfigValue('editor_height', 0), 'label' => $this->translator->trans('Height of the editor area, in pixels. Enter 0 for default ', [], Tinymce::MODULE_DOMAIN)])->add('show_menu_bar', 'checkbox', ['required' => false, 'data' => intval(Tinymce::getConfigValue('show_menu_bar', 0)) != 0, 'label' => $this->translator->trans('Show the TinyMCE menu bar', [], Tinymce::MODULE_DOMAIN)])->add('force_pasting_as_text', 'checkbox', ['required' => false, 'data' => intval(Tinymce::getConfigValue('force_pasting_as_text', 0)) != 0, 'label' => $this->translator->trans('Force pasting as text', [], Tinymce::MODULE_DOMAIN), 'label_attr' => ['help' => $this->translator->trans('If checked, all pasted data will be converted as plain text, removing tags and styles.', [], Tinymce::MODULE_DOMAIN)]])->add('set_images_as_responsive', 'checkbox', ['required' => false, 'data' => intval(Tinymce::getConfigValue('set_images_as_responsive', 1)) != 0, 'label' => $this->translator->trans('Add responsive class to images', [], Tinymce::MODULE_DOMAIN), 'label_attr' => ['help' => $this->translator->trans('If checked, the "img-responsive" class is added by default to inserted images', [], Tinymce::MODULE_DOMAIN)]])->add('custom_css', 'textarea', ['required' => false, 'data' => Tinymce::getConfigValue('custom_css', '/* Enter here CSS or LESS code */'), 'label' => $this->translator->trans('Custom CSS available in the editor', [], Tinymce::MODULE_DOMAIN), 'label_attr' => ['help' => $this->translator->trans('Enter CSS or LESS code. You may also customize the editor.less file in the plugin template directory.', [], Tinymce::MODULE_DOMAIN)], 'attr' => ['rows' => 10, 'style' => 'font-family: \'Courier New\', Courier, monospace;']])->add('test_zone', 'textarea', ['required' => false, 'label' => $this->translator->trans('Sample editor', [], Tinymce::MODULE_DOMAIN), 'label_attr' => ['help' => $this->translator->trans('This is a sample text editor, to view actual configuration.', [], Tinymce::MODULE_DOMAIN)]]); }
protected function addConfigField($key) { $this->formBuilder->add($key, "checkbox", array("label_attr" => [], "required" => false, "constraints" => array(), "data" => intval(Tinymce::getConfigValue($key, 0)) != 0)); }