Commit c36a6f60 authored by Kristof De Jaeger's avatar Kristof De Jaeger
Browse files

Issue #2954557 by schnippy: Fallback image not stored permanently

parent 486c21f3
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -3,9 +3,11 @@
namespace Drupal\imagecache_external\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\FileInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class SettingsForm extends ConfigFormBase {
@@ -24,6 +26,13 @@ class SettingsForm extends ConfigFormBase {
   */
  protected $configFactory;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new SettingsForm.
   *
@@ -32,9 +41,10 @@ class SettingsForm extends ConfigFormBase {
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(FileSystemInterface $fileSystem, ConfigFactoryInterface $config_factory) {
  public function __construct(FileSystemInterface $fileSystem, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
    $this->fileSystem = $fileSystem;
    $this->configFactory = $config_factory;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
@@ -43,7 +53,8 @@ class SettingsForm extends ConfigFormBase {
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('file_system'),
      $container->get('config.factory')
      $container->get('config.factory'),
      $container->get('entity_type.manager')
    );
  }

@@ -169,6 +180,13 @@ class SettingsForm extends ConfigFormBase {
    $fallback_image = 0;
    if (!empty($values['imagecache_fallback_image'])) {
      $fallback_image = $values['imagecache_fallback_image'][0];

      /** @var \Drupal\file\FileInterface $file */
      $file = $this->entityTypeManager->getStorage('file')->load($fallback_image);
      if ($file instanceof FileInterface && !$file->isPermanent()) {
        $file->setPermanent();
        $file->save();
      }
    }

    $this->config('imagecache_external.settings')