FilterFormatEditForm.php

Same filename and directory in other branches
  1. 9 core/modules/filter/src/FilterFormatEditForm.php
  2. 8.9.x core/modules/filter/src/FilterFormatEditForm.php
  3. 11.x core/modules/filter/src/FilterFormatEditForm.php

Namespace

Drupal\filter

File

core/modules/filter/src/FilterFormatEditForm.php

View source
<?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);
        $this->messenger()
            ->addStatus($this->t('The text format %format has been updated.', [
            '%format' => $this->entity
                ->label(),
        ]));
        return $this->entity;
    }

}

Classes

Title Deprecated Summary
FilterFormatEditForm Provides a form for adding a filter format.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.