function CodeBlock::parseLanguagesFromValue

Same name and namespace in other branches
  1. 10 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock::parseLanguagesFromValue()

Parses the line-based (for form) Code Block configuration.

Parameters

string $form_value: A string containing >=1 lines with on each line a language key and label.

Return value

array The parsed equivalent: a list of arrays with each containing:

  • label: the label after the pipe symbol, with whitespace trimmed
  • language: the key for the language
1 call to CodeBlock::parseLanguagesFromValue()
CodeBlock::validateConfigurationForm in core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php

File

core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php, line 75

Class

CodeBlock
CKEditor 5 Code Block plugin configuration.

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin

Code

protected static function parseLanguagesFromValue(string $form_value) : array {
    $not_parseable_lines = [];
    $lines = explode("\n", $form_value);
    $languages = [];
    foreach ($lines as $line) {
        if (empty(trim($line))) {
            continue;
        }
        // Parse the line.
        [
            $language,
            $label,
        ] = array_map('trim', explode('|', $line));
        $languages[] = [
            'label' => $label,
            'language' => $language,
        ];
    }
    return [
        $languages,
        $not_parseable_lines,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.