protected function StylesCombo::generateStylesSetSetting in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo::generateStylesSetSetting()
Builds the "stylesSet" configuration part of the CKEditor JS settings.
Parameters
string $styles: The "styles" setting.
Return value
array|FALSE An array containing the "stylesSet" configuration, or FALSE when the syntax is invalid.
See also
getConfig()
2 calls to StylesCombo::generateStylesSetSetting()
- StylesCombo::getConfig in core/
modules/ ckeditor/ src/ Plugin/ CKEditorPlugin/ StylesCombo.php - Returns the additions to CKEDITOR.config for a specific CKEditor instance.
- StylesCombo::validateStylesValue in core/
modules/ ckeditor/ src/ Plugin/ CKEditorPlugin/ StylesCombo.php - #element_validate handler for the "styles" element in settingsForm().
File
- core/
modules/ ckeditor/ src/ Plugin/ CKEditorPlugin/ StylesCombo.php, line 120 - Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo.
Class
- StylesCombo
- Defines the "stylescombo" plugin.
Namespace
Drupal\ckeditor\Plugin\CKEditorPluginCode
protected function generateStylesSetSetting($styles) {
$styles_set = array();
// Early-return when empty.
$styles = trim($styles);
if (empty($styles)) {
return $styles_set;
}
$styles = str_replace(array(
"\r\n",
"\r",
), "\n", $styles);
foreach (explode("\n", $styles) as $style) {
$style = trim($style);
// Ignore empty lines in between non-empty lines.
if (empty($style)) {
continue;
}
// Validate syntax: element[.class...]|label pattern expected.
if (!preg_match('@^ *[a-zA-Z0-9]+ *(\\.[a-zA-Z0-9_-]+ *)*\\| *.+ *$@', $style)) {
return FALSE;
}
// Parse.
list($selector, $label) = explode('|', $style);
$classes = explode('.', $selector);
$element = array_shift($classes);
// Build the data structure CKEditor's stylescombo plugin expects.
// @see http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Styles
$configured_style = array(
'name' => trim($label),
'element' => trim($element),
);
if (!empty($classes)) {
$configured_style['attributes'] = array(
'class' => implode(' ', array_map('trim', $classes)),
);
}
$styles_set[] = $configured_style;
}
return $styles_set;
}