/** * 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); } } }
/** * Test if the current paste action is a simple paste for the passed data provider. * * @param ClipboardInterface $clipboard The clipboard instance. * @param string $provider The provider name. * * @return bool */ private function isSimpleCreatePaste(ClipboardInterface $clipboard, $provider) { $filter = new Filter(); $all = $clipboard->fetch($filter); return 1 === count($all) && $all[0]->isCreate() && null === $all[0]->getModelId() && $all[0]->getDataProviderName() === $provider; }