/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $defaultWysiwygOptions = ['plugins' => ['textcolor', 'code', 'link', 'bdesk_photo'], 'toolbar_type' => self::TOOLBAR_DEFAULT, 'skin_url' => 'bundles/oroform/css/tinymce', 'valid_elements' => implode(',', $this->htmlTagProvider->getAllowedElements()), 'menubar' => false, 'statusbar' => false, 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => true]; $defaults = ['wysiwyg_enabled' => (bool) $this->configManager->get('oro_form.wysiwyg_enabled'), 'wysiwyg_options' => $defaultWysiwygOptions, 'page-component' => ['module' => 'oroui/js/app/components/view-component', 'options' => ['view' => 'oroform/js/app/views/wysiwig-editor/wysiwyg-editor-view', 'content_css' => 'bundles/oroform/css/wysiwyg-editor.css']]]; $resolver->setDefaults($defaults); $resolver->setNormalizers(['wysiwyg_options' => function (Options $options, $wysiwygOptions) use($defaultWysiwygOptions) { if (empty($wysiwygOptions['toolbar_type']) || !array_key_exists($wysiwygOptions['toolbar_type'], $this->toolbars)) { $toolbarType = self::TOOLBAR_DEFAULT; } else { $toolbarType = $wysiwygOptions['toolbar_type']; } $wysiwygOptions['toolbar'] = $this->toolbars[$toolbarType]; $wysiwygOptions = array_merge($defaultWysiwygOptions, $wysiwygOptions); unset($wysiwygOptions['toolbar_type']); return $wysiwygOptions; }, 'attr' => function (Options $options, $attr) { $pageComponent = $options->get('page-component'); $wysiwygOptions = (array) $options->get('wysiwyg_options'); if ($this->assetHelper) { if (!empty($pageComponent['options']['content_css'])) { $pageComponent['options']['content_css'] = $this->assetHelper->getUrl($pageComponent['options']['content_css']); } if (!empty($wysiwygOptions['skin_url'])) { $wysiwygOptions['skin_url'] = $this->assetHelper->getUrl($wysiwygOptions['skin_url']); } } $pageComponent['options'] = array_merge($pageComponent['options'], $wysiwygOptions); $pageComponent['options']['enabled'] = (bool) $options->get('wysiwyg_enabled'); $attr['data-page-component-module'] = $pageComponent['module']; $attr['data-page-component-options'] = json_encode($pageComponent['options']); return $attr; }]); }
/** * @param string $string * @param bool $uiAllowedTags * @return string */ public function stripTags($string, $uiAllowedTags = false) { if ($uiAllowedTags) { return strip_tags($string, $this->htmlTagProvider->getAllowedTags()); } return trim(strip_tags($string)); }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $assetsVersionBaseUrl = ''; $assetsVersionFormatted = ''; if ($this->assetHelper) { /** * As we can't get "assets_version_format" parameter and method "getVersion" returns only version value * without any formatting - we have to calculate formatted version url's parameter to be used inside * WYSIWYG editor. */ $assetsVersionBaseUrl = $this->assetHelper->getUrl('/'); $assetsVersionFormatted = substr($assetsVersionBaseUrl, strrpos($assetsVersionBaseUrl, '/') + 1); } $defaultWysiwygOptions = ['plugins' => self::$defaultPlugins, 'toolbar_type' => self::TOOLBAR_DEFAULT, 'skin_url' => 'bundles/oroform/css/tinymce', 'valid_elements' => implode(',', $this->htmlTagProvider->getAllowedElements()), 'menubar' => false, 'statusbar' => false, 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => true, 'cache_suffix' => $assetsVersionFormatted, 'document_base_url' => $assetsVersionBaseUrl]; $defaults = ['wysiwyg_enabled' => (bool) $this->configManager->get('oro_form.wysiwyg_enabled'), 'wysiwyg_options' => $defaultWysiwygOptions, 'page-component' => ['module' => 'oroui/js/app/components/view-component', 'options' => ['view' => 'oroform/js/app/views/wysiwig-editor/wysiwyg-editor-view', 'content_css' => 'bundles/oroform/css/wysiwyg-editor.css']]]; $resolver->setDefaults($defaults); $resolver->setNormalizers(['wysiwyg_options' => function (Options $options, $wysiwygOptions) use($defaultWysiwygOptions) { if (!empty($wysiwygOptions['toolbar'])) { $wysiwygOptions = array_merge($defaultWysiwygOptions, $wysiwygOptions); unset($wysiwygOptions['toolbar_type']); return $wysiwygOptions; } if (empty($wysiwygOptions['toolbar_type']) || !array_key_exists($wysiwygOptions['toolbar_type'], self::$toolbars)) { $toolbarType = self::TOOLBAR_DEFAULT; } else { $toolbarType = $wysiwygOptions['toolbar_type']; } $wysiwygOptions['toolbar'] = self::$toolbars[$toolbarType]; $wysiwygOptions = array_merge($defaultWysiwygOptions, $wysiwygOptions); unset($wysiwygOptions['toolbar_type']); return $wysiwygOptions; }, 'attr' => function (Options $options, $attr) { $pageComponent = $options->get('page-component'); $wysiwygOptions = (array) $options->get('wysiwyg_options'); $pageComponent['options'] = array_merge($pageComponent['options'], $wysiwygOptions); $pageComponent['options']['enabled'] = (bool) $options->get('wysiwyg_enabled'); $attr['data-page-component-module'] = $pageComponent['module']; $attr['data-page-component-options'] = json_encode($pageComponent['options']); return $attr; }]); }
public function testGetAllowedTags() { $allowedTags = $this->htmlTagProvider->getAllowedTags(); $this->assertEquals($this->allowedTags, $allowedTags); }