protected function createForm(
        CollectionInterface $filterCollection,
        $name = null,
        array $rootFormBuilderOptions = [],
        array $filterFormBuilderOptions = []

    ) {
        // Create the root form builder, which is used as the container for all filter forms.
        $rootFormBuilder = $this->createFormBuilder($name, 'form', null, $rootFormBuilderOptions);

        if ($filterCollection->hasFilters()) {
            foreach ($filterCollection as $filter) {
                if (!($filter instanceof FilterHasFormInterface) || $filter->hasForm() !== true) {
                    // Create a form for only filters, which have a form representation.
                    continue;
                }

                // Create the filter form builder itself.
                $filterFormBuilder = $this->createFormBuilder(
                    $filter->getName(),
                    $this->createFilterFormType(),
                    $filter,
                    array_merge($filterFormBuilderOptions, ['data_class' => get_class($filter)])
                );

                // Append the filter to the filter form.
                $this->appendFormField($filter, $filterFormBuilder);

                // Finally, add the filter form builder to the root form builder.
                $rootFormBuilder->add($filterFormBuilder);
            }
        }

        return $rootFormBuilder->getForm();
    }