Retrieves text editor libraries and JavaScript settings.
array $format_ids: An array of format IDs as returned by array_keys(filter_formats()).
array An array of attachments, for use with #attached.
public function getAttachments(array $format_ids) {
$attachments = array(
'library' => array(),
);
$settings = array();
foreach ($format_ids as $format_id) {
$editor = editor_load($format_id);
if (!$editor) {
continue;
}
$plugin = $this
->createInstance($editor->editor);
// Libraries.
$attachments['library'] = array_merge($attachments['library'], $plugin
->getLibraries($editor));
// JavaScript settings.
$settings[$format_id] = array(
'editor' => $editor->editor,
'editorSettings' => $plugin
->getJSSettings($editor),
);
}
// We have all JavaScript settings, allow other modules to alter them.
drupal_alter('editor_js_settings', $settings);
if (empty($attachments['library']) && empty($settings)) {
return array();
}
$attachments['js'][] = array(
'type' => 'setting',
'data' => array(
'editor' => array(
'formats' => $settings,
),
),
);
return $attachments;
}