class EditorController

Same name and namespace in other branches
  1. 11.x core/modules/editor/src/EditorController.php \Drupal\editor\EditorController

Returns responses for Editor module routes.

Hierarchy

Expanded class hierarchy of EditorController

File

core/modules/editor/src/EditorController.php, line 14

Namespace

Drupal\editor
View source
class EditorController extends ControllerBase {
  
  /**
   * Apply the necessary XSS filtering for using a certain text format's editor.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request object.
   * @param \Drupal\filter\FilterFormatInterface $filter_format
   *   The text format whose text editor (if any) will be used.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   A JSON response containing the XSS-filtered value.
   *
   * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
   *   Thrown if no value to filter is specified.
   *
   * @see editor_filter_xss()
   */
  public function filterXss(Request $request, FilterFormatInterface $filter_format) {
    $value = $request->request
      ->get('value');
    if (!isset($value)) {
      throw new NotFoundHttpException();
    }
    // The original_format parameter will only exist when switching text format.
    $original_format_id = $request->request
      ->get('original_format_id');
    $original_format = NULL;
    if (isset($original_format_id)) {
      $original_format = $this->entityTypeManager()
        ->getStorage('filter_format')
        ->load($original_format_id);
    }
    return new JsonResponse(editor_filter_xss($value, $filter_format, $original_format));
  }

}

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