/** * Test andActionIs filter. * * @dataProvider provideActions() */ public function testAndActionIs($action1, $action2) { $filter = new Filter(); $filter->andSub(new MockedFilter(true)); $filter->andActionIs($action1); $item = new MockedAbstractItem($action1); $this->assertEquals(true, $filter->accepts($item)); $item2 = new MockedAbstractItem($action2); $this->assertEquals(false, $filter->accepts($item2)); }
/** * Handle "old" add to clipboard actions. * * @param ActionEvent $event The action event. * * @return void */ private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = ModelId::fromSerialized($parentIdRaw); } else { $parentId = null; } $clipboardActionName = $this->translateActionName($actionName); if (!$clipboardActionName) { return; } if ('create' === $actionName) { if ($this->isAddingAllowed($environment)) { return; } $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider(); $item = new UnsavedItem($clipboardActionName, $parentId, $providerName); // Remove other create items, there can only be one create item in the clipboard or many others $clipboard->clear(); } else { $modelIdRaw = $input->getParameter('source'); $modelId = ModelId::fromSerialized($modelIdRaw); $filter = new Filter(); $filter->andActionIs(ItemInterface::CREATE); $items = $clipboard->fetch($filter); foreach ($items as $item) { $clipboard->remove($item); } // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); } // Let the clipboard save it's values persistent. $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); }
/** * Check the buttons based on the action. * * @param ClipboardInterface $clipboard The clipboard. * * @param string $action The action to be checked. * * @return void */ protected function checkForAction($clipboard, $action) { // Make a filter for the given action. $filter = new Filter(); $filter->andActionIs($action); $items = $clipboard->fetch($filter); // Check if there are items. if ($items === null) { return; } /** @var ItemInterface[] $items */ foreach ($items as $item) { // Check the context. $itemProviderName = $item->getModelId()->getDataProviderName(); $modelId = $item->getModelId()->getId(); if ($this->providerName !== $itemProviderName) { continue; } $containedModel = $this->getModelById($modelId); if ($this->currentModel == null) { $this->checkForRoot($containedModel, $action); } elseif ($containedModel) { $this->checkForModel($containedModel, $action); } else { $this->checkEmpty($action); } } }
/** * Handle "old" add to clipboard actions. * * @param ActionEvent $event The action event. * * @return void */ private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = ModelId::fromSerialized($parentIdRaw); } else { $parentId = null; } $clipboardActionName = $this->translateActionName($actionName); if (!$clipboardActionName) { return; } if ('create' === $actionName) { $inputProvider = $environment->getInputProvider(); // No manual sorting property defined, no need to add it to the clipboard. // Or we already have an after attribute, a handler can pick it up. if (!ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after')) { return; } $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider(); $item = new UnsavedItem($clipboardActionName, $parentId, $providerName); // Remove other create items, there can only be one create item in the clipboard or many others $clipboard->clear(); } else { $modelIdRaw = $input->getParameter('source'); $modelId = ModelId::fromSerialized($modelIdRaw); $filter = new Filter(); $filter->andActionIs(ItemInterface::CREATE); $items = $clipboard->fetch($filter); foreach ($items as $item) { $clipboard->remove($item); } // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); } // Let the clipboard save it's values persistent. // TODO remove clear and allow adding multiple items // Clipboard get cleared twice so far if being in create mode and partially in others. Don't know why it's here. $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); }