You are here

public function ServerForm::validateForm in GraphQL 8.4

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides FormBase::validateForm

File

src/Form/ServerForm.php, line 225

Class

ServerForm
Admin form to set up a GraphQL server configuration entity.

Namespace

Drupal\graphql\Form

Code

public function validateForm(array &$form, FormStateInterface $formState) : void {
  $endpoint =& $formState
    ->getValue('endpoint');

  // Trim the submitted value of whitespace and slashes. Ensure to not trim
  // the slash on the left side.
  $endpoint = rtrim(trim(trim($endpoint), ''), "\\/");
  if ($endpoint[0] !== '/') {
    $formState
      ->setErrorByName('endpoint', 'The endpoint path has to start with a forward slash.');
  }
  elseif (!UrlHelper::isValid($endpoint)) {
    $formState
      ->setErrorByName('endpoint', 'The endpoint path contains invalid characters.');
  }
  $schema = $formState
    ->getValue('schema');

  /** @var \Drupal\graphql\Plugin\SchemaPluginInterface $instance */
  $instance = $this->schemaManager
    ->createInstance($schema);
  if (!empty($form['schema_configuration'][$schema]) && $instance instanceof PluginFormInterface && $instance instanceof ConfigurableInterface) {
    $state = SubformState::createForSubform($form['schema_configuration'][$schema], $form, $formState);
    $instance
      ->validateConfigurationForm($form['schema_configuration'][$schema], $state);
  }
}