Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3332947 by zanvidmar: Mentions filter throws an error if NULL ... #3319

Closed

Conversation

zanvidmar
Copy link
Contributor

@zanvidmar zanvidmar commented Feb 23, 2023

Problem

In the mention filter method getMentions(string $text) only strings are accepted. It can not be guaranteed that all sting fields will return an empty string '' when they are left empty. When NULL is provided getMentions() throws an error.

Error:

TypeError: Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions(): Argument #1 ($text) must be of type string, null given,

Solution

Allow that $text variable can be also NULL by getMentions(?string $text) and add return empty array like it is shown below. empty($text) was deliberately chosen over $text === NULL because there is also no value in processing an empty sting.

  public function getMentions(?string $text): array {
    $mentions = [];

    if (empty($text)) {
      return $mentions;
    }

Issue tracker

3332947

Theme issue tracker

N/A

How to test

[Required] For example

  • Install and configure the mentions module.
  • In a custom module, create a node with an empty body field using Node::create()
  • Attempt to run the code in the module
  • An error TypeError: Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions(): Argument #1 ($text) must be of type string, null given is triggered
  • The expected result is attained when repeating the steps with this fix applied.

Definition of done

Before merge

  • Code/peer review is completed
  • All commit messages are clear and clean. If applicable a rebase was performed
  • All automated tests are green
  • Functional/manual tests of the acceptance criteria are approved
  • All acceptance criteria were met
  • New features or changes to existing features are covered by tests, either unit (preferably) or behat
  • Update path is tested. New hook_updates should respect update order, right naming convention and consider hook_post_update code
  • Module can be safely uninstalled. Update/implement hook_uninstall and make sure that removed configuration or dependencies are removed/uninstalled
  • This pull request has all required labels (team/type/priority)
  • This pull request has a milestone
  • This pull request has an assignee (if applicable)
  • Any front end changes are tested on all major browsers
  • New UI elements, or changes on UI elements are approved by the design team
  • New features, or feature changes are approved by the product owner

After merge

  • Code is tested on all branches that it has been cherry-picked
  • Update hook number might need adjustment, make sure they have the correct order
  • The Drupal.org ticket(s) are updated according to this pull request status

Screenshots

N/A

Release notes

Fix Mentions prevents saving of content with empty text field

Change Record

N/A

Translations

N/A

  • Changed or removed source strings are added to the translations.php file.

@mergeable
Copy link

mergeable bot commented Feb 23, 2023

Thanks for contributing towards Open Social! A maintainer from the @goalgorilla/maintainers group might not review all changes from all teams/contributors. Please don't be discouraged if it takes a while. In the meantime, we have some automated checks running and it might be that you will see our comments with some tips or requests to speed up the review process. 😊

@open-social-tugboat
Copy link

Tugboat has finished building the preview for this pull request!

Link:

Dashboard:

@zanvidmar zanvidmar changed the title PROD-24337: Fix mentions filter throws an error if NULL is provided i… PROD-24337 by zanvidmar: Mentions filter throws an error if NULL ... Feb 23, 2023
@zanvidmar zanvidmar added type: bug Fixes a bug in Open Social status: needs review This pull request is waiting for a requested review team: guardians labels Feb 23, 2023
@zanvidmar zanvidmar marked this pull request as ready for review February 23, 2023 12:58
@zanvidmar zanvidmar changed the title PROD-24337 by zanvidmar: Mentions filter throws an error if NULL ... Issue #3332947 by zanvidmar: Mentions filter throws an error if NULL ... Feb 23, 2023
@zanvidmar zanvidmar added this to the 11.7.4 milestone Feb 23, 2023
@open-social-tugboat
Copy link

Tugboat has finished building the preview for this pull request!

Link:

Dashboard:

3 similar comments
@open-social-tugboat
Copy link

Tugboat has finished building the preview for this pull request!

Link:

Dashboard:

@open-social-tugboat
Copy link

Tugboat has finished building the preview for this pull request!

Link:

Dashboard:

@open-social-tugboat
Copy link

Tugboat has finished building the preview for this pull request!

Link:

Dashboard:

@zanvidmar
Copy link
Contributor Author

I am closing this PR because of #3322 which is fixing the issue without breaking changes.

@zanvidmar zanvidmar closed this Feb 27, 2023
@ribel ribel removed this from the 12.0.0 milestone Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio: high status: needs review This pull request is waiting for a requested review team: guardians type: bug Fixes a bug in Open Social
4 participants