summaryrefslogtreecommitdiffstats
path: root/core/modules/filter/src/FilterFormatEditForm.php
blob: 8173a785c0a4d670839f347c6f426c0192625b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

namespace Drupal\filter;

use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Provides a form for adding a filter format.
 *
 * @internal
 */
class FilterFormatEditForm extends FilterFormatFormBase {

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

    $form['#title'] = $this->entity->label();
    $form = parent::form($form, $form_state);
    $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($this->entity));
    return $form;
  }

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

}