You are here

public function XmlRpcExampleAlterForm::buildForm in xmlrpc 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

xmlrpc_example/src/Form/XmlRpcExampleAlterForm.php, line 38

Class

XmlRpcExampleAlterForm
Presents a form to enable/disable the code implemented in hook_xmlrpc_alter.

Namespace

Drupal\xmlrpc_example\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('xmlrpc_example.server');
  $form['explanation'] = [
    '#markup' => '<div>' . $this
      ->t('This is a configuration form to enable the alteration of XML-RPC methods using hook_xmlrpc_alter.<br />hook_xmlrpc_alter() can be used to alter the current defined methods by other modules. In this case as demonstration, we will overide current add and subtraction methods with others not being limited. Remember that this hook is optional and is not required to create XMLRPC services.<br />') . '</div>',
  ];
  $form['alter_enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Override current xmlrpc_example.add and xmlrpc_example.subtraction methods'),
    '#description' => $this
      ->t('If this checkbox is enabled, the default methods will be replaced with custom methods that ignore the XML-RPC server maximum and minimum restrictions.'),
    '#default_value' => $config
      ->get('alter_enabled'),
  ];
  $form['info'] = [
    '#markup' => '<div>' . $this
      ->t('Use the <a href=":url">client submission form</a> to see the results of checking this checkbox', [
      ':url' => Url::fromRoute('xmlrpc_example.client')
        ->toString(),
    ]) . '</div>',
  ];
  return parent::buildForm($form, $form_state);
}