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

Created on 25 September 2019, almost 5 years ago
Updated 8 May 2024, about 2 months 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

Fix the tests as described in #46.

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Editorย  โ†’

Last updated 1 minute 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.

  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

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.69.0 2024