Beispiel #1
0
 /**
  * Handle the action.
  *
  * @return void
  */
 public function process()
 {
     $environment = $this->getEnvironment();
     $inputProvider = $environment->getInputProvider();
     $event = $this->getEvent();
     $action = $event->getAction();
     // Only handle if we do not have a manual sorting or we know where to insert.
     // Manual sorting is handled by clipboard.
     if ($action->getName() !== 'create' || ViewHelpers::getManualSortingProperty($environment) && !$inputProvider->hasParameter('after') && !$inputProvider->hasParameter('into')) {
         return;
     }
     $definition = $environment->getDataDefinition();
     $dataProvider = $environment->getDataProvider();
     $propertyDefinition = $definition->getPropertiesDefinition();
     $properties = $propertyDefinition->getProperties();
     $model = $dataProvider->getEmptyModel();
     $clone = $dataProvider->getEmptyModel();
     // If some of the fields have a default value, set it.
     foreach ($properties as $property) {
         $propName = $property->getName();
         if ($property->getDefaultValue() !== null) {
             $model->setProperty($propName, $property->getDefaultValue());
             $clone->setProperty($propName, $property->getDefaultValue());
         }
     }
     $view = $environment->getView();
     if (!$view instanceof BaseView) {
         return;
     }
     $editMask = new EditMask($view, $model, $clone, null, null, $view->breadcrumb());
     $event->setResponse($editMask->execute());
 }
 /**
  * Handle the action.
  *
  * @return void
  */
 public function process()
 {
     $environment = $this->getEnvironment();
     $inputProvider = $environment->getInputProvider();
     $event = $this->getEvent();
     $action = $event->getAction();
     // Only handle if we does not have a manual sorting or we know where to insert.
     // Manual sorting is handled by clipboard.
     if ($action->getName() !== 'create' || ViewHelpers::getManualSortingProperty($environment) && !$inputProvider->hasParameter('after')) {
         return;
     }
     $dataProvider = $environment->getDataProvider();
     $model = $dataProvider->getEmptyModel();
     $clone = $dataProvider->getEmptyModel();
     $view = $environment->getView();
     if (!$view instanceof BaseView) {
         return;
     }
     $editMask = new EditMask($view, $model, $clone, null, null, $view->breadcrumb());
     $event->setResponse($editMask->execute());
 }
 /**
  * Handle the "create variant" event.
  *
  * @param ActionEvent $event The action Event being executed.
  *
  * @return void
  *
  * @throws \RuntimeException When the base model can not be found.
  * @throws \InvalidArgumentException When the view in the environment is incompatible.
  */
 public function handleCreateVariantAction(ActionEvent $event)
 {
     if ($event->getAction()->getName() != 'createvariant') {
         return;
     }
     $environment = $event->getEnvironment();
     $view = $environment->getView();
     $dataProvider = $environment->getDataProvider();
     $inputProvider = $environment->getInputProvider();
     $modelId = $inputProvider->hasParameter('id') ? ModelId::fromSerialized($inputProvider->getParameter('id')) : null;
     /** @var \MetaModels\DcGeneral\Data\Driver $dataProvider */
     $model = $dataProvider->createVariant($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     if ($model == null) {
         throw new \RuntimeException(sprintf('Could not find model with id %s for creating a variant.', $modelId));
     }
     $metaModel = $this->getServiceContainer()->getFactory()->getMetaModel($model->getProviderName());
     if (!$metaModel || !$metaModel->hasVariants()) {
         return;
     }
     $preFunction = function ($environment, $model) {
         /** @var EnvironmentInterface $environment */
         $copyEvent = new PreCreateModelEvent($environment, $model);
         $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent);
     };
     $postFunction = function ($environment, $model) {
         /** @var EnvironmentInterface $environment */
         $copyEvent = new PostCreateModelEvent($environment, $model);
         $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent);
     };
     if (!$view instanceof BackendViewInterface) {
         throw new \InvalidArgumentException('Invalid view registered in environment.');
     }
     $editMask = new EditMask($view, $model, null, $preFunction, $postFunction, $this->breadcrumb($environment));
     $event->setResponse($editMask->execute());
 }
Beispiel #4
0
 /**
  * Create the edit mask.
  *
  * @param ModelInterface $model         The model with the current data.
  *
  * @param ModelInterface $originalModel The data from the original data.
  *
  * @param callable       $preFunction   The function to call before saving an item.
  *
  * @param callable       $postFunction  The function to call after saving an item.
  *
  * @return string
  *
  * @throws DcGeneralRuntimeException         If the data container is not editable, closed.
  *
  * @throws DcGeneralInvalidArgumentException If an unknown property is encountered in the palette.
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 protected function createEditMask($model, $originalModel, $preFunction, $postFunction)
 {
     $editMask = new EditMask($this, $model, $originalModel, $preFunction, $postFunction, $this->breadcrumb());
     return $editMask->execute();
 }