Skip to content

Commit

Permalink
Merge pull request #52 from systopia/improve-decoratability-of-Applic…
Browse files Browse the repository at this point in the history
…ationProcessDropButton

ApplicationProcessDropButton: Improve decoratability
  • Loading branch information
dontub authored May 17, 2024
2 parents 26c0a39 + 48c689b commit 0b71b8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions civiremote_funding.module
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function civiremote_funding_views_plugins_field_alter(array &$plugins): void {
$plugins['numeric']['class'] = LanguageAwareNumericField::class;
}

/**
* Implements hook_views_pre_build().
*/
function civiremote_funding_views_pre_build(ViewExecutable $view): void {
if (!in_array($view->id(), ['civiremote_funding_application_list', 'civiremote_funding_combined_application_process_list'], TRUE)) {
return;
Expand Down
16 changes: 10 additions & 6 deletions src/Views/ApplicationProcessDropButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
*/
final class ApplicationProcessDropButton extends Dropbutton {

private Dropbutton $dropbutton;

private FundingApi $fundingApi;

private ?int $applicationProcessId = NULL;

public function __construct(FundingApi $fundingApi, Dropbutton $dropbutton) {
$this->fundingApi = $fundingApi;
$this->dropbutton = $dropbutton;
parent::__construct($dropbutton->configuration, $dropbutton->getPluginId(), $dropbutton->getPluginDefinition());
// @phpstan-ignore-next-line
if (NULL !== $dropbutton->view) {
Expand All @@ -49,6 +52,8 @@ public function __construct(FundingApi $fundingApi, Dropbutton $dropbutton) {
* {@inheritDoc}
*/
public function render(ResultRow $values) {
$this->applicationProcessId = NULL;

// @phpstan-ignore-next-line
foreach ($values as $key => $value) {
if (str_ends_with($key, '_application_process_id')) {
Expand All @@ -58,12 +63,11 @@ public function render(ResultRow $values) {
}
}

try {
return parent::render($values);
}
finally {
$this->applicationProcessId = NULL;
if (get_class($this->dropbutton) !== Dropbutton::class) {
$this->dropbutton->render($values);
}

return parent::render($values);
}

/**
Expand All @@ -74,7 +78,7 @@ public function render(ResultRow $values) {
* @throws \Drupal\civiremote_funding\Api\Exception\ApiCallFailedException
*/
protected function getLinks(): array {
$links = parent::getLinks();
$links = $this->dropbutton->getLinks();
if (NULL === $this->applicationProcessId) {
// Should not happen.
return $links;
Expand Down

0 comments on commit 0b71b8e

Please sign in to comment.