You are here

public function TagForm::form in Extensible BBCode 8.3

Same name and namespace in other branches
  1. 4.0.x src/Form/TagForm.php \Drupal\xbbcode\Form\TagForm::form()

Gets the actual form array to be built.

Overrides TagFormBase::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/TagForm.php, line 66

Class

TagForm
Base form for creating and editing custom tags.

Namespace

Drupal\xbbcode\Form

Code

public function form(array $form, FormStateInterface $form_state) : array {
  $form = parent::form($form, $form_state);
  $form['name']['#attached']['library'] = [
    'xbbcode/tag-form',
  ];
  $form['preview']['code'] += [
    '#prefix' => '<div id="ajax-preview">',
    '#suffix' => '</div>',
  ];

  // Update preview if the sample or the template are manually changed.
  // (The sample and the name are kept in sync locally.)
  $form['sample']['#ajax'] = $form['template_code']['#ajax'] = [
    'wrapper' => 'ajax-preview',
    'callback' => [
      $this,
      'ajaxPreview',
    ],
    // Don't refocus into the text field, and only update on change.
    'disable-refocus' => TRUE,
    'event' => 'change',
  ];

  // The preview may need to show error messages on update.
  $form['preview']['#attached']['library'] = [
    'classy/messages',
  ];
  return $form;
}