public function delete(View $view, Widget $widget)
    {
        $this->builder->build($view);

        $widgetMap = $widget->getWidgetMap();
        $slot = $widgetMap->getSlot();

        $originalParent = $widgetMap->getParent();
        $originalPosition = $widgetMap->getPosition();

        $children = $this->resolver->getChildren($widgetMap, $view);
        $beforeChild = !empty($children[WidgetMap::POSITION_BEFORE]) ? $children[WidgetMap::POSITION_BEFORE] : null;
        $afterChild = !empty($children[WidgetMap::POSITION_AFTER]) ? $children[WidgetMap::POSITION_AFTER] : null;

        //we remove the widget from the current view
        if ($widgetMap->getView() === $view) {
            // If the widgetMap has substitutes, delete them or transform them in create mode
            if (count($widgetMap->getAllSubstitutes()) > 0) {
                foreach ($widgetMap->getAllSubstitutes() as $substitute) {
                    if ($substitute->getAction() === WidgetMap::ACTION_OVERWRITE) {
                        $substitute->setAction(WidgetMap::ACTION_CREATE);
                        $substitute->setReplaced(null);
                    } else {
                        $view->removeWidgetMap($widgetMap);
                    }
                }
            }
            //remove the widget map from the slot
            $view->removeWidgetMap($widgetMap);
        } else {
            //the widget is owned by another view (a parent)
            //so we add a new widget map that indicates we delete this widget
            $replaceWidgetMap = new WidgetMap();
            $replaceWidgetMap->setAction(WidgetMap::ACTION_DELETE);
            $replaceWidgetMap->addWidget($widget);
            $replaceWidgetMap->setSlot($slot);
            $replaceWidgetMap->setReplaced($widgetMap);

            $view->addWidgetMap($replaceWidgetMap);
        }

        //Move children for current WidgetMap View
        $this->moveChildren($view, $beforeChild, $afterChild, $originalParent, $originalPosition);

        //Move children WidgetMap for children from other View
        foreach ($widgetMap->getChildren() as $child) {
            if ($child->getView() === $view || $child->getView()->getTemplate() === $view) {
                $this->moveWidgetMap($child->getView(), $child, $originalParent, $originalPosition);
            }
        }
    }