private function resolveDataClass(FormInterface $form)
    {
        // Nothing to do if root
        if ($form->isRoot()) {
            return $form->getConfig()->getDataClass();
        }

        $propertyPath = $form->getPropertyPath();
        /** @var FormInterface $dataForm */
        $dataForm = $form;

        // If we have a index then we need to use it's parent
        if ($propertyPath->getLength() === 1 && $propertyPath->isIndex(0) && $form->getConfig()->getCompound()) {
            return $this->resolveDataClass($form->getParent());
        }

        // Now locate the closest data class
        // TODO what is the length really for?
        for ($i = $propertyPath->getLength(); $i !== 0; $i--) {
            $dataForm = $dataForm->getParent();

            # When a data class is found then use that form
            # This happend when property_path contains multiple parts aka `entity.prop`
            if ($dataForm->getConfig()->getDataClass() !== null) {
                break;
            }
        }

        // If the root inherits data, then grab the parent
        if ($dataForm->getConfig()->getInheritData()) {
            $dataForm = $dataForm->getParent();
        }

        return $dataForm->getConfig()->getDataClass();
    }