private function buildFieldSets(Action $action, \ArrayObject $renderInformation, EnvironmentInterface $environment)
    {
        $formInputs = $environment->getInputProvider()->getValue('FORM_INPUTS');
        $collection = $this->getCollectionFromSession($action, $environment);

        $fieldSets = [];
        $errors    = [];
        while ($collection->count() > 0) {
            $model   = $collection->shift();
            $modelId = ModelId::fromModel($model);

            $editPropertyValuesBag = $this->getPropertyValueBagFromModel($action, $model, $environment);
            if ($formInputs) {
                $this->handleEditCollection($action, $editPropertyValuesBag, $model, $renderInformation, $environment);
            }

            $fields = $this->renderEditFields(
                $action,
                new ContaoWidgetManager($environment, $model),
                $model,
                $editPropertyValuesBag,
                $environment
            );

            if (\count($fields) < 1) {
                continue;
            }

            $fieldSets[] = [
                'label'   => $modelId->getSerialized(),
                'model'   => $model,
                'legend'  => \str_replace('::', '____', $modelId->getSerialized()),
                'class'   => 'tl_box',
                'palette' => \implode('', $fields)
            ];
        }

        $renderInformation->offsetSet('fieldsets', $this->handleLegendCollapsed($fieldSets));
        $renderInformation->offsetSet('error', $errors);
    }