b8decc138fa1cd980c8642e4467ae64c3308fe6d
[yaffs-website] / web / core / modules / filter / src / FilterFormatEditForm.php
1 <?php
2
3 namespace Drupal\filter;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
7
8 /**
9  * Provides a form for adding a filter format.
10  *
11  * @internal
12  */
13 class FilterFormatEditForm extends FilterFormatFormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function form(array $form, FormStateInterface $form_state) {
19     if (!$this->entity->status()) {
20       throw new NotFoundHttpException();
21     }
22
23     $form['#title'] = $this->entity->label();
24     $form = parent::form($form, $form_state);
25     $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($this->entity));
26     return $form;
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function submitForm(array &$form, FormStateInterface $form_state) {
33     parent::submitForm($form, $form_state);
34     $this->messenger()->addStatus($this->t('The text format %format has been updated.', ['%format' => $this->entity->label()]));
35     return $this->entity;
36   }
37
38 }