src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
public function handleView(ViewEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        if (DcGeneralViews::CLIPBOARD !== $event->getViewName()) {
            return;
        }

        $environment     = $event->getEnvironment();
        $input           = $environment->getInputProvider();
        $eventDispatcher = $environment->getEventDispatcher();
        $basicDefinition = $environment->getDataDefinition()->getBasicDefinition();

        $filter = new Filter();
        $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
        if ($parentProviderName = $basicDefinition->getParentDataProvider()) {
            $filter->andParentIsFromProvider($parentProviderName);
        } else {
            $filter->andHasNoParent();
        }

        $options = [];
        foreach ($environment->getClipboard()->fetch($filter) as $item) {
            $modelId      = $item->getModelId();
            $dataProvider = $environment->getDataProvider($item->getDataProviderName());

            if ($modelId) {
                $config = $dataProvider->getEmptyConfig();
                $config->setId($modelId->getId());
                $model = $dataProvider->fetch($config);

                // The model might have been deleted meanwhile.
                if (!$model) {
                    continue;
                }

                $formatModelLabelEvent = new FormatModelLabelEvent($environment, $model);
                $eventDispatcher->dispatch(DcGeneralEvents::FORMAT_MODEL_LABEL, $formatModelLabelEvent);
                $label = $formatModelLabelEvent->getLabel();
                $label = \array_shift($label);
                $label = $label['content'];
            } else {
                $model = $dataProvider->getEmptyModel();
                $label = $environment->getTranslator()->translate('new.0', $item->getDataProviderName());
            }

            $options[$item->getClipboardId()] = ['item'  => $item, 'model' => $model, 'label' => $label];
        }

        $inputAction   = $input->getParameter('act');
        $addToUrlEvent = new AddToUrlEvent('act=clear-clipboard&original-act=' . $inputAction);
        $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent);
        $clearUrl = $addToUrlEvent->getUrl();

        $addToUrlEvent = new AddToUrlEvent(
            'clipboard-item=%id%&act=clear-clipboard&original-act=' . $inputAction
        );
        $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent);
        $clearItemUrl = $addToUrlEvent->getUrl();

        $template = new ContaoBackendViewTemplate('dcbe_general_clipboard');
        $template
            ->set('environment', $environment)
            ->set('options', $options)
            ->set('clearUrl', $clearUrl)
            ->set('clearItemUrl', $clearItemUrl);

        $event->setResponse($template->parse());
    }
public function handleView(ViewEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        if (DcGeneralViews::CLIPBOARD !== $event->getViewName()) {
            return;
        }

        $environment     = $event->getEnvironment();
        $input           = $environment->getInputProvider();
        $eventDispatcher = $environment->getEventDispatcher();
        $basicDefinition = $environment->getDataDefinition()->getBasicDefinition();

        $filter = new Filter();
        $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
        if ($parentProviderName = $basicDefinition->getParentDataProvider()) {
            $filter->andParentIsFromProvider($parentProviderName);
        } else {
            $filter->andHasNoParent();
        }

        $options = [];
        foreach ($environment->getClipboard()->fetch($filter) as $item) {
            $modelId      = $item->getModelId();
            $dataProvider = $environment->getDataProvider($item->getDataProviderName());

            if ($modelId) {
                $config = $dataProvider->getEmptyConfig();
                $config->setId($modelId->getId());
                $model = $dataProvider->fetch($config);

                // The model might have been deleted meanwhile.
                if (!$model) {
                    continue;
                }

                $formatModelLabelEvent = new FormatModelLabelEvent($environment, $model);
                $eventDispatcher->dispatch(DcGeneralEvents::FORMAT_MODEL_LABEL, $formatModelLabelEvent);
                $label = $formatModelLabelEvent->getLabel();
                $label = \array_shift($label);
                $label = $label['content'];
            } else {
                $model = $dataProvider->getEmptyModel();
                $label = $environment->getTranslator()->translate('new.0', $item->getDataProviderName());
            }

            $options[$item->getClipboardId()] = ['item'  => $item, 'model' => $model, 'label' => $label];
        }

        $inputAction   = $input->getParameter('act');
        $addToUrlEvent = new AddToUrlEvent('act=clear-clipboard&original-act=' . $inputAction);
        $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent);
        $clearUrl = $addToUrlEvent->getUrl();

        $addToUrlEvent = new AddToUrlEvent(
            'clipboard-item=%id%&act=clear-clipboard&original-act=' . $inputAction
        );
        $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent);
        $clearItemUrl = $addToUrlEvent->getUrl();

        $template = new ContaoBackendViewTemplate('dcbe_general_clipboard');
        $template
            ->set('environment', $environment)
            ->set('options', $options)
            ->set('clearUrl', $clearUrl)
            ->set('clearItemUrl', $clearItemUrl);

        $event->setResponse($template->parse());
    }
public function handleView ( ViewEvent $ event ) { if ( ! $ this -> scopeDeterminator -> currentScopeIsBackend ( ) ) { return ; } if ( DcGeneralViews :: CLIPBOARD !== $ event -> getViewName ( ) ) { return ; } $ environment = $ event -> getEnvironment ( ) ; $ input = $ environment -> getInputProvider ( ) ; $ eventDispatcher = $ environment -> getEventDispatcher ( ) ; $ basicDefinition = $ environment -> getDataDefinition ( ) -> getBasicDefinition ( ) ; $ filter = new Filter ( ) ; $ filter -> andModelIsFromProvider ( $ basicDefinition -> getDataProvider ( ) ) ; if ( $ parentProviderName = $ basicDefinition -> getParentDataProvider ( ) ) { $ filter -> andParentIsFromProvider ( $ parentProviderName ) ; } else { $ filter -> andHasNoParent ( ) ; } $ options = [ ] ; foreach ( $ environment -> getClipboard ( ) -> fetch ( $ filter ) as $ item ) { $ modelId = $ item -> getModelId ( ) ; $ dataProvider = $ environment -> getDataProvider ( $ item -> getDataProviderName ( ) ) ; if ( $ modelId ) { $ config = $ dataProvider -> getEmptyConfig ( ) ; $ config -> setId ( $ modelId -> getId ( ) ) ; $ model = $ dataProvider -> fetch ( $ config ) ; // The model might have been deleted meanwhile. if ( ! $ model ) { continue ; } $ formatModelLabelEvent = new FormatModelLabelEvent ( $ environment , $ model ) ; $ eventDispatcher -> dispatch ( DcGeneralEvents :: FORMAT_MODEL_LABEL , $ formatModelLabelEvent ) ; $ label = $ formatModelLabelEvent -> getLabel ( ) ; $ label = \ array_shift ( $ label ) ; $ label = $ label [ 'content' ] ; } else { $ model = $ dataProvider -> getEmptyModel ( ) ; $ label = $ environment -> getTranslator ( ) -> translate ( 'new.0' , $ item -> getDataProviderName ( ) ) ; } $ options [ $ item -> getClipboardId ( ) ] = [ 'item' => $ item , 'model' => $ model , 'label' => $ label ] ; } $ inputAction = $ input -> getParameter ( 'act' ) ; $ addToUrlEvent = new AddToUrlEvent ( 'act=clear-clipboard&original-act=' . $ inputAction ) ; $ eventDispatcher -> dispatch ( ContaoEvents :: BACKEND_ADD_TO_URL , $ addToUrlEvent ) ; $ clearUrl = $ addToUrlEvent -> getUrl ( ) ; $ addToUrlEvent = new AddToUrlEvent ( 'clipboard-item=%id%&act=clear-clipboard&original-act=' . $ inputAction ) ; $ eventDispatcher -> dispatch ( ContaoEvents :: BACKEND_ADD_TO_URL , $ addToUrlEvent ) ; $ clearItemUrl = $ addToUrlEvent -> getUrl ( ) ; $ template = new ContaoBackendViewTemplate ( 'dcbe_general_clipboard' ) ; $ template -> set ( 'environment' , $ environment ) -> set ( 'options' , $ options ) -> set ( 'clearUrl' , $ clearUrl ) -> set ( 'clearItemUrl' , $ clearItemUrl ) ; $ event -> setResponse ( $ template -> parse ( ) ) ; }
Handle view.

@param ViewEvent $event The view event.

@return void
Handle view .