Programatically changing taxonomy description always resets text format to "Full HTML"

Created on 29 November 2023, about 1 year ago
Updated 17 February 2024, 10 months ago

Problem/Motivation

When you change the description of a taxonomy term by using the setDescription() method, the text format is always reset to "Full HTML".

Steps to reproduce

Executing the following code will create a taxonomy term with a "Full HTML" description.

$term = Term::create([
    'name' => 'test',
    'vid' => 'tags',
  ]);
  $term->setFormat('plain_text');
  $term->setDescription('Test');
  $term->save();

The following code works as expected:

$term = Term::create([
    'name' => 'test2',
    'vid' => 'tags',
  ]);
  $term->setDescription('Test');
  $term->setFormat('plain_text');
  $term->save();

Proposed resolution

Make setDescription preserve the text format.

Alternative: I think, theoretically, you can also pass an array ["format" => "plain_text", "value" => 'Test'] to setDescription and it would work correctly. However, this is not documented - according to the PHPDoc, setDescription only accepts strings. Hence, an alternative would be to change the PHPDoc *and* to clearly document the behavior.

Remaining tasks

Make decision on how to fix and implement the fix.

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Taxonomyย  โ†’

Last updated 2 minutes ago

  • Maintained by
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States @xjm
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @catch
Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024