You are here

public function HubspotDialog::buildForm in Hubspot forms 8

Parameters

\Drupal\filter\Entity\FilterFormat $filter_format: The filter format for which this dialog corresponds.

Overrides FormInterface::buildForm

File

src/Form/HubspotDialog.php, line 35

Class

HubspotDialog
Provides Hubspot Forms dialog for text editors.

Namespace

Drupal\hubspot_forms\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL) {

  // The default values are set directly from \Drupal::request()->request,
  // provided by the editor plugin opening the dialog.
  $user_input = $form_state
    ->getUserInput();
  $input = isset($user_input['editor_object']) ? $user_input['editor_object'] : [];
  $form['#tree'] = TRUE;
  $form['#attached']['library'][] = 'editor/drupal.editor.dialog';
  $form['#prefix'] = '<div id="hubspot-forms-dialog-form">';
  $form['#suffix'] = '</div>';
  $HubspotFormsCore = new HubspotFormsCore();
  $form['formid'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Hubspot Form'),
    '#description' => $this
      ->t('Please choose a form you would like to display.'),
    '#options' => $HubspotFormsCore
      ->getFormIds(),
    '#required' => TRUE,
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['save_modal'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Insert'),
    // No regular submit-handler. This form only works via JavaScript.
    '#submit' => [],
    '#ajax' => [
      'callback' => '::submitForm',
      'event' => 'click',
    ],
  ];

  // This is the element where we put generated code
  // By doing this we can generate [video:url]
  // in PHP instead of generating it in CKEditor JS plugin.
  $form['attributes']['code'] = [
    '#title' => $this
      ->t('Hubspot Forms'),
    '#type' => 'textfield',
    '#prefix' => '<div class="visually-hidden">',
    '#suffix' => '</div>',
  ];
  return $form;
}