GcContent\Controller\TranslationController::indexAction PHP Méthode

indexAction() public méthode

List and edit translation
public indexAction ( ) : Zend\View\Model\ViewModel | array
Résultat Zend\View\Model\ViewModel | array
    public function indexAction()
    {
        $translationForm = new Form\Translation();
        $translationForm->prepareForm($this->getServiceLocator()->get('Config'));
        $translationForm->setAttribute('action', $this->url()->fromRoute('content/translation'));
        if ($this->getRequest()->isPost()) {
            $post = $this->getRequest()->getPost();
            if (empty($post['source']) or empty($post['destination'])) {
                return $this->redirect()->toRoute('content/translation');
            }
            $translator = new Translator();
            foreach ($post['source'] as $sourceId => $source) {
                $translator->update(array('source' => $source), sprintf('id = %d', $sourceId));
                if (!empty($post['destination'][$sourceId])) {
                    $translator->setValue($sourceId, $post['destination'][$sourceId]);
                }
            }
            $translator->generateCache();
            $this->flashMessenger()->addSuccessMessage('Translation saved !');
            return $this->redirect()->toRoute('content/translation');
        }
        $translator = new Translator();
        return array('form' => $translationForm, 'values' => $translator->getValues());
    }