You are here

public function SocialAlbumConfigOverride::loadOverrides in Open Social 10.1.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_album/src/SocialAlbumConfigOverride.php \Drupal\social_album\SocialAlbumConfigOverride::loadOverrides()
  2. 10.0.x modules/social_features/social_album/src/SocialAlbumConfigOverride.php \Drupal\social_album\SocialAlbumConfigOverride::loadOverrides()
  3. 10.2.x modules/social_features/social_album/src/SocialAlbumConfigOverride.php \Drupal\social_album\SocialAlbumConfigOverride::loadOverrides()

Returns config overrides.

Parameters

array $names: A list of configuration names that are being loaded.

Return value

array An array keyed by configuration name of override data. Override data contains a nested array structure of overrides.

Overrides ConfigFactoryOverrideInterface::loadOverrides

File

modules/social_features/social_album/src/SocialAlbumConfigOverride.php, line 48

Class

SocialAlbumConfigOverride
Provides an overridden elements.

Namespace

Drupal\social_album

Code

public function loadOverrides($names) {
  $overrides = [];
  $config_names = [
    'core.entity_form_display.post.photo.default',
    'core.entity_form_display.post.photo.group',
    'core.entity_form_display.post.photo.profile',
  ];
  foreach ($config_names as $config_name) {
    if (in_array($config_name, $names)) {
      $fields = $this->configFactory
        ->getEditable($config_name)
        ->get('content');
      $weight = $fields['field_post_image']['weight'] + 1;
      foreach ($fields as &$field) {
        if ($field['weight'] >= $weight) {
          $field['weight']++;
        }
      }
      $fields['field_album'] = [
        'weight' => $weight,
        'settings' => [],
        'third_party_settings' => [],
        'type' => 'social_album_options_select',
        'region' => 'content',
      ];
      $overrides[$config_name] = self::DEPENDENCY + [
        'content' => $fields,
      ];
    }
  }
  $config_name = 'core.entity_view_display.post.photo.default';
  if (in_array($config_name, $names)) {
    $overrides[$config_name] = self::DEPENDENCY + [
      'hidden' => [
        'field_album' => TRUE,
      ],
    ];
  }
  $config_name = 'core.entity_view_display.post.photo.activity';
  if (in_array($config_name, $names)) {
    $overrides[$config_name] = self::DEPENDENCY + [
      'dependencies' => [
        'module' => [
          'social_album' => 'social_album',
        ],
      ],
      'content' => [
        'field_album' => [
          'type' => 'social_album_entity_reference_label',
          'weight' => 5,
          'region' => 'content',
          'label' => 'hidden',
          'settings' => [
            'link' => TRUE,
          ],
          'third_party_settings' => [],
        ],
      ],
    ];
  }
  $config_name = 'like_and_dislike.settings';
  if (in_array($config_name, $names)) {
    $overrides[$config_name] = [
      'enabled_types' => [
        'node' => [
          'album' => 'album',
        ],
      ],
    ];
  }
  $config_names = [
    'search_api.index.social_all',
    'search_api.index.social_content',
  ];
  foreach ($config_names as $config_name) {
    if (in_array($config_name, $names)) {
      $overrides[$config_name] = [
        'datasource_settings' => [
          'entity:node' => [
            'bundles' => [
              'selected' => [
                'album' => 'album',
              ],
            ],
          ],
        ],
      ];
    }
  }
  $config_names = [
    'core.entity_form_display.node.album.default',
  ];
  foreach ($config_names as $config_name) {
    if (in_array($config_name, $names)) {
      $config = \Drupal::service('config.factory')
        ->getEditable($config_name);

      // Add the field to the content.
      $content = $config
        ->get('content');
      $content['groups'] = [];
      $content['groups']['type'] = 'social_group_selector_widget';
      $content['groups']['settings'] = [];
      $content['groups']['region'] = 'content';
      $content['groups']['third_party_settings'] = [];
      $overrides[$config_name] = [
        'content' => $content,
      ];
    }
  }
  return $overrides;
}