Skip to content

Commit

Permalink
Merge pull request #8 from bolt/feature/configure-thumbnailing-option
Browse files Browse the repository at this point in the history
Allow thumbnailing images to be configured
  • Loading branch information
bobdenotter authored Oct 17, 2020
2 parents 8683f0b + 465a15d commit fce1f19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ default:
'4|8': 'col-4|col-8'
'6|6': 'col-6|col-6'
'8|4': 'col-8|col-4'
image:
thumbnail: 1000×1000×max

plugins:
~
1 change: 1 addition & 0 deletions src/ArticleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private function getDefaults(): array
'_csrf_token' => $this->csrfTokenManager->getToken('bolt_article')->getValue(),
],
'multiple' => false,
'thumbnail' => '1000×1000×max',
],
'minHeight' => '200px',
'maxHeight' => '700px',
Expand Down
11 changes: 9 additions & 2 deletions src/Controller/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Bolt\Article\Controller;

use Bolt\Article\ArticleConfig;
use Bolt\Configuration\Config;
use Bolt\Controller\Backend\Async\AsyncZoneInterface;
use Bolt\Controller\CsrfTrait;
Expand Down Expand Up @@ -37,12 +38,16 @@ class Upload implements AsyncZoneInterface
/** @var Request */
private $request;

public function __construct(Config $config, CsrfTokenManagerInterface $csrfTokenManager, TextExtension $textExtension, RequestStack $requestStack)
/** @var ArticleConfig */
private $articleConfig;

public function __construct(Config $config, CsrfTokenManagerInterface $csrfTokenManager, TextExtension $textExtension, RequestStack $requestStack, ArticleConfig $articleConfig)
{
$this->config = $config;
$this->csrfTokenManager = $csrfTokenManager;
$this->textExtension = $textExtension;
$this->request = $requestStack->getCurrentRequest();
$this->articleConfig = $articleConfig;
}

/**
Expand Down Expand Up @@ -102,9 +107,11 @@ public function handleUpload(Request $request): JsonResponse
}

if ($result->isValid()) {
$thumbnail = '/thumbs/' . $this->articleConfig->getConfig()['image']['thumbnail'] . '/';

$resultMessage = [
'filekey' => [
'url' => '/thumbs/1000×1000×max/' . $result->name,
'url' => $thumbnail . $result->name,
'id' => 1,
],
];
Expand Down

0 comments on commit fce1f19

Please sign in to comment.