Issue #3424769: Create enum for FilterInterface constants
7 unresolved threads
Closes #3424769
Merge request reports
Activity
Filter activity
- Resolved by Michael Strelan
93 102 */ 94 103 const TYPE_TRANSFORM_REVERSIBLE = 2; 95 104 96 105 /** 97 106 * Irreversible transformation filters. 107 * 108 * @deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use 109 * * \Drupal\filter\FilterType::TransformIrreversible instead. 98 110 */ 99 111 const TYPE_TRANSFORM_IRREVERSIBLE = 3; 100 112 101 113 /** 102 114 * Returns the processing type of this filter plugin. 103 115 * 104 * @return int 116 * @return \Drupal\filter\FilterType Hrm … very interesting question
How about changing this to:
public function getType(bool $enum_return_type = FALSE);
and then in the logic for Drupal 10.3:
if ($enum_return_type === FALSE) { @trigger_error(E_USER_DEPRECATED, …); }
That'd avoid breaking all contrib/custom calls. During the Drupal 11 cycle, they'd have to change their calls fromgetType()
togetType(TRUE)
. Then in Drupal 11, we'd deprecate that parameter entirely. And in Drupal 12 we'd be able to remove it.
added 2 commits
added 3 commits
259 260 * @return iterable|\Drupal\filter\Plugin\FilterInterface[] 260 261 * An iterable of matched filter plugins. 261 262 */ 262 private static function getFiltersInFormatOfType(FilterFormatInterface $text_format, int $filter_type, callable $extra_requirements = NULL): iterable { 263 assert(in_array($filter_type, [ 264 FilterInterface::TYPE_MARKUP_LANGUAGE, 265 FilterInterface::TYPE_HTML_RESTRICTOR, 266 FilterInterface::TYPE_TRANSFORM_REVERSIBLE, 267 FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE, 268 ])); 263 private static function getFiltersInFormatOfType(FilterFormatInterface $text_format, FilterType|int $filter_type, callable $extra_requirements = NULL): iterable { 264 if (is_int($filter_type)) { 265 // @todo trigger deprecation warning. 107 * @return int 108 * One of: 109 * - FilterInterface::TYPE_MARKUP_LANGUAGE 110 * - FilterInterface::TYPE_HTML_RESTRICTOR 111 * - FilterInterface::TYPE_TRANSFORM_REVERSIBLE 112 * - FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE 107 * @return \Drupal\filter\FilterType|null 108 * The filter type. 113 109 * 114 110 * @see \Drupal\filter\Plugin\FilterInterface::getType() 115 111 */ 116 112 protected static function getSourceFilterType($filter_id) { 117 switch ($filter_id) { 118 // Drupal 7 core filters. 119 // - https://git.drupalcode.org/project/drupal/blob/7.69/modules/filter/filter.module#L1229 120 // - https://git.drupalcode.org/project/drupal/blob/7.69/modules/php/php.module#L139 changed this line in version 9 of the diff
added 171 commits
-
a5d95ad9...b4a9a825 - 157 commits from branch
project:11.x
- b4a9a825...e294833f - 4 earlier commits
- 590dc080 - Update more references
- a451234a - Move enum
- d508d277 - Fix call to array_unique on FilterType[]
- 67a9bba8 - Move FilterType docs to the enum
- a137a691 - Convert switch to match
- 06c30d12 - Update more references to TYPE_MARKUP_LANGUAGE
- 88ee3922 - Update more references to TYPE_HTML_RESTRICTOR
- ee6a1319 - Add todos
- 92a98327 - Expect enum in attribute
- 36117180 - Import filter type when passing to attribute
Toggle commit list-
a5d95ad9...b4a9a825 - 157 commits from branch
22 22 #[Filter( 23 23 id: "editor_file_reference", 24 24 title: new TranslatableMarkup("Track images uploaded via a Text Editor"), 25 description: new TranslatableMarkup("Ensures that the latest versions of images uploaded via a Text Editor are displayed, along with their dimensions."), 26 type: FilterInterface::TYPE_TRANSFORM_REVERSIBLE 25 type: FilterType::TransformReversible, 26 description: new TranslatableMarkup("Ensures that the latest versions of images uploaded via a Text Editor are displayed, along with their dimensions.") 46 46 public function __construct( 47 47 public readonly string $id, 48 48 public readonly TranslatableMarkup $title, 49 public readonly int $type, 49 public readonly FilterType $type, - core/modules/filter/src/FilterType.php 0 → 100644
30 case TransformIrreversible; 31 32 /** 33 * Backwards compatibility with legacy integer values. 34 * 35 * @param int $legacyInt 36 * The legacy integer value from \Drupal\filter\Plugin\FilterInterface. 37 */ 38 public static function fromLegacyInt(int $legacyInt): self { 39 // @todo trigger deprecation warning. 40 return match ($legacyInt) { 41 0 => self::MarkupLanguage, 42 1 => self::HtmlRestrictor, 43 2 => self::TransformReversible, 44 3 => self::TransformIrreversible, 45 default => throw new \InvalidArgumentException("Invalid legacy integer value: $legacyInt"),
Please register or sign in to reply