/**
  * Generate the toggle command information.
  *
  * @param CommandCollectionInterface $commands    The already existing commands.
  *
  * @param IAttribute                 $attribute   The attribute.
  *
  * @param string                     $commandName The name of the new command.
  *
  * @param string                     $class       The name of the CSS class for the command.
  *
  * @param string                     $language    The language name.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function generateToggleCommand($commands, $attribute, $commandName, $class, $language)
 {
     if (!$commands->hasCommandNamed($commandName)) {
         $toggle = new TranslatedToggleCommand();
         $toggle->setLanguage($language)->setToggleProperty($attribute->getColName())->setName($commandName)->setLabel($GLOBALS['TL_LANG']['MSC']['metamodelattribute_translatedcheckbox']['toggle'][0])->setDescription(sprintf($GLOBALS['TL_LANG']['MSC']['metamodelattribute_translatedcheckbox']['toggle'][1], $attribute->getName(), $language));
         $extra = $toggle->getExtra();
         $extra['icon'] = 'visible.gif';
         $extra['class'] = $class;
         if ($commands->hasCommandNamed('show')) {
             $info = $commands->getCommandNamed('show');
         } else {
             $info = null;
         }
         $commands->addCommand($toggle, $info);
     }
 }
Example #2
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 #3
0
 /**
  * Retrieve or create a command instance of the given name.
  *
  * @param CommandCollectionInterface $collection    The command collection.
  *
  * @param string                     $operationName The name of the operation.
  *
  * @return CommandInterface
  */
 protected function getCommandInstance(CommandCollectionInterface $collection, $operationName)
 {
     if ($collection->hasCommandNamed($operationName)) {
         $command = $collection->getCommandNamed($operationName);
     } else {
         switch ($operationName) {
             case 'cut':
                 $command = new CutCommand();
                 break;
             case 'copy':
                 $command = new CopyCommand();
                 break;
             default:
                 $command = new Command();
         }
         $command->setName($operationName);
         $collection->addCommand($command);
     }
     return $command;
 }