You are here

class PirateDayCacheabilityMetadataConfigOverride in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php \Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride

Test implementation of a config override that provides cacheability metadata.

Hierarchy

Expanded class hierarchy of PirateDayCacheabilityMetadataConfigOverride

1 string reference to 'PirateDayCacheabilityMetadataConfigOverride'
config_override_test.services.yml in core/modules/config/tests/config_override_test/config_override_test.services.yml
core/modules/config/tests/config_override_test/config_override_test.services.yml
1 service uses PirateDayCacheabilityMetadataConfigOverride
config_override_test.pirate_day_cacheability_metadata_override in core/modules/config/tests/config_override_test/config_override_test.services.yml
Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride

File

core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php, line 18
Contains \Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride.

Namespace

Drupal\config_override_test
View source
class PirateDayCacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {

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

    // Override the theme and the 'call_to_action' block on Pirate Day.
    if (PirateDayCacheContext::isPirateDay()) {
      if (in_array('system.theme', $names)) {
        $overrides = $overrides + [
          'system.theme' => [
            'default' => 'pirate',
          ],
        ];
      }
      if (in_array('block.block.call_to_action', $names)) {
        $overrides = $overrides + [
          'block.block.call_to_action' => [
            'settings' => [
              'label' => 'Draw yer cutlasses!',
            ],
          ],
        ];
      }
    }
    return $overrides;
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($name) {
    $metadata = new CacheableMetadata();
    $metadata
      ->setCacheContexts([
      'pirate_day',
    ])
      ->setCacheTags([
      'pirate-day-tag',
    ])
      ->setCacheMaxAge(PirateDayCacheContext::PIRATE_DAY_MAX_AGE);
    return $metadata;
  }

  /**
   * Returns whether or not our overrides are potentially applicable.
   *
   * @param string $name
   *   The name of the config object that is being constructed.
   *
   * @return bool
   *   TRUE if the merchant ship will be boarded. FALSE if we drink rum instead.
   */
  protected function isCacheabilityMetadataApplicable($name) {
    return in_array($name, [
      'system.theme',
      'block.block.call_to_action',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PirateDayCacheabilityMetadataConfigOverride::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
PirateDayCacheabilityMetadataConfigOverride::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
PirateDayCacheabilityMetadataConfigOverride::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
PirateDayCacheabilityMetadataConfigOverride::isCacheabilityMetadataApplicable protected function Returns whether or not our overrides are potentially applicable.
PirateDayCacheabilityMetadataConfigOverride::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides