-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dominic Tubach
committed
Feb 22, 2024
1 parent
cb8e8a5
commit 1b9cf2a
Showing
10 changed files
with
285 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) 2023 SYSTOPIA GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\civiremote_funding\Api\DTO; | ||
|
||
/** | ||
* @phpstan-type templateT array{ | ||
* id: int, | ||
* label: string, | ||
* } | ||
* | ||
* @phpstan-extends AbstractDTO<templateT> | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
final class ApplicationProcessTemplate extends AbstractDTO { | ||
|
||
public function getId(): int { | ||
return $this->values['id']; | ||
} | ||
|
||
public function getLabel(): string { | ||
return $this->values['label']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) 2024 SYSTOPIA GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\civiremote_funding\Controller; | ||
|
||
use Drupal\civiremote_funding\Api\FundingApi; | ||
use Drupal\civiremote_funding\RemotePage\RemotePageProxy; | ||
use Drupal\Core\Controller\ControllerBase; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class ApplicationTemplateRenderController extends ControllerBase { | ||
|
||
private FundingApi $fundingApi; | ||
|
||
private RemotePageProxy $remotePageProxy; | ||
|
||
public function __construct( | ||
FundingApi $fundingApi, | ||
RemotePageProxy $remotePageProxy | ||
) { | ||
$this->fundingApi = $fundingApi; | ||
$this->remotePageProxy = $remotePageProxy; | ||
} | ||
|
||
public function render(int $applicationProcessId, int $templateId): Response { | ||
$uri = $this->getDownloadUri($applicationProcessId, $templateId); | ||
|
||
return $this->remotePageProxy->get($uri); | ||
} | ||
|
||
private function getDownloadUri(int $applicationProcessId, int $templateId): string { | ||
return $this->fundingApi->getApplicationTemplateRenderUri($applicationProcessId, $templateId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) 2024 SYSTOPIA GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\civiremote_funding\Views; | ||
|
||
use Drupal\civiremote_funding\Api\FundingApi; | ||
use Drupal\Core\Url; | ||
use Drupal\views\Plugin\views\field\Dropbutton; | ||
use Drupal\views\ResultRow; | ||
|
||
/** | ||
* Acts like a decorator (a real decorator is not possible) to add application | ||
* process document creation links. | ||
*/ | ||
final class ApplicationProcessDropButton extends Dropbutton { | ||
|
||
private FundingApi $fundingApi; | ||
|
||
private ?int $applicationProcessId = NULL; | ||
|
||
public function __construct(FundingApi $fundingApi, Dropbutton $dropbutton) { | ||
$this->fundingApi = $fundingApi; | ||
parent::__construct($dropbutton->configuration, $dropbutton->getPluginId(), $dropbutton->getPluginDefinition()); | ||
// @phpstan-ignore-next-line | ||
if (NULL !== $dropbutton->view) { | ||
$this->init($dropbutton->view, $dropbutton->view->getDisplay(), $dropbutton->options); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(ResultRow $values) { | ||
// @phpstan-ignore-next-line | ||
foreach ($values as $key => $value) { | ||
if (str_ends_with($key, '_application_process_id')) { | ||
$this->applicationProcessId = $value; | ||
|
||
break; | ||
} | ||
} | ||
|
||
try { | ||
return parent::render($values); | ||
} | ||
finally { | ||
$this->applicationProcessId = NULL; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @phpstan-return array<mixed> | ||
* | ||
* @throws \Drupal\civiremote_funding\Api\Exception\ApiCallFailedException | ||
*/ | ||
protected function getLinks(): array { | ||
$links = parent::getLinks(); | ||
if (NULL === $this->applicationProcessId) { | ||
// Should not happen. | ||
return $links; | ||
} | ||
|
||
foreach ($this->fundingApi->getApplicationTemplates($this->applicationProcessId) as $template) { | ||
$links[] = [ | ||
'url' => Url::fromRoute('civiremote_funding.application_template_render', [ | ||
'applicationProcessId' => $this->applicationProcessId, | ||
'templateId' => $template->getId(), | ||
]), | ||
'title' => $this->t('Create: @label', ['@label' => $template->getLabel()]), | ||
'attributes' => [ | ||
'target' => '_blank', | ||
], | ||
]; | ||
} | ||
|
||
return $links; | ||
} | ||
|
||
} |
Oops, something went wrong.