Example #1
0
 public function entityCommand($categoryName, $entityName, $commandKey, $instanceId, Request $request)
 {
     // Find Entity config (from sharp CMS config file)
     $entity = SharpCmsConfig::findEntity($categoryName, $entityName);
     // Have to manage access auth here, because it can be managed from the config
     $granted = SharpAccessManager::granted('entity', $entity->commands->entity->{$commandKey}->auth ?: "update", $entity->key);
     if (!$granted) {
         return redirect("/");
     }
     $commandForm = $this->commandsManager->getEntityCommandForm($entity, $commandKey);
     $error = false;
     if ($commandForm) {
         // There's a form attached to the command:
         if (!$request->has("sharp_form_valued")) {
             // Return the view of the form
             // to make the user fill parameters before send the command
             return view("sharp::cms.partials.list.commandForm", ['fields' => $commandForm, 'url' => route('cms.entityCommand', array_merge([$categoryName, $entityName, $commandKey, $instanceId], $request->all()))]);
         }
         // Form posted: call the command with the values of the form
         try {
             $commandReturn = $this->commandsManager->executeEntityCommand($entity, $commandKey, $instanceId, $request->only(array_keys($commandForm)));
         } catch (CommandValidationException $ex) {
             $commandReturn = $ex->getMessage();
             $error = true;
         }
     } else {
         $commandReturn = $this->commandsManager->executeEntityCommand($entity, $commandKey, $instanceId);
     }
     return $this->handleCommandReturn($entity->commands->entity->{$commandKey}, $commandReturn, $categoryName, $entityName, $request->except(array_merge(["_token", "sharp_form_valued"], $commandForm ? array_keys($commandForm) : [])), $error);
 }
Example #2
0
 public function entityCommand($categoryName, $entityName, $commandKey, $instanceId)
 {
     // Find Entity config (from sharp CMS config file)
     $entity = SharpCmsConfig::findEntity($categoryName, $entityName);
     // Have to manage access auth here, because it can be managed from the config
     $granted = SharpAccessManager::granted('entity', $entity->commands->entity->{$commandKey}->auth ?: "update", $entity->key);
     if (!$granted) {
         return redirect("/");
     }
     $commandReturn = $this->commandsManager->executeEntityCommand($entity, $commandKey, $instanceId);
     return $this->handleCommandReturn($entity->commands->entity->{$commandKey}, $commandReturn, $categoryName, $entityName);
 }