Problem/Motivation

The logic in OptionsHooks::hasValuesInUse() is unnecessarily nested. When no values are provided, no entity query is required, and the method can return early.

Steps to reproduce

Review core/modules/options/src/Hook/OptionsHooks.php and observe that the entity query and its result handling are nested inside an if ($values) condition.

Proposed resolution

Return FALSE early when $values is empty. Otherwise, execute the entity query and return its result cast to a boolean.

Remaining tasks

  • Review the change.
  • Confirm that existing automated tests pass.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

Not required - no functional changes.

Issue fork drupal-3615750

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nicxvan created an issue. See original summary.

nicxvan’s picture

Title: [pp-1] Update logic of hasValuesInUse in OptionsHOOKS » Update logic of hasValuesInUse in OptionsHooks
Status: Postponed » Active

kieran.cott made their first commit to this issue’s fork.

kieran.cott changed the visibility of the branch 3615750-update-logic-of-hviu to hidden.

kieran.cott’s picture

Issue summary: View changes
Status: Active » Needs review

Updated the issue summary and implemented the change suggested in https://git.drupalcode.org/project/drupal/-/merge_requests/14683#note_16....

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Early return looks good to me.

nicxvan’s picture

Status: Reviewed & tested by the community » Needs work

Isn't it better to check if the array is empty? Or is the ! operator preferred?

kieran.cott’s picture

Status: Needs work » Needs review

empty() might be better as you suggest, now updated.

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Looks great.