You are here

class SocialCommentUploadConfigOverride in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  2. 8 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  3. 8.2 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  4. 8.3 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  5. 8.4 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  6. 8.5 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  7. 8.6 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  8. 8.7 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  9. 8.8 modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  10. 10.3.x modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  11. 10.1.x modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride
  12. 10.2.x modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php \Drupal\social_comment_upload\SocialCommentUploadConfigOverride

Class SocialCommentUploadConfigOverride.

Example configuration override.

@package Drupal\social_comment_upload

Hierarchy

Expanded class hierarchy of SocialCommentUploadConfigOverride

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

File

modules/social_features/social_comment_upload/src/SocialCommentUploadConfigOverride.php, line 17

Namespace

Drupal\social_comment_upload
View source
class SocialCommentUploadConfigOverride implements ConfigFactoryOverrideInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs the configuration override.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The Drupal configuration factory.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * Returns config overrides.
   */
  public function loadOverrides($names) {
    $overrides = [];

    // We don't need to add any fields if uploads are disabled.
    // We use getEditable and getOriginal to avoid override loops.
    if ($this->configFactory
      ->getEditable('social_comment_upload.settings')
      ->getOriginal('allow_upload_comments', TRUE) == FALSE) {
      return $overrides;
    }

    // Add field_group and field_comment_files.
    $config_name = 'core.entity_form_display.comment.comment.default';
    if (in_array($config_name, $names)) {
      $third_party = [
        'field_group' => [
          'group_add_attachment' => [
            'children' => [
              'field_comment_files',
            ],
            'parent_name' => '',
            'weight' => 20,
            'format_type' => 'details',
            'format_settings' => [
              'label' => 'Add attachment',
              'required_fields' => TRUE,
              'id' => '',
              'classes' => 'comment-attachments',
              'open' => FALSE,
            ],
            'label' => 'Add attachment',
            'region' => 'content',
          ],
        ],
      ];
      $content = [
        'field_comment_files' => [
          'weight' => 1,
          'settings' => [
            'progress_indicator' => 'throbber',
          ],
          'third_party_settings' => [],
          'type' => 'file_generic',
          'region' => 'content',
        ],
      ];
      $overrides[$config_name] = [
        'third_party_settings' => $third_party,
        'content' => $content,
      ];
    }

    // Add field_comment_files.
    $config_name = 'core.entity_view_display.comment.comment.default';
    if (in_array($config_name, $names)) {
      $content = [
        'field_comment_files' => [
          'weight' => 1,
          'label' => 'hidden',
          'settings' => [
            'image_style' => 'social_x_large',
            'image_link' => '',
          ],
          'third_party_settings' => [],
          'type' => 'file_image_default',
          'region' => 'content',
        ],
      ];
      $overrides[$config_name] = [
        'content' => $content,
      ];
    }
    return $overrides;
  }

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

  /**
   * {@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
SocialCommentUploadConfigOverride::$configFactory protected property The config factory.
SocialCommentUploadConfigOverride::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
SocialCommentUploadConfigOverride::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
SocialCommentUploadConfigOverride::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
SocialCommentUploadConfigOverride::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides
SocialCommentUploadConfigOverride::__construct public function Constructs the configuration override.