Skip to content
Snippets Groups Projects

Issue #3424769: Create enum for FilterInterface constants

Open Issue #3424769: Create enum for FilterInterface constants
7 unresolved threads
Open Michael Strelan requested to merge issue/drupal-3424769:3424769-filter-type-enum into 11.x
7 unresolved threads

Closes #3424769

Merge request reports

Members who can merge are allowed to add commits.

Merge request pipeline passed for 16a05939

Approval is optional
Code Quality is loading
Test summary results are being parsed
Ready to merge by members who can write to the target branch.

Merge details

  • The source branch is 1758 commits behind the target branch.
  • 1 commit and 1 merge commit will be added to .
  • Source branch will not be deleted.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 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
    • Comment on lines -104 to +116

      How to make this backwards compatible?

    • Maybe we need to keep this returning ints and deprecate it, introducing a new getFilterType that returns the enum.

    • Hrm … very interesting question :thinking::grimacing:

      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, …);
        }

      :point_up: That'd avoid breaking all contrib/custom calls. During the Drupal 11 cycle, they'd have to change their calls from getType() to getType(TRUE). Then in Drupal 11, we'd deprecate that parameter entirely. And in Drupal 12 we'd be able to remove it.

    • Of course, that makes sense! Although a bit annoying having to add the param value in 11.x only to remove it again in 12.x. And if you tried to jump from 10.x to 12.x you might miss that change and end up with the enum when you're still expecting an int.

    • Please register or sign in to reply
  • added 2 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 3 commits

    Compare with previous version

  • added 1 commit

    • 2a5f3c2e - Fix call to array_unique on FilterType[]

    Compare with previous version

  • added 5 commits

    • 2db53efb - Move FilterType docs to the enum
    • 3db9eafa - Convert switch to match
    • 1efe5449 - Update more references to TYPE_MARKUP_LANGUAGE
    • deaf63bb - Update more references to TYPE_HTML_RESTRICTOR
    • a5d95ad9 - Add todos

    Compare with previous version

  • 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
  • 106 106 * {@inheritdoc}
    107 107 */
    108 108 public function getType() {
    109 // @todo reconcile ints with enum and trigger deprecation warning.
  • Michael Strelan added 171 commits

    added 171 commits

    Compare with previous version

  • 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,
  • added 1 commit

    • 16a05939 - Revert "Convert switch to match"

    Compare with previous version

  • 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
    Loading