Loading src/Form/SettingsForm.php +20 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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. * Loading @@ -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; } /** Loading @@ -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') ); } Loading Loading @@ -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') Loading Loading
src/Form/SettingsForm.php +20 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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. * Loading @@ -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; } /** Loading @@ -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') ); } Loading Loading @@ -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') Loading