protected function SocialEmbedConfigOverride::addEditorOverride in Open Social 8.5
Same name and namespace in other branches
- 8.9 modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 8.4 modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 8.6 modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 8.7 modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 8.8 modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 10.3.x modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 10.0.x modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 10.1.x modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
- 10.2.x modules/social_features/social_embed/src/SocialEmbedConfigOverride.php \Drupal\social_embed\SocialEmbedConfigOverride::addEditorOverride()
Alters the editor settings for the text format.
Parameters
string $text_format: The text format to adjust.
array $overrides: An override configuration.
1 call to SocialEmbedConfigOverride::addEditorOverride()
- SocialEmbedConfigOverride::loadOverrides in modules/
social_features/ social_embed/ src/ SocialEmbedConfigOverride.php - Returns config overrides.
File
- modules/
social_features/ social_embed/ src/ SocialEmbedConfigOverride.php, line 124
Class
- SocialEmbedConfigOverride
- Class SocialEmbedConfigOverride.
Namespace
Drupal\social_embedCode
protected function addEditorOverride($text_format, array &$overrides) {
$config_name = 'editor.editor.' . $text_format;
/* @var \Drupal\Core\Config\Config $config */
$config = $this->configFactory
->getEditable($config_name);
$settings = $config
->get('settings');
// Ensure we have an existing row that the button can be added to.
if (empty($settings) || !isset($settings['toolbar']['rows']) || !is_array($settings['toolbar']['rows'])) {
return;
}
$overrides = [];
$button_exists = FALSE;
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
foreach ($group['items'] as $button) {
if ($button === 'social_embed') {
$button_exists = TRUE;
break 3;
}
}
}
}
// If the button already exists we change nothing.
if (!$button_exists) {
$row_array_keys = array_keys($settings['toolbar']['rows']);
$last_row_key = end($row_array_keys);
// Ensure we add our button at the end of the row.
// We use count to avoid issues when keys are non-numeric (even though
// that shouldn't happen). This will break if the keys are non-consecutive
// (which should also never happen).
$group_key = count($settings['toolbar']['rows'][$last_row_key]) + 1;
// Add the button as a new group to the bottom row as the last item.
$group = [
'name' => 'Embed',
'items' => [
'social_embed',
],
];
$overrides[$config_name]['settings']['toolbar']['rows'][$last_row_key][$group_key] = $group;
}
}