Problem/Motivation

It would be useful if FlagCountManager offered a method to count a particular flag. This would be like ::getEntityFlagCounts() except that it would also take a string flag_id param and return an integer, the count for that flag_id.

Proposed resolution

Add a new method.

Remaining tasks

Agree on the name of the method. Implement.

User interface changes

None.

API changes

Method is added.

Data model changes

None.

CommentFileSizeAuthor
#5 3376688-5.patch1.92 KBsamitk

Issue fork flag-3376688

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

Liam Morland created an issue. See original summary.

samitk’s picture

Assigned: Unassigned » samitk
Status: Active » Needs work

I am looking into it.

samitk’s picture

Assigned: samitk » Unassigned
Status: Needs work » Needs review

Hi @Liam Morland ,

I checked it and i found a similar function as you mentioned public function getFlagEntityCount(FlagInterface $flag); Defined in the same file FlagCountManager.
The only difference is it takes flag instance as a argument not string flag_id.

I guess we can use getFlagEntityCount function.

Thanks
Samit K.

liam morland’s picture

::getFlagEntityCount() gives the total number of flags not the number on a particular entity. The new method would need to take both an entity and a flag as parameters.

samitk’s picture

StatusFileSize
new1.92 KB

Hi Liam Morland,

Function getFlagCounts added, Please review.

Function getFlagCounts takes 2 arguments $flag and $entity object, $entity object is optional here.

Thanks
Samit K.

ivnish’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs tests

Needs reroll to MR. Also needs tests

liam morland’s picture

Issue tags: -Needs reroll

Merge request created with the patch in #5.

ivnish’s picture

Thanks Liam!

Could you write a simple test for it?

liam morland’s picture

I'm not currently working on the project that I needed this for, so I won't be able to write a test for it quickly.

ivnish’s picture

Ok, no problem

ivnish changed the visibility of the branch 8.x-4.x to hidden.

ivnish’s picture

Version: 8.x-4.x-dev » 5.x-dev

deaom made their first commit to this issue’s fork.

deaom’s picture

Status: Needs work » Needs review

The tests are actually passing, the issue is with previous version of composer in the gitlab-ci template #3564269: Composer 2.9 blocks dependencies which have security advisories which makes composer previous minor fail (D 11.1). It can be ignored, so removed from the gitlab-ci this project uses or simply ignored till the issue is fixed. Up to maintainers to decide, but marking the issue as needs review as test was updated to add the new function in.

liam morland’s picture

Title: Add method to count a particular flag, like ::getEntityFlagCounts() » Create FlagCountManagerInterface::getFlagCounts()
Issue tags: -Needs tests

The code looks good and has tests.