Skip to content
Snippets Groups Projects
Commit 6831ed70 authored by Sourabh Jain's avatar Sourabh Jain Committed by Vitalii Podoba
Browse files

Issue #3425194 by nilesh.addweb, sourabhjain, hitchshock: PHPCS and PHPStan errors

parent c05cc580
No related branches found
No related tags found
1 merge request!3#3425194: Phpcs and phpstan errors
Pipeline #349620 passed
filefield
Ghostscript
Spatie
\ No newline at end of file
......@@ -60,7 +60,7 @@ composer:
extends: .composer-base
before_script:
- sudo apt-get update
- apt-get install -y libmagickwand-dev
- apt-get install -y libmagickwand-dev pkg-config build-essential
- pecl install imagick
- docker-php-ext-enable imagick
......
......@@ -52,8 +52,10 @@ With the above configs set up right, you can now
* If you delete the image(s), an image of the PDF will be regenerated.
* If you upload non PDF file then:
* If 'Process only PDF files' option is enabled, non PDF files will be ignored
* If 'Process only PDF files' option is disabled, non PDF files will copied to the target field without changes
* In this case make sure that the field extensions are compatible in both fields
* If 'Process only PDF files' option is disabled,
non PDF files will copied to the target field without changes
* In this case make sure that the field extensions are compatible in both
fields
## Troubleshooting ##
......@@ -67,4 +69,4 @@ the command that was run and see what failed.
Processing of PDF may take some time.
Larger documents use the 'batch' process to generate each page.
\ No newline at end of file
Larger documents use the 'batch' process to generate each page.
......@@ -3,11 +3,8 @@
"type": "drupal-module",
"description": "Imports PDF file and split pages into image field files",
"homepage": "https://www.drupal.org/project/pdf_to_imagefield",
"license": "GPL-2.0+",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.4.0",
"drupal/core": "^9.5 || ^10",
"ext-soap": "*",
"spatie/pdf-to-image": "^2.2"
},
"minimum-stability": "dev"
......
parameters:
ignoreErrors:
-
message: """
#^Fetching deprecated class constant EXISTS_ERROR of interface Drupal\\\\Core\\\\File\\\\FileSystemInterface\\:
in drupal\\:10\\.3\\.0 and is removed from drupal\\:12\\.0\\.0\\. Use
\\\\Drupal\\\\Core\\\\File\\\\FileExists\\:\\:Error instead\\.$#
"""
count: 1
path: src/PDFToImageBatchHelper.php
-
message: """
#^Fetching deprecated class constant EXISTS_RENAME of interface Drupal\\\\Core\\\\File\\\\FileSystemInterface\\:
in drupal\\:10\\.3\\.0 and is removed from drupal\\:12\\.0\\.0\\. Use
\\\\Drupal\\\\Core\\\\File\\\\FileExists\\:\\:Rename instead\\.$#
"""
count: 1
path: src/PDFToImageBatchHelper.php
......@@ -88,7 +88,7 @@ class PDFToImageBatchHelper {
}
/**
* Retrieve messanger.
* Retrieve messenger.
*
* @return \Drupal\Core\Messenger\MessengerInterface
* Message interface
......@@ -151,7 +151,7 @@ class PDFToImageBatchHelper {
->saveImage($image_temp_path);
if (file_exists($image_temp_path)) {
// @todo logger about succesfull creation.
// @todo logger about successful creation.
}
$guesser = \Drupal::service('file.mime_type.guesser');
......
......@@ -7,10 +7,10 @@ use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityFieldManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\file\FileInterface;
use Drupal\pdf_to_imagefield\PDFToImageBatchHelper as BatchHelper;
use Spatie\PdfToImage\Pdf;
/**
......@@ -63,7 +63,7 @@ class PDFToImageManager implements PDFToImageManagerInterface {
EntityDisplayRepositoryInterface $entityDisplayRepository,
EntityTypeManagerInterface $entityTypeManager,
StreamWrapperManagerInterface $streamWrapperManager,
LoggerChannelInterface $logger
LoggerChannelInterface $logger,
) {
$this->logger = $logger;
$this->streamWrapperManager = $streamWrapperManager;
......@@ -158,7 +158,15 @@ class PDFToImageManager implements PDFToImageManagerInterface {
}
// Prepare data for PDF conversion.
$full_path = $this->streamWrapperManager->getViaUri($file->getFileUri())->realpath();
$uri = $file->getFileUri();
if ($uri === NULL) {
continue;
}
$stream_wrapper = $this->streamWrapperManager->getViaUri($uri);
if (!$stream_wrapper instanceof StreamWrapperInterface) {
continue;
}
$full_path = $stream_wrapper->realpath();
if (!file_exists($full_path)) {
$this->logger->error('Invalid file given to convert. Could not read %file (%source_file)',
[
......
......@@ -21,7 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* }
* )
*/
class PDFToImageWidget extends FileWidget {
final class PDFToImageWidget extends FileWidget {
/**
* Determine valid image formats.
......@@ -107,7 +107,7 @@ class PDFToImageWidget extends FileWidget {
'#title' => $this->t('Image field to convert PDF into'),
'#type' => 'select',
'#required' => TRUE,
'#options' => $this->pdfToImageManager->getImageTargetFields($entity_type_id, $bundle),
'#options' => $this->pdfToImageManager->getImageTargetFields($entity_type_id, $bundle ?? $entity_type_id),
'#default_value' => $this->getSetting('target_field'),
'#description' => $this->t('A list of available image fields to attach PDF conversion'),
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment