Problem/Motivation

The FlagServiceInterface::getFlags() method is supposed to return an array of flags, keyed by entity id (in this case, flag machine name). When the user account is omitted, this holds true. However, when filtering for access, the flag ID keys are lost:

    if ($account == NULL) {
      return $flags;
    }

    $filtered_flags = [];
    foreach ($flags as $flag) {
      if ($flag->actionAccess('flag', $account)->isAllowed() ||
          $flag->actionAccess('unflag', $account)->isAllowed()) {
        $filtered_flags[] = $flag;
      }
    }

    return $filtered_flags;

Proposed resolution

The $filtered_flags array should retain the flag ID keying.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom created an issue. See original summary.

jhedstrom’s picture

The last submitted patch, 2: 2827864-02-TEST-ONLY.patch, failed testing.

The last submitted patch, 2: 2827864-02-TEST-ONLY.patch, failed testing.

  • joachim committed ecb38bf on 8.x-4.x authored by jhedstrom
    Issue #2827864 by jhedstrom: Fixed getFlags() return array isn't...
joachim’s picture

Status: Needs review » Fixed

Good catch!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.