You are here

public function CodemirrorModePluginManager::normalizeMode in The CodeMirror Editor 8

Normalizes language mode.

Parameters

string $mode: Language mode to normalize.

Return value

string Normalized language mode.

Overrides CodemirrorModeManagerInterface::normalizeMode

File

src/CodemirrorModePluginManager.php, line 104

Class

CodemirrorModePluginManager
Defines a plugin manager to deal with CodeMirror modes.

Namespace

Drupal\codemirror_editor

Code

public function normalizeMode($mode) {
  $mode = strtolower($mode);
  if (strpos($mode, '/') === FALSE) {

    // HTML is actually just a subtype of XML.
    if ($mode == 'html') {
      $mode = 'text/html';
    }
    else {
      $modes = $this
        ->getDefinitions();
      if (isset($modes[$mode])) {

        // Consider the first declared mime type as a default one.
        // @see codemirror_editor.language_modes.yml
        $mode = reset($modes[$mode]['mime_types']);
      }
    }
  }
  return $mode;
}