protected function FontCKEditorButton::generateFontStyleSetting in CKEditor Font Size and Family 8
Builds the "font_names" configuration part of the CKEditor JS settings.
Parameters
string $fonts: The "font_names" setting.
Return value
array|FALSE An array containing the "font_names" configuration, or FALSE when the syntax is invalid.
See also
getConfig()
3 calls to FontCKEditorButton::generateFontStyleSetting()
- FontCKEditorButton::getConfig in src/
Plugin/ CKEditorPlugin/ FontCKEditorButton.php - Returns the additions to CKEDITOR.config for a specific CKEditor instance.
- FontCKEditorButton::validateFontSizeValue in src/
Plugin/ CKEditorPlugin/ FontCKEditorButton.php - #element_validate handler for the "font" element in settingsForm().
- FontCKEditorButton::validateFontValue in src/
Plugin/ CKEditorPlugin/ FontCKEditorButton.php - #element_validate handler for the "font" element in settingsForm().
File
- src/
Plugin/ CKEditorPlugin/ FontCKEditorButton.php, line 207
Class
- FontCKEditorButton
- Defines the "font" plugin.
Namespace
Drupal\ckeditor_font\Plugin\CKEditorPluginCode
protected function generateFontStyleSetting($fonts, $type) {
$font_style = array();
// Early-return when empty.
$fonts = trim($fonts);
if (empty($fonts)) {
return $font_style;
}
$fonts = str_replace(array(
"\r\n",
"\r",
), "\n", $fonts);
foreach (explode("\n", $fonts) as $font) {
$font = trim($font);
// Ignore empty lines in between non-empty lines.
if (empty($font)) {
continue;
}
switch ($type) {
case 'font':
// Match for patterns:
// font1, font2, font3|font label
// font1|font label
$pattern = '@^\\s*[a-zA-Z0-9\\,\\-\\s]+\\s*\\|\\s*.+\\s*$@';
break;
case 'size':
// Match for patterns:
// 123px/pt/em/rem/%|Label
$pattern = '@^\\s*\\d+(\\.?\\d+)?(px|em|%|pt|rem)\\|.*$@';
break;
}
if (!preg_match($pattern, $font)) {
return FALSE;
}
list($families, $label) = explode('|', $font);
// Build string for CKEditor.font_names.
$font_name = $label ? $label . '/' : '';
$font_name .= $families;
$font_style[] = $font_name;
}
return $font_style;
}