function _panopoly_wysiwyg_set_editor_anchor in Panopoly WYSIWYG 8.2
Sets the anchor plugin into the editor.
Parameters
string $editor_id: The editor ID.
1 call to _panopoly_wysiwyg_set_editor_anchor()
- panopoly_wysiwyg_update_8206 in ./
panopoly_wysiwyg.install - Add anchor plugin to standard and full input format and WYSIWYG.
File
- ./
panopoly_wysiwyg.install, line 377 - Install hooks for Panopoly WYSIWYG.
Code
function _panopoly_wysiwyg_set_editor_anchor($editor_id) {
if (!($editor = Editor::load($editor_id))) {
return;
}
// Only update ckeditor.
if ($editor
->getEditor() != 'ckeditor') {
return;
}
$settings = $editor
->get('settings');
if (!empty($settings['toolbar']['rows'])) {
// Iterate through all the rows and groups to ensure we don't already have
// the anchor plugin.
foreach ($settings['toolbar']['rows'] as $rowId => $row) {
foreach ($row as $groupId => $group) {
if (in_array('panopoly_wysiwyg_anchor', $group['items'])) {
return;
}
}
}
foreach ($settings['toolbar']['rows'] as $rowId => $row) {
foreach ($row as $groupId => $group) {
// Look for link and unlink plugins in the same group, place after last
// of those two.
$lpos = array_search('DrupalLink', $group['items']);
$upos = array_search('DrupalUnlink', $group['items']);
if ($lpos === FALSE || $upos === FALSE) {
continue;
}
$pos = max($lpos, $upos) + 1;
array_splice($group['items'], $pos, 0, [
'panopoly_wysiwyg_anchor',
]);
$settings['toolbar']['rows'][$rowId][$groupId] = $group;
$editor
->setSettings($settings);
$editor
->save();
return;
}
}
}
}