private function prepareWidgetAttributes(ModelInterface $model, PropertyInterface $property)
    {
        $environment = $this->getEnvironment();
        $defName     = $environment->getDataDefinition()->getName();

        $propExtra = $property->getExtra();

        $value = $this->valueToWidget($model, $property);

        $propExtra['required'] = ('' === $value) && !empty($propExtra['mandatory']);

        $widgetConfig = [
            'inputType' => $property->getWidgetType(),
            'label'     => [
                $property->getLabel(),
                $property->getDescription()
            ],
            'options'   => $this->getOptionsForWidget($property, $model),
            'eval'      => $propExtra,
            // 'foreignKey' => null
        ];

        if (isset($propExtra['reference'])) {
            $widgetConfig['reference'] = $propExtra['reference'];
        }

        $event = new GetAttributesFromDcaEvent(
            $widgetConfig,
            $property->getName(),
            $value,
            $property->getName(),
            $defName,
            new DcCompat($environment, $model, $property->getName())
        );

        $environment->getEventDispatcher()->dispatch(ContaoEvents::WIDGET_GET_ATTRIBUTES_FROM_DCA, $event);
        $prepareAttributes = $event->getResult();

        if (('checkbox' === $widgetConfig['inputType'])
            && $widgetConfig['eval']['submitOnChange']
            && isset($GLOBALS['TL_DCA'][$defName]['subpalettes'])
            && \is_array($GLOBALS['TL_DCA'][$defName]['subpalettes'])
            && \array_key_exists($property->getName(), $GLOBALS['TL_DCA'][$defName]['subpalettes'])
        ) {
            // We have to override the onclick, do not append to it as Contao adds it's own code here in
            // Widget::getAttributesFromDca() which kills our sub palette handling!
            $prepareAttributes['onclick'] = "Backend.autoSubmit('" . $defName . "');";
        }

        return $prepareAttributes;
    }