FilterFormatEditForm.php 979 Bytes
Newer Older
1 2 3 4
<?php

namespace Drupal\filter;

5
use Drupal\Core\Form\FormStateInterface;
6 7 8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
9
 * Provides a form for adding a filter format.
10 11
 *
 * @internal
12
 */
13
class FilterFormatEditForm extends FilterFormatFormBase {
14 15 16 17

  /**
   * {@inheritdoc}
   */
18
  public function form(array $form, FormStateInterface $form_state) {
19 20 21 22
    if (!$this->entity->status()) {
      throw new NotFoundHttpException();
    }

23
    $form['#title'] = $this->entity->label();
24 25 26 27 28 29 30 31
    $form = parent::form($form, $form_state);
    $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($this->entity));
    return $form;
  }

  /**
   * {@inheritdoc}
   */
32 33
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
34
    $this->messenger()->addStatus($this->t('The text format %format has been updated.', ['%format' => $this->entity->label()]));
35 36 37 38
    return $this->entity;
  }

}