SocialEmbedEditorConfigOverride.php in Open Social 8.2
File
modules/social_features/social_embed/src/SocialEmbedEditorConfigOverride.php
View source
<?php
namespace Drupal\social_embed;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
class SocialEmbedEditorConfigOverride implements ConfigFactoryOverrideInterface {
public function loadOverrides($names) {
$overrides = [];
$config_names = [
'editor.editor.basic_html',
'editor.editor.full_html',
];
foreach ($config_names as $config_name) {
if (in_array($config_name, $names)) {
$config = \Drupal::service('config.factory')
->getEditable($config_name);
if ($settings = $config
->get('settings')) {
if (isset($settings['toolbar']['rows']) && is_array($settings['toolbar']['rows'])) {
$button_exists = FALSE;
foreach ($settings['toolbar']['rows'] as $row_id => $row) {
foreach ($row as $group_id => $group) {
foreach ($group['items'] as $button_id => $button) {
if ($button === 'social_embed') {
$button_exists = TRUE;
}
}
}
}
if ($button_exists === FALSE) {
$row_array_keys = array_keys($settings['toolbar']['rows']);
$last_row_key = end($row_array_keys);
$group = [];
$group['name'] = 'Embed';
$group['items'] = [];
$group['items'][] = 'social_embed';
$settings['toolbar']['rows'][$last_row_key][] = $group;
$overrides[$config_name] = [
'settings' => $settings,
];
}
}
}
}
}
return $overrides;
}
public function getCacheSuffix() {
return 'SocialEmbedEditorConfigOverride';
}
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
}