You are here

public static function BUEditor::getBUEditorEditorId in BUEditor 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Editor/BUEditor.php \Drupal\bueditor\Plugin\Editor\BUEditor::getBUEditorEditorId()

Returns the selected BUEditor Editor id for an account from editor settings.

1 call to BUEditor::getBUEditorEditorId()
BUEditor::getBUEditorEditor in src/Plugin/Editor/BUEditor.php
Returns the selected BUEditor Editor entity for an account from editor settings.

File

src/Plugin/Editor/BUEditor.php, line 127

Class

BUEditor
Defines BUEditor as an Editor plugin.

Namespace

Drupal\bueditor\Plugin\Editor

Code

public static function getBUEditorEditorId(Editor $editor, AccountInterface $account) {
  $settings = $editor
    ->getSettings();
  $roles_editors = !empty($settings['roles_editors']) ? array_filter($settings['roles_editors']) : FALSE;
  if ($roles_editors) {

    // Filter roles in two steps. May avoid a db hit by filter_get_roles_by_format().
    if ($roles_editors = array_intersect_key($roles_editors, array_flip($account
      ->getRoles()))) {
      if ($roles_editors = array_intersect_key($roles_editors, filter_get_roles_by_format($editor
        ->getFilterFormat()))) {
        return reset($roles_editors);
      }
    }
  }
  return $settings['default_editor'];
}