public function getChildrenCategories(
        CategoryInterface $parentCategory,
        $recursively = false
    ) {
        $categories = $this
            ->createQueryBuilder('c')
            ->where('c.parent = :parent_category')
            ->setParameters([
                'parent_category' => $parentCategory,
            ])
            ->getQuery()
            ->getResult();

        if ($recursively && !empty($categories)) {
            foreach ($categories as $category) {
                $categories = array_merge(
                    $categories,
                    $this->getChildrenCategories($category, true)
                );
            }
        }

        return $categories;
    }
public function getChildrenCategories(
        CategoryInterface $parentCategory,
        $recursively = false
    ) {
        $categories = $this
            ->createQueryBuilder('c')
            ->where('c.parent = :parent_category')
            ->setParameters([
                'parent_category' => $parentCategory,
            ])
            ->getQuery()
            ->getResult();

        if ($recursively && !empty($categories)) {
            foreach ($categories as $category) {
                $categories = array_merge(
                    $categories,
                    $this->getChildrenCategories($category, true)
                );
            }
        }

        return $categories;
    }
public function getChildrenCategories ( CategoryInterface $ parentCategory , $ recursively = false ) { $ categories = $ this -> createQueryBuilder ( 'c' ) -> where ( 'c.parent = :parent_category' ) -> setParameters ( [ 'parent_category' => $ parentCategory , ] ) -> getQuery ( ) -> getResult ( ) ; if ( $ recursively && ! empty ( $ categories ) ) { foreach ( $ categories as $ category ) { $ categories = array_merge ( $ categories , $ this -> getChildrenCategories ( $ category , true ) ) ; } } return $ categories ; }
Get the children categories given a parent category.

@param CategoryInterface $parentCategory The parent category.
@param bool              $recursively    If it should check the
children recursively

@return array The list of children categories.
Get the children categories given a parent category .