You are here

public function XmlRpcExampleClientForm::submitInformation in xmlrpc 8

Submit handler to query system.listMethods.

Submit: query the XML-RPC endpoint for the method system.listMethods and report the result as a Drupal message. The result is a list of the available methods in this XML-RPC server.

Important note: Not all XML-RPC servers implement this method. Drupal's built-in XML-RPC server implements this method by default.

Parameters

array $form: Form array.

\Drupal\Core\Form\FormStateInterface $form_state: Form_state object.

See also

xmlrpc()

xmlrpc_errno()

xmlrpc_error_msg()

File

xmlrpc_example/src/Form/XmlRpcExampleClientForm.php, line 122

Class

XmlRpcExampleClientForm
Form demonstrating XML-RPC client.

Namespace

Drupal\xmlrpc_example\Form

Code

public function submitInformation(array &$form, FormStateInterface $form_state) {

  // First define the endpoint of the XML-RPC service, in this case this is
  // our own server.
  $server = $this
    ->getEndpoint();

  // Then we should define the method to call. xmlrpc() requires that all the
  // information related to the called method be passed as an array in the
  // form of 'method_name' => arguments_array.
  $options = [
    'system.listMethods' => [],
  ];

  // Make the xmlrpc request and process the results.
  $result = xmlrpc($server, $options);
  if ($result === FALSE) {
    $this
      ->messenger()
      ->addError($this
      ->t('Error return from xmlrpc(): Error: @errno, Message: @message', [
      '@errno' => xmlrpc_errno(),
      '@message' => xmlrpc_error_msg(),
    ]));
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('The XML-RPC server returned this response: <pre>@response</pre>', [
      '@response' => print_r($result, TRUE),
    ]));
  }
}