You are here

public function ImageStyleConfiguration::saveToActiveStore in Configuration Management 7.2

Implements Drupal\configuration\Config\Configuration::saveToActiveStore().

Overrides Configuration::saveToActiveStore

File

lib/Drupal/configuration/Config/ImageStyleConfiguration.php, line 123
Definition of Drupal\configuration\Config\ImageStyleConfiguration.

Class

ImageStyleConfiguration

Namespace

Drupal\configuration\Config

Code

public function saveToActiveStore(ConfigIteratorSettings &$settings) {
  $style = $this
    ->getData();

  // Does an image style with the same name already exist?
  if ($existing_style = image_style_load($this
    ->getIdentifier())) {
    $isExistingEditable = (bool) ($existing_style['storage'] & IMAGE_STORAGE_EDITABLE);
    $isNewEditable = (bool) ($style['storage'] & IMAGE_STORAGE_EDITABLE);

    // New style is using defaults -> revert existing.
    if (!$isNewEditable && $isExistingEditable) {
      image_default_style_revert($this
        ->getIdentifier());
    }
    elseif ($isExistingEditable && $isNewEditable) {
      $style['isid'] = $existing_style['isid'];
      $style = image_style_save($style);
      if (!empty($existing_style['effects'])) {
        foreach ($existing_style['effects'] as $effect) {
          image_effect_delete($effect);
        }
      }
      if (!empty($style['effects'])) {
        foreach ($style['effects'] as $effect) {
          $effect['isid'] = $style['isid'];
          image_effect_save($effect);
        }
      }
    }
    elseif ($isNewEditable && !$isExistingEditable) {
      if (!empty($existing_style['isid'])) {
        $style['isid'] = $existing_style['isid'];
      }
      $style = image_style_save($style);
      if (!empty($style['effects'])) {
        foreach ($style['effects'] as $effect) {
          $effect['isid'] = $style['isid'];
          image_effect_save($effect);
        }
      }
    }
    else {
    }
  }
  else {
    $style = image_style_save($style);
    if (!empty($style['effects'])) {
      foreach ($style['effects'] as $effect) {
        $effect['isid'] = $style['isid'];
        image_effect_save($effect);
      }
    }
    image_style_flush($style);
  }
  $settings
    ->addInfo('imported', $this
    ->getUniqueId());
}