/** * Retrieve possible suggestions for a field name * * @param string $fieldNameAndPath * @return array */ public function getSuggestions($fieldNameAndPath) { $values = array(); $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) { $values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions(); } else { if (Tca::table($dataType)->hasField($fieldName)) { if (Tca::table($dataType)->field($fieldName)->hasRelation()) { // Fetch the adequate repository $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); $contentRepository = ContentRepositoryFactory::getInstance($foreignTable); $table = Tca::table($foreignTable); // Initialize the matcher object. $matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $foreignTable); $numberOfValues = $contentRepository->countBy($matcher); if ($numberOfValues <= $this->getLimit()) { $contents = $contentRepository->findBy($matcher); foreach ($contents as $content) { $values[] = array($content->getUid() => $content[$table->getLabelField()]); } } } elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) { // We don't want suggestion if field is text area. // Fetch the adequate repository /** @var \Fab\Vidi\Domain\Repository\ContentRepository $contentRepository */ $contentRepository = ContentRepositoryFactory::getInstance($dataType); // Initialize some objects related to the query $matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $dataType); // Count the number of objects. $numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher); // Only returns suggestion if there are not too many for the browser. if ($numberOfValues <= $this->getLimit()) { // Query the repository. $contents = $contentRepository->findDistinctValues($fieldName, $matcher); foreach ($contents as $content) { $value = $content[$fieldName]; $label = $content[$fieldName]; if (Tca::table($dataType)->field($fieldName)->isSelect()) { $label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value); } $values[] = $label; } } } } } return $values; }
/** * Save data into the clipboard. * * @param array $matches * @return string */ public function saveAction(array $matches = array()) { $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches); $this->getClipboardService()->save($matcher); // Fetch objects via the Content Service. $contentService = $this->getContentService()->findBy($matcher); $numberOfObjects = $contentService->getNumberOfObjects(); if ($numberOfObjects === 0) { $this->getClipboardService()->flush(); } # Json header is not automatically sent in the BE... $this->response->setHeader('Content-Type', 'application/json'); $this->response->sendHeaders(); return json_encode($numberOfObjects); }
/** * Retrieve Content objects first according to matching criteria and then "localize" them. * * Possible values for $matches, refer to method "updateAction". * * @param string $fieldNameAndPath * @param array $matches * @param int $language * @return string * @throws \Exception */ public function localizeAction($fieldNameAndPath, array $matches = array(), $language = 0) { $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches); // Fetch objects via the Content Service. $contentService = $this->getContentService()->findBy($matcher); // Get result object for storing data along the processing. $result = $this->getJsonResult(); $result->setNumberOfObjects($contentService->getNumberOfObjects()); foreach ($contentService->getObjects() as $object) { $identifier = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, 'uid'); $dataType = $this->getContentObjectResolver()->getDataType($object, $fieldNameAndPath); // Fetch the source object to be localized. /** @var Content $content */ $content = ContentRepositoryFactory::getInstance($dataType)->findByIdentifier($identifier); // Makes sure the object was retrieved. Security! if (!$content) { $message = sprintf('Something went wrong when retrieving content "%s" with identifier "%s".', $dataType, $identifier); throw new \Exception($message, 1412343097); } // Handover the localization to the Repository. ContentRepositoryFactory::getInstance($dataType)->localize($content, $language); // Get the possible error messages and store them. $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages(); // Redirect to TCEForm so that the BE User can do its job! if ($contentService->getNumberOfObjects() === 1) { if (!empty($errorMessages)) { $message = sprintf('Something went wrong when localizing content "%s" with identifier "%s". <br/>%s', $dataType, $identifier, implode('<br/>', $errorMessages)); throw new \Exception($message, 1412343098); } $localizedContent = $this->getLanguageService()->getLocalizedContent($content, $language); if (empty($localizedContent)) { $message = sprintf('Oups! I could not retrieve localized content of type "%s" with identifier "%s"', $content->getDataType(), $content->getUid()); throw new \Exception($message, 1412343099); } /** @var \Fab\Vidi\View\Uri\EditUri $uri */ $uriRenderer = GeneralUtility::makeInstance('Fab\\Vidi\\View\\Uri\\EditUri'); $uri = $uriRenderer->render($localizedContent); HttpUtility::redirect($uri); break; // no need to further continue } $result->addErrorMessages($errorMessages); } // Set the result and render the JSON view. $this->getJsonView()->setResult($result); return $this->getJsonView()->render(); }
/** * Returns an editing form for moving Files between storage. * * @param array $matches * @throws \Exception */ public function editStorageAction(array $matches = array()) { $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages()); $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle()); $fieldName = 'storage'; // Instantiate the Matcher object according different rules. $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType); // Fetch objects via the Content Service. $contentService = $this->getContentService()->findBy($matcher); $fieldType = Tca::table($this->dataType)->field($fieldName)->getType(); $this->view->assign('fieldType', ucfirst($fieldType)); $this->view->assign('dataType', $this->dataType); $this->view->assign('matches', $matches); $this->view->assign('fieldNameAndPath', $fieldName); $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects()); $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary?? }