protected function handleInvalidPropertyValueBag(
        PropertyValueBagInterface $propertyValueBag = null,
        ModelInterface $model = null,
        EnvironmentInterface $environment
    ) {
        // @codingStandardsIgnoreStart
        @\trigger_error('This function where remove in 3.0. ' . __CLASS__  . '::' . __FUNCTION__, E_USER_DEPRECATED);
        // @codingStandardsIgnoreEnd

        if ((null === $propertyValueBag)
            || (null === $model)
        ) {
            return;
        }

        $inputProvider = $environment->getInputProvider();

        foreach (\array_keys($propertyValueBag->getArrayCopy()) as $propertyName) {
            $allErrors    = $propertyValueBag->getPropertyValueErrors($propertyName);
            $mergedErrors = [];
            if (\count($allErrors) > 0) {
                foreach ($allErrors as $error) {
                    if (\in_array($error, $mergedErrors)) {
                        continue;
                    }

                    $mergedErrors[] = $error;
                }
            }

            $eventPropertyValueBag = new PropertyValueBag();
            $eventPropertyValueBag->setPropertyValue($propertyName, $inputProvider->getValue($propertyName, true));

            $event = new EncodePropertyValueFromWidgetEvent($environment, $model, $eventPropertyValueBag);
            $event->setProperty($propertyName)
                ->setValue($inputProvider->getValue($propertyName, true));
            $environment->getEventDispatcher()->dispatch(EncodePropertyValueFromWidgetEvent::NAME, $event);

            $propertyValueBag->setPropertyValue($propertyName, $event->getValue());

            if (\count($mergedErrors) > 0) {
                $propertyValueBag->markPropertyValueAsInvalid($propertyName, $mergedErrors);
            }
        }
    }