-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render app credential warnings with BigPipe
- Loading branch information
Showing
8 changed files
with
142 additions
and
8 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
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,72 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Copyright 2023 Google Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* version 2 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, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
namespace Drupal\apigee_edge\LazyBuilder; | ||
|
||
use Drupal\apigee_edge\Entity\AppInterface; | ||
use Drupal\Core\Security\TrustedCallbackInterface; | ||
|
||
/** | ||
* Lazy builder for app credential warnings. | ||
*/ | ||
final class AppWarningsLazyBuilder implements TrustedCallbackInterface { | ||
|
||
/** | ||
* Lazy builds app credentials warnings. | ||
* | ||
* @param string $entity_type_id | ||
* The type of the entity, either "developer_app" or "team_app". | ||
* @param string $id | ||
* The entity id. | ||
* | ||
* @return array | ||
* A render array with warnings. | ||
*/ | ||
public static function lazyBuilder(string $entity_type_id, string $id): array { | ||
if (!in_array($entity_type_id, ['developer_app', 'team_app'], TRUE)) { | ||
throw new \LogicException(sprintf('Unexpected entity type: %s.', $entity_type_id)); | ||
} | ||
|
||
$entity = \Drupal::entityTypeManager()->getStorage($entity_type_id)->load($id); | ||
if ($entity instanceof AppInterface) { | ||
/** @var \Drupal\apigee_edge\Entity\AppWarningsCheckerInterface $app_warnings_checker */ | ||
$app_warnings_checker = \Drupal::service('apigee_edge.entity.app_warnings_checker'); | ||
$warnings = array_filter($app_warnings_checker->getWarnings($entity)); | ||
if (count($warnings) > 0) { | ||
return [ | ||
'#theme' => 'apigee_app_credential_warnings', | ||
'#warnings' => $warnings, | ||
]; | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function trustedCallbacks(): array { | ||
return ['lazyBuilder']; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
templates/apigee-app-credential-warnings-placeholder.html.twig
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,5 @@ | ||
<div class="app-credential-warnings"> | ||
<div class="app-credential-warning-placeholder"> | ||
<span>{{ 'Fetching crendential information...'|t }}</span> | ||
</div> | ||
</div> |
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,5 @@ | ||
<div class="app-credential-warnings"> | ||
{% for warning in warnings %} | ||
<div class="app-credential-warning">{{ warning }}</div> | ||
{% endfor %} | ||
</div> |