Example #1
0
 /**
  * Handle the paste into and after buttons.
  *
  * @param GetPasteButtonEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When more than one model is contained within the clipboard.
  */
 public function handle(GetPasteButtonEvent $event)
 {
     $this->circularReference = $event->isCircularReference();
     $this->environment = $event->getEnvironment();
     $this->provider = $this->environment->getDataProvider();
     $this->providerName = $this->provider->getEmptyModel()->getProviderName();
     $clipboard = $this->environment->getClipboard();
     $this->currentModel = $event->getModel();
     $this->disablePI = true;
     $this->disablePA = true;
     // Only run for a MetaModels and if both values already disabled return here.
     if (substr($this->providerName, 0, 3) !== 'mm_' || $event->isPasteIntoDisabled() && $event->isPasteAfterDisabled()) {
         return;
     }
     $this->checkForAction($clipboard, 'copy');
     $this->checkForAction($clipboard, 'create');
     $this->checkForAction($clipboard, 'cut');
     $event->setPasteAfterDisabled($this->disablePA)->setPasteIntoDisabled($this->disablePI);
 }
 /**
  * Update the versioning information in the data provider for a given model (if necessary).
  *
  * @param ModelInterface $model The model to update.
  *
  * @return void
  */
 private function storeVersion(ModelInterface $model)
 {
     if (!$this->modelProvider->isVersioningEnabled()) {
         return;
     }
     $environment = $this->environment;
     $modelId = $model->getId();
     $dataProvider = $environment->getDataProvider($this->model->getProviderName());
     $currentVersion = $dataProvider->getActiveVersion($modelId);
     // Compare version and current record.
     if (!$currentVersion || !$dataProvider->sameModels($model, $dataProvider->getVersion($modelId, $currentVersion))) {
         $user = \FrontendUser::getInstance();
         $username = '******';
         if ($user->authenticate()) {
             $username = $user->username;
         }
         $dataProvider->saveVersion($model, $username);
     }
 }
 /**
  * Handle a property in a cloned model.
  *
  * @param ModelInterface        $model        The cloned model.
  *
  * @param PropertyInterface     $property     The property to handle.
  *
  * @param DataProviderInterface $dataProvider The data provider the model originates from.
  *
  * @return void
  */
 private function handleClonedModelProperty(ModelInterface $model, PropertyInterface $property, DataProviderInterface $dataProvider)
 {
     $extra = $property->getExtra();
     $propName = $property->getName();
     // Check doNotCopy.
     if (isset($extra['doNotCopy']) && $extra['doNotCopy'] === true) {
         $model->setProperty($propName, null);
         return;
     }
     // Check uniqueness.
     if (isset($extra['unique']) && $extra['unique'] === true && !$dataProvider->isUniqueValue($propName, $model->getProperty($propName))) {
         // Implicit "do not copy" unique values, they cannot be unique anymore.
         $model->setProperty($propName, null);
     }
 }
Example #4
0
 /**
  * Retrieve the children of a model (if any exist).
  *
  * @param DataProviderInterface         $dataProvider   The data provider.
  *
  * @param ModelInterface                $model          The model.
  *
  * @param ParentChildConditionInterface $childCondition The condition.
  *
  * @return CollectionInterface|null
  */
 private function getChildrenOfModel($dataProvider, $model, $childCondition)
 {
     $childIds = $dataProvider->fetchAll($dataProvider->getEmptyConfig()->setFilter($childCondition->getFilter($model))->setIdOnly(true));
     if (!$childIds) {
         return null;
     }
     return $dataProvider->fetchAll($dataProvider->getEmptyConfig()->setSorting(array('sorting' => 'ASC'))->setFilter(FilterBuilder::fromArray()->getFilter()->andPropertyValueIn('id', $childIds)->getAllAsArray()));
 }
 /**
  * Remove an entity.
  *
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException If an invalid entity type is given.
  */
 public function remove($entity)
 {
     Assertion::isInstanceOf($entity, 'ContaoCommunityAlliance\\DcGeneral\\Data\\ModelInterface', 'Entity repository requires an instance of the ModelInterface');
     $this->provider->delete($entity);
 }