public function testAddTwoBeforeNonExistant() { $collection = new CommandCollection(); $command1 = new Command(); $command1->setName('test1'); $command2 = new Command(); $command2->setName('test2'); $command3 = new Command(); $command3->setName('test3'); $this->setExpectedException('ContaoCommunityAlliance\\DcGeneral\\Exception\\DcGeneralInvalidArgumentException'); $collection->addCommands(array($command1, $command2), $command3); $this->assertTrue($collection->hasCommand($command1)); $this->assertTrue($collection->hasCommandNamed('test1')); $this->assertTrue($collection->hasCommand($command2)); $this->assertTrue($collection->hasCommandNamed('test2')); $this->assertFalse($collection->hasCommand($command3)); $this->assertFalse($collection->hasCommandNamed('test3')); $this->assertIndexIs(0, $collection->getCommands(), $command1); $this->assertIndexIs(1, $collection->getCommands(), $command2); $this->assertIndexIs(false, $collection->getCommands(), $command3); }
/** * Create the "back" button. * * @return null|Command */ protected function getBackCommand() { $environment = $this->getEnvironment(); if (!($this->isSelectModeActive() || $environment->getDataDefinition()->getBasicDefinition()->getParentDataProvider())) { return null; } /** @var GetReferrerEvent $event */ if ($environment->getParentDataDefinition()) { $event = $environment->getEventDispatcher()->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, new GetReferrerEvent(true, $environment->getParentDataDefinition()->getName())); } else { $event = $environment->getEventDispatcher()->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, new GetReferrerEvent(true, $environment->getDataDefinition()->getName())); } $command = new Command(); $extra = $command->getExtra(); $extra['class'] = 'header_back'; $extra['accesskey'] = 'b'; $extra['attributes'] = 'onclick="Backend.getScrollOffset();"'; $extra['href'] = $event->getReferrerUrl(); $command->setName('back_button')->setLabel($this->translate('MSC.backBT'))->setDescription($this->translate('MSC.backBT')); return $command; }
/** * 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; }