Skip to content

Commit

Permalink
Merge pull request #66 from systopia/cast-tile-to-string
Browse files Browse the repository at this point in the history
Cast `#title` to string
  • Loading branch information
dontub authored Sep 16, 2024
2 parents c51fee7 + 11906c4 commit 7010f5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/Element/CiviremoteFundingApplicationHistoryStatusChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ public static function preRenderActivity(array $element): array {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter */
$dateFormatter = \Drupal::service('date.formatter');

Assertion::string($element['#title']);
if (is_scalar($element['#title']) ||
(is_object($element['#title']) && method_exists($element['#title'], '__toString'))
) {
$element['#title'] = (string) $element['#title'];
}
else {
throw new \InvalidArgumentException('Expected string for "#title", got ' . gettype($element['#title']));
}

Assertion::isInstanceOf($element['#activity'], ApplicationProcessActivity::class);
$activity = $element['#activity'];

Expand Down
12 changes: 10 additions & 2 deletions src/Element/CiviremoteFundingClearingHistoryStatusChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getInfo(): array {
// Array mapping status to \Drupal\civiremote_funding\Api\DTO\Option.
// Instance of \Drupal\civiremote_funding\Api\DTO\Option.
'#status_option' => NULL,
'#title' => $this->t('Clearing Status: @status'),
'#title' => $this->t('Clearing Status: @status')->__toString(),
'#status_label' => NULL,
'#source_contact_title' => $this->t('Performed by'),
'#pre_render' => [
Expand All @@ -57,7 +57,15 @@ public static function preRenderActivity(array $element): array {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter */
$dateFormatter = \Drupal::service('date.formatter');

Assertion::string($element['#title']);
if (is_scalar($element['#title']) ||
(is_object($element['#title']) && method_exists($element['#title'], '__toString'))
) {
$element['#title'] = (string) $element['#title'];
}
else {
throw new \InvalidArgumentException('Expected string for "#title", got ' . gettype($element['#title']));
}

Assertion::isInstanceOf($element['#activity'], ApplicationProcessActivity::class);
$activity = $element['#activity'];

Expand Down

0 comments on commit 7010f5c

Please sign in to comment.