Ejemplo n.º 1
0
 /**
  * Build a single toggle operation.
  *
  * @param Checkbox $attribute The checkbox attribute.
  *
  * @return ToggleCommandInterface
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function buildCommand($attribute)
 {
     if ($attribute->get('check_listview') == 1) {
         $commandName = 'listviewtoggle_' . $attribute->getColName();
     } else {
         $commandName = 'publishtoggle_' . $attribute->getColName();
     }
     $toggle = new ToggleCommand();
     $toggle->setName($commandName);
     $toggle->setLabel($GLOBALS['TL_LANG']['MSC']['metamodelattribute_checkbox']['toggle'][0]);
     $toggle->setDescription(sprintf($GLOBALS['TL_LANG']['MSC']['metamodelattribute_checkbox']['toggle'][1], $attribute->getName()));
     $extra = $toggle->getExtra();
     $extra['icon'] = 'visible.gif';
     $objIconEnabled = \FilesModel::findByUuid($attribute->get('check_listviewicon'));
     $objIconDisabled = \FilesModel::findByUuid($attribute->get('check_listviewicondisabled'));
     if ($attribute->get('check_listview') == 1 && $objIconEnabled->path && $objIconDisabled->path) {
         $extra['icon'] = $objIconEnabled->path;
         $extra['icon_disabled'] = $objIconDisabled->path;
     } else {
         $extra['icon'] = 'visible.gif';
     }
     $toggle->setToggleProperty($attribute->getColName());
     return $toggle;
 }
 /**
  * Create the correct command instance for the given information.
  *
  * @param string $commandName The name of the command to create.
  *
  * @param array  $commandDca  The Dca information of the command.
  *
  * @return CommandInterface
  */
 protected function createCommandInstance($commandName, array &$commandDca)
 {
     switch ($commandName) {
         case 'cut':
             return new CutCommand();
         case 'copy':
         case 'deepcopy':
             return new CopyCommand();
         case 'all':
             return new SelectCommand();
         case 'toggle':
             $command = new ToggleCommand();
             if (isset($commandDca['toggleProperty'])) {
                 $command->setToggleProperty($commandDca['toggleProperty']);
                 unset($commandDca['toggleProperty']);
             } else {
                 // Implicit fallback to "published" as in Contao core.
                 $command->setToggleProperty('published');
             }
             if (isset($commandDca['toggleInverse'])) {
                 $command->setInverse($commandDca['toggleInverse']);
                 unset($commandDca['toggleInverse']);
             }
             return $command;
         default:
     }
     return new Command();
 }