You are here

class SocialLazyLoadingTextFormatOverride in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php \Drupal\social_lazy_loading\SocialLazyLoadingTextFormatOverride
  2. 8.6 modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php \Drupal\social_lazy_loading\SocialLazyLoadingTextFormatOverride
  3. 8.7 modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php \Drupal\social_lazy_loading\SocialLazyLoadingTextFormatOverride
  4. 8.8 modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php \Drupal\social_lazy_loading\SocialLazyLoadingTextFormatOverride
  5. 10.3.x modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php \Drupal\social_lazy_loading\SocialLazyLoadingTextFormatOverride
  6. 10.0.x modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php \Drupal\social_lazy_loading\SocialLazyLoadingTextFormatOverride
  7. 10.2.x modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php \Drupal\social_lazy_loading\SocialLazyLoadingTextFormatOverride

Class SocialLazyLoadingTextFormatOverride.

@package Drupal\social_lazy_loading

Hierarchy

Expanded class hierarchy of SocialLazyLoadingTextFormatOverride

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

File

modules/custom/social_lazy_loading/src/SocialLazyLoadingTextFormatOverride.php, line 15

Namespace

Drupal\social_lazy_loading
View source
class SocialLazyLoadingTextFormatOverride implements ConfigFactoryOverrideInterface {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs the configuration override.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public function loadOverrides($names) {
    $overrides = [];
    $formats = [
      'basic_html' => TRUE,
      'full_html' => TRUE,
      'plain_text' => TRUE,
      'simple_text' => TRUE,
      'restricted_html' => TRUE,
      'mail_html' => TRUE,
    ];
    $this->moduleHandler
      ->alter('social_lazy_loading_formats', $formats);
    foreach ($formats as $format => $convert_url) {
      if (in_array('filter.format.' . $format, $names, FALSE)) {
        $this
          ->addFilterOverride($format, $convert_url, $overrides);
      }
    }

    // Set lazy loading settings.
    if (in_array('lazy.settings', $names, FALSE)) {
      $overrides['lazy.settings']['alter_tag'] = [
        'img' => 'img',
        'iframe' => 'iframe',
      ];
    }
    return $overrides;
  }

  /**
   * Alters the filter settings for the text format.
   *
   * @param string $text_format
   *   A config name.
   * @param bool $convert_url
   *   TRUE if filter should be used.
   * @param array $overrides
   *   An override configuration.
   */
  protected function addFilterOverride($text_format, $convert_url, array &$overrides) {
    $config_name = 'filter.format.' . $text_format;
    if ($convert_url) {
      $overrides[$config_name]['dependencies']['module']['lazy'] = 'lazy';
      $overrides[$config_name]['filters']['lazy_filter'] = [
        'id' => 'lazy_filter',
        'provider' => 'lazy',
        'status' => TRUE,
        'weight' => 999,
        'settings' => [],
      ];
    }
  }

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

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
SocialLazyLoadingTextFormatOverride::$moduleHandler protected property The module handler.
SocialLazyLoadingTextFormatOverride::addFilterOverride protected function Alters the filter settings for the text format.
SocialLazyLoadingTextFormatOverride::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
SocialLazyLoadingTextFormatOverride::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
SocialLazyLoadingTextFormatOverride::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
SocialLazyLoadingTextFormatOverride::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides
SocialLazyLoadingTextFormatOverride::__construct public function Constructs the configuration override.