You are here

xbbcode.install in Extensible BBCode 8.3

Update functions for the xbbcode module.

File

xbbcode.install
View source
<?php

/**
 * @file
 * Update functions for the xbbcode module.
 */
use Drupal\Core\Utility\UpdateException;

/**
 * Add an "xss" key to the filter settings.
 *
 * @throws \Drupal\Core\Utility\UpdateException
 *   If the update fails.
 */
function xbbcode_update_8300() {
  try {
    $storage = Drupal::entityTypeManager()
      ->getStorage('filter_format');

    /** @var \Drupal\filter\FilterFormatInterface[] $formats */
    $formats = $storage
      ->loadByProperties([
      'status' => TRUE,
    ]);
    foreach ($formats as $format) {
      $filters = $format
        ->filters();
      if ($filters
        ->has('xbbcode')) {
        $config = $filters
          ->get('xbbcode')
          ->getConfiguration();
        $config['settings']['xss'] = $config['settings']['xss'] ?? TRUE;
        $filters
          ->get('xbbcode')
          ->setConfiguration($config);
        $format
          ->save();
      }
    }
  } catch (Exception $exception) {
    throw new UpdateException('Error while updating XBBCode.', 0, $exception);
  }
}

Functions

Namesort descending Description
xbbcode_update_8300 Add an "xss" key to the filter settings.