You are here

abstract class ContentTranslationConfigOverrideBase in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  2. 8.4 modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  3. 8.5 modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  4. 8.6 modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  5. 8.7 modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  6. 8.8 modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  7. 10.3.x modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  8. 10.0.x modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase
  9. 10.2.x modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php \Drupal\social_core\ContentTranslationConfigOverrideBase

Provides a base class for configurable content translation config overrides.

@package Drupal\social_core

Hierarchy

Expanded class hierarchy of ContentTranslationConfigOverrideBase

4 files declare their use of ContentTranslationConfigOverrideBase
ContentTranslationDefaultsConfigOverride.php in modules/social_features/social_landing_page/src/ContentTranslationDefaultsConfigOverride.php
ContentTranslationDefaultsConfigOverride.php in modules/social_features/social_page/src/ContentTranslationDefaultsConfigOverride.php
ContentTranslationDefaultsConfigOverride.php in modules/social_features/social_book/src/ContentTranslationDefaultsConfigOverride.php
ContentTranslationDefaultsConfigOverride.php in modules/social_features/social_event/src/ContentTranslationDefaultsConfigOverride.php

File

modules/social_features/social_core/src/ContentTranslationConfigOverrideBase.php, line 14

Namespace

Drupal\social_core
View source
abstract class ContentTranslationConfigOverrideBase implements ConfigFactoryOverrideInterface {

  /**
   * Returns the configuration override for this module's translations.
   *
   * By making this a separate method it can easily be overwritten in child
   * classes without having to duplicate the logic of whether it should be
   * invoked.
   *
   * @return array
   *   An array keyed by configuration name with the override as value.
   */
  protected abstract function getTranslationOverrides();

  /**
   * Returns the module that provides the overrides.
   *
   * This is used as the social_contant_translation.settings configuration key
   * as well as in the cache suffix for the overrides.
   *
   * @return string
   *   The module name providing the overrides.
   */
  protected abstract function getModule();

  /**
   * Returns the display name for this set of configuration overrides.
   *
   * This can be used in a user interface to let sitemanagers determine which
   * parts of Open Social should be translatable. For consistency when
   * displaying this should always be a plural string.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup|string
   *   The (translatable) string that can be shown to the user.
   */
  protected abstract function getDisplayName();

  /**
   * {@inheritdoc}
   */
  public function loadOverrides($names) {
    $overrides = [];

    // This setting can't be changed in an override because that would create
    // and endless loop in trying to apply the override.
    $settings = \Drupal::configFactory()
      ->getEditable('social_content_translation.settings');
    $is_enabled = $settings
      ->getOriginal($this
      ->getModule(), FALSE);
    if ($is_enabled) {
      $translation_overrides = $this
        ->getTranslationOverrides();
      foreach ($translation_overrides as $name => $override) {
        if (in_array($name, $names)) {
          $overrides[$name] = $override;
        }
      }
    }
    return $overrides;
  }

  /**
   * Returns the configurations that are overridden in this class.
   *
   * @return array
   *   An array of configuration names.
   */
  protected function getOverriddenConfigurations() {
    return array_keys($this
      ->getTranslationOverrides());
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheSuffix() {
    return $this
      ->getModule() . '.content_translation_defaults_config_override';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($name) {
    $metadata = new CacheableMetadata();
    if (in_array($name, $this
      ->getOverriddenConfigurations())) {
      $metadata
        ->addCacheTags([
        'config:social_content_translation.settings',
      ]);
    }
    return $metadata;
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
ContentTranslationConfigOverrideBase::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
ContentTranslationConfigOverrideBase::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
ContentTranslationConfigOverrideBase::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
ContentTranslationConfigOverrideBase::getDisplayName abstract protected function Returns the display name for this set of configuration overrides. 4
ContentTranslationConfigOverrideBase::getModule abstract protected function Returns the module that provides the overrides. 4
ContentTranslationConfigOverrideBase::getOverriddenConfigurations protected function Returns the configurations that are overridden in this class.
ContentTranslationConfigOverrideBase::getTranslationOverrides abstract protected function Returns the configuration override for this module's translations. 4
ContentTranslationConfigOverrideBase::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides