Exemple #1
0
 /**
  * Render the paste after button.
  *
  * @param GetPasteButtonEvent $event The event that has been triggered.
  *
  * @return string
  */
 public function renderPasteAfterButton(GetPasteButtonEvent $event)
 {
     if ($event->getHtmlPasteAfter() !== null) {
         return $event->getHtmlPasteAfter();
     }
     $model = $event->getModel();
     $modelId = IdSerializer::fromModel($model);
     $environment = $event->getEnvironment();
     $controller = $environment->getController();
     $clipboard = $environment->getClipboard();
     $dataDefinition = $environment->getDataDefinition();
     $basicDefinition = $dataDefinition->getBasicDefinition();
     $pasteAfterIsDisabled = $event->isPasteAfterDisabled();
     if (!$pasteAfterIsDisabled) {
         // pre-build filter, to fetch other items
         $filter = new Filter();
         $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
         if ($parentDataProviderName = $basicDefinition->getParentDataProvider()) {
             $filter->andParentIsFromProvider($parentDataProviderName);
         } else {
             $filter->andHasNoParent();
         }
         $filter->andModelIsNot($modelId);
         /*
          * FIXME to be discussed, allow pasting only in the same grouping
                 }
                 /** @var Filter $filter Prevent IDE from saying $filter may be undefined! ;-D * /
         
                 if (!$pasteAfterIsDisabled) {
         // Determine if the grouping is the same
         $groupingMode = ViewHelpers::getGroupingMode($environment);
         
         if ($groupingMode) {
             $items  = $clipboard->fetch($filter);
             $models = $controller->getModelsFromClipboardItems($items);
             $propertyName = $groupingMode['property'];
             $propertyValue = $model->getProperty($propertyName);
         
             $pasteAfterIsDisabled = true;
             foreach ($models as $clipboardModel) {
                 if ($propertyValue === $clipboardModel->getProperty($propertyName)) {
                     // there exist at least one item, with the same grouping
                     $pasteAfterIsDisabled = false;
                     break;
                 }
             }
         }
                 }
         
                 if (!$pasteAfterIsDisabled) {
         */
         $pasteAfterIsDisabled = $clipboard->isEmpty($filter);
     }
     $strLabel = $this->translate('pasteafter.0', $model->getProviderName());
     if ($pasteAfterIsDisabled) {
         /** @var GenerateHtmlEvent $imageEvent */
         $imageEvent = $environment->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pasteafter_.gif', $strLabel, 'class="blink"'));
         return $imageEvent->getHtml();
     }
     /** @var GenerateHtmlEvent $imageEvent */
     $imageEvent = $environment->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pasteafter.gif', $strLabel, 'class="blink"'));
     $opDesc = $this->translate('pasteafter.1', $environment->getDataDefinition()->getName());
     if (strlen($opDesc)) {
         $title = sprintf($opDesc, $model->getId());
     } else {
         $title = sprintf('%s id %s', $strLabel, $model->getId());
     }
     return sprintf(' <a href="%s" title="%s" %s>%s</a>', $event->getHrefAfter(), specialchars($title), 'onclick="Backend.getScrollOffset()"', $imageEvent->getHtml());
 }
Exemple #2
0
 /**
  * Render the paste after button.
  *
  * @param GetPasteButtonEvent $event The event that has been triggered.
  *
  * @return string
  */
 private function renderPasteAfterButton(GetPasteButtonEvent $event)
 {
     if (null !== ($value = $event->getHtmlPasteAfter())) {
         return $value;
     }
     $label = $this->translate('pasteafter.0');
     if ($event->isPasteAfterDisabled()) {
         return $this->renderImageAsHtml('pasteafter_.gif', $label, 'class="blink"');
     }
     if ('pasteafter.1' !== ($opDesc = $this->translate('pasteafter.1'))) {
         $title = sprintf($opDesc, $event->getModel()->getId());
     } else {
         $title = sprintf('%s id %s', $label, $event->getModel()->getId());
     }
     return sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', $event->getHrefAfter(), specialchars($title), $this->renderImageAsHtml('pasteafter.gif', $label, 'class="blink"'));
 }
Exemple #3
0
 /**
  * Render the paste after button.
  *
  * @param GetPasteButtonEvent $event The event that has been triggered.
  *
  * @return string
  */
 public function renderPasteAfterButton(GetPasteButtonEvent $event)
 {
     if (!is_null($event->getHtmlPasteAfter())) {
         return $event->getHtmlPasteAfter();
     }
     $strLabel = $this->translate('pasteafter.0', $event->getModel()->getProviderName());
     if ($event->isPasteAfterDisabled()) {
         /** @var GenerateHtmlEvent $imageEvent */
         $imageEvent = $this->getEnvironment()->getEventPropagator()->propagate(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pasteafter_.gif', $strLabel, 'class="blink"'));
         return $imageEvent->getHtml();
     }
     /** @var GenerateHtmlEvent $imageEvent */
     $imageEvent = $this->getEnvironment()->getEventPropagator()->propagate(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pasteafter.gif', $strLabel, 'class="blink"'));
     $opDesc = $this->translate('pasteafter.1', $this->getEnvironment()->getDataDefinition()->getName());
     if (strlen($opDesc)) {
         $title = sprintf($opDesc, $event->getModel()->getId());
     } else {
         $title = sprintf('%s id %s', $strLabel, $event->getModel()->getId());
     }
     return sprintf(' <a href="%s" title="%s" %s>%s</a>', $event->getHrefAfter(), specialchars($title), 'onclick="Backend.getScrollOffset()"', $imageEvent->getHtml());
 }