Change the boolean constants to have boolean values in NodeInterface, CommentInterface and FileInterface

Created on 23 September 2024, about 2 months ago

Problem/Motivation

The boolean constants in the NodeInterface, CommentInterface and FileInterface have integer values. With MongoDB boolean values need to be booleans (TRUE or FALSE) and not integer (1 or 0). When used in query conditions, these contants need to be type hinted. For example:

$query->condition('status', (bool) NodeInterface::PUBLISHED);
$query->condition('status', (bool) CommentInterface::PUBLISHED);
$query->condition('status', (bool) FileInterface::STATUS_PERMANENT)

Proposed resolution

Change the boolean constants in NodeInterface, CommentInterface and FileInterface

Remaining tasks

TBD

User interface changes

None

Introduced terminology

None

API changes

The following constants have changed from an integer value to the correstonding boolean value:

    Drupal\node\NodeInterface::NOT_PUBLISHED = FALSE
    Drupal\node\NodeInterface::PUBLISHED = TRUE
    Drupal\node\NodeInterface::NOT_PROMOTED = FALSE
    Drupal\node\NodeInterface::PROMOTED = TRUE
    Drupal\node\NodeInterface::NOT_STICKY = FALSE
    Drupal\node\NodeInterface::STICKY = TRUE
    Drupal\comment\CommentInterface::NOT_PUBLISHED = FALSE
    Drupal\comment\CommentInterface::PUBLISHED = TRUE
    Drupal\file\FileInterface::STATUS_PERMANENT = TRUE

Data model changes

None

Release notes snippet

TBD

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

other

Created by

πŸ‡³πŸ‡±Netherlands daffie

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

Merge Requests

Comments & Activities

  • Issue created by @daffie
  • Pipeline finished with Failed
    about 2 months ago
    Total: 599s
    #290040
  • Pipeline finished with Success
    about 2 months ago
    Total: 1044s
    #291022
  • πŸ‡³πŸ‡±Netherlands daffie
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Could this possible be an issue in the schema?

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Spoke previously on slack and doesn't appear to be related to config schema, so change seems pretty straight forward.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    While I agree that this should be fixed, this has the same issue that there could be existing code performing strict comparisons that would break, for example this one I found from a GitLab code search: https://git.drupalcode.org/project/ezproxy_stanza/-/blob/8.x-1.x/src/Form/EZProxyStanzaConfigForm.php#L258

    Having said that, it seems it's more common to use these constants in query conditions where this is not an issue.

    It might be better to deprecate these constants somehow, and move to a generic PublishedStatus enum that is correctly typed, and shared for all EntityPublishedInterface entities.

    Setting back to needs review for consideration.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    You're probably right. Believe that's what has been done in the past.

    So deprecate current constants and use new ones.

Production build 0.71.5 2024