protected function calculateFilterOptionsCount($items, &$amountArray, $idList)
    {
        $builder = $this
            ->getConnection()
            ->createQueryBuilder()
            ->select('value_id')
            ->addSelect('COUNT(item_id) AS amount')
            ->from('tl_metamodel_tag_relation')
            ->where('att_id=:attId')
            ->setParameter('attId', $this->get('id'))
            ->groupBy('value_id');

        if (0 < $items->getCount()) {
            $ids = [];
            foreach ($items as $item) {
                $ids[] = $item->get('id');
            }
            $builder
                ->andWhere('value_id IN (:valueIds)')
                ->setParameter('valueIds', $ids, Connection::PARAM_STR_ARRAY);
            if ($idList && \is_array($idList)) {
                $builder
                    ->andWhere('item_id IN (:itemIds)')
                    ->setParameter('itemIds', $idList, Connection::PARAM_STR_ARRAY);
            }
        }

        $counts = $builder->execute();
        foreach ($counts->fetchAll(\PDO::FETCH_ASSOC) as $count) {
            $amountArray[$count['value_id']] = $count['amount'];
        }
    }