You are here

class SocialEmbedEditorConfigOverride in Open Social 8

Same name and namespace in other branches
  1. 8.2 modules/social_features/social_embed/src/SocialEmbedEditorConfigOverride.php \Drupal\social_embed\SocialEmbedEditorConfigOverride
  2. 8.3 modules/social_features/social_embed/src/SocialEmbedEditorConfigOverride.php \Drupal\social_embed\SocialEmbedEditorConfigOverride

Class SocialEmbedEditorConfigOverride.

@package Drupal\social_embed

Hierarchy

Expanded class hierarchy of SocialEmbedEditorConfigOverride

2 string references to 'SocialEmbedEditorConfigOverride'
SocialEmbedEditorConfigOverride::getCacheSuffix in modules/social_features/social_embed/src/SocialEmbedEditorConfigOverride.php
The string to append to the configuration static cache name.
social_embed.services.yml in modules/social_features/social_embed/social_embed.services.yml
modules/social_features/social_embed/social_embed.services.yml
1 service uses SocialEmbedEditorConfigOverride
social_embed_editor.overrider in modules/social_features/social_embed/social_embed.services.yml
\Drupal\social_embed\SocialEmbedEditorConfigOverride

File

modules/social_features/social_embed/src/SocialEmbedEditorConfigOverride.php, line 14

Namespace

Drupal\social_embed
View source
class SocialEmbedEditorConfigOverride implements ConfigFactoryOverrideInterface {

  /**
   * {@inheritdoc}
   */
  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)) {

        /* @var \Drupal\Core\Config\ConfigFactory $config */
        $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;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheSuffix() {
    return 'SocialEmbedEditorConfigOverride';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($name) {
    return new CacheableMetadata();
  }

  /**
   * {@inheritdoc}
   */
  public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialEmbedEditorConfigOverride::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
SocialEmbedEditorConfigOverride::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
SocialEmbedEditorConfigOverride::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
SocialEmbedEditorConfigOverride::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides