Example #1
0
 /**
  * Render the operation buttons for the passed model.
  *
  * @param ModelInterface $model    The model to render the buttons for.
  *
  * @param ModelInterface $previous The previous model in the collection.
  *
  * @param ModelInterface $next     The next model in the collection.
  *
  * @return void
  */
 private function renderButtonsFor(ModelInterface $model, ModelInterface $previous = null, ModelInterface $next = null)
 {
     $modelId = ModelId::fromModel($model)->getSerialized();
     if ($this->clipboardItems) {
         $isCircular = in_array(ModelId::fromModel($model)->getSerialized(), $this->circularModelIds);
     } else {
         $isCircular = false;
     }
     $childIds = $this->getChildIds($model);
     $buttons = array();
     foreach ($this->commands->getCommands() as $command) {
         $buttons[$command->getName()] = $this->buildCommand($command, $model, $previous, $next, $isCircular, $childIds);
     }
     if ($this->hasPasteNewButton) {
         $buttons['pasteNew'] = $this->renderPasteNewFor($modelId);
     }
     // Add paste into/after icons.
     if ($this->hasPasteButtons) {
         $urlAfter = $this->addToUrl(sprintf('act=paste&after=%s&', $modelId));
         $urlInto = $this->addToUrl(sprintf('act=paste&into=%s&', $modelId));
         $buttonEvent = new GetPasteButtonEvent($this->environment);
         $buttonEvent->setModel($model)->setCircularReference($isCircular)->setPrevious($previous)->setNext($next)->setHrefAfter($urlAfter)->setHrefInto($urlInto)->setPasteAfterDisabled($isCircular)->setPasteIntoDisabled($isCircular)->setContainedModels($this->clipboardModels);
         $this->eventDispatcher->dispatch(GetPasteButtonEvent::NAME, $buttonEvent);
         $buttons['pasteafter'] = $this->renderPasteAfterButton($buttonEvent);
         if ($this->isHierarchical) {
             $buttons['pasteinto'] = $this->renderPasteIntoButton($buttonEvent);
         }
     }
     $model->setMeta($model::OPERATION_BUTTONS, implode(' ', $buttons));
 }
Example #2
0
 /**
  * Compile buttons from the table configuration array and return them as HTML.
  *
  * @param ModelInterface $model    The model for which the buttons shall be generated for.
  * @param ModelInterface $previous The previous model in the collection.
  * @param ModelInterface $next     The next model in the collection.
  *
  * @return string
  */
 protected function generateButtons(ModelInterface $model, ModelInterface $previous = null, ModelInterface $next = null)
 {
     $environment = $this->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     $basicDefinition = $dataDefinition->getBasicDefinition();
     $commands = $this->getViewSection()->getModelCommands();
     $clipboard = $environment->getClipboard();
     $dispatcher = $environment->getEventDispatcher();
     $filter = new Filter();
     $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
     if ($parentDataProviderName = $basicDefinition->getParentDataProvider()) {
         $filter->andParentIsFromProvider($parentDataProviderName);
     } else {
         $filter->andHasNoParent();
     }
     if ($clipboard->isNotEmpty($filter)) {
         $circularIds = $clipboard->getCircularIds();
         $isCircular = in_array(ModelId::fromModel($model)->getSerialized(), $circularIds);
     } else {
         $circularIds = array();
         $isCircular = false;
     }
     $arrButtons = array();
     foreach ($commands->getCommands() as $command) {
         $arrButtons[$command->getName()] = $this->buildCommand($command, $model, $isCircular, $circularIds, $previous, $next);
     }
     if (ViewHelpers::getManualSortingProperty($this->environment)) {
         $clipboardIsEmpty = $clipboard->isEmpty($filter);
         if ($clipboardIsEmpty && BasicDefinitionInterface::MODE_HIERARCHICAL !== $basicDefinition->getMode()) {
             /** @var AddToUrlEvent $urlEvent */
             $urlEvent = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent('act=create&after=' . ModelId::fromModel($model)->getSerialized()));
             /** @var GenerateHtmlEvent $imageEvent */
             $imageEvent = $dispatcher->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('new.gif', $this->translate('pastenew.0', $this->getDataDefinition()->getName())));
             $arrButtons['pasteNew'] = sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', $urlEvent->getUrl(), specialchars($this->translate('pastenew.1', $this->getDataDefinition()->getName())), $imageEvent->getHtml());
         }
         // Add paste into/after icons.
         if (!$clipboardIsEmpty) {
             if ($clipboard->isCreate()) {
                 // Add ext. information.
                 $add2UrlAfter = sprintf('act=create&after=%s&', ModelId::fromModel($model)->getSerialized());
                 $add2UrlInto = sprintf('act=create&into=%s&', ModelId::fromModel($model)->getSerialized());
             } else {
                 // Add ext. information.
                 $add2UrlAfter = sprintf('act=paste&after=%s&', ModelId::fromModel($model)->getSerialized());
                 $add2UrlInto = sprintf('act=paste&into=%s&', ModelId::fromModel($model)->getSerialized());
             }
             /** @var AddToUrlEvent $urlAfter */
             $urlAfter = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($add2UrlAfter));
             /** @var AddToUrlEvent $urlInto */
             $urlInto = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($add2UrlInto));
             $models = $this->environment->getController()->getModelsFromClipboard($parentDataProviderName ? IdSerializer::fromValues($parentDataProviderName, null) : null);
             $buttonEvent = new GetPasteButtonEvent($this->getEnvironment());
             $buttonEvent->setModel($model)->setCircularReference($isCircular)->setPrevious($previous)->setNext($next)->setHrefAfter($urlAfter->getUrl())->setHrefInto($urlInto->getUrl())->setPasteAfterDisabled($clipboard->isCut() && $isCircular)->setPasteIntoDisabled($clipboard->isCut() && $isCircular)->setContainedModels($models);
             $this->getEnvironment()->getEventDispatcher()->dispatch(GetPasteButtonEvent::NAME, $buttonEvent);
             $arrButtons['pasteafter'] = $this->renderPasteAfterButton($buttonEvent);
             if ($this->getDataDefinition()->getBasicDefinition()->getMode() == BasicDefinitionInterface::MODE_HIERARCHICAL) {
                 $arrButtons['pasteinto'] = $this->renderPasteIntoButton($buttonEvent);
             }
         }
     }
     return implode(' ', $arrButtons);
 }