Editor::getFilterFormat() should throw domain error if Editor::format not set

Created on 25 September 2019, over 5 years ago
Updated 20 January 2023, about 2 years ago

Problem/Motivation

If you call Editor::getFilterFormat() to see if it's set, it doesn't work, and the error message isn't very helpful:

  $format = $editor->getFilterFormat();
  if (empty($format)) {
    return;
  }

If you do this before an editor object is saved, you get a frustrating fatal error about trying to load an entity with a NULL id.

This usually happens calling code in a subroutine at '/admin/config/content/formats/add'.

The error message should be more helpful. The correct way to use this code is to check first with ::hasAssociatedFilterFormat().

  if (!$editor->hasAssociatedFilterFormat()) {
    return;
  }

  $format = $editor->getFilterFormat();
  if (empty($format)) {
    return;
  }

Proposed resolution

Throw a \DomainException with a helpful message if $editor->getFilterFormat() called without a text format assigned to the Editor.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

10.1 โœจ

Component
Editorย  โ†’

Last updated 23 days ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States oknate Greater New York City Area

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024