public static function DeveloperAppFormTrait::appExists in Apigee Edge 8
File
- src/Entity/Form/DeveloperAppFormTrait.php, line 44
Class
- DeveloperAppFormTrait
- Helper trait that contains developer app (create/edit) form specific tweaks.
Namespace
Drupal\apigee_edge\Entity\Form
Code
public static function appExists(string $name, array $element, FormStateInterface $form_state) : bool {
if ($name === '') {
return FALSE;
}
if ($form_state
->getValue('owner') === NULL) {
return TRUE;
}
$factory = \Drupal::service('apigee_edge.controller.developer_app_controller_factory');
$app = TRUE;
try {
$app = $factory
->developerAppController($form_state
->getValue('owner'))
->load($name);
} catch (ApiException $exception) {
if ($exception instanceof ClientErrorException && $exception
->getEdgeErrorCode() === 'developer.service.AppDoesNotExist') {
$app = FALSE;
}
else {
$context = [
'%app_name' => $name,
'%owner' => $form_state
->getValue('owner'),
];
$context += Error::decodeException($exception);
\Drupal::logger('apigee_edge')
->error("Unable to properly validate an app name's uniqueness. App name: %app_name. Owner: %owner. @message %function (line %line of %file). <pre>@backtrace_string</pre>", $context);
}
}
return (bool) $app;
}