コード例 #1
0
ファイル: Category.php プロジェクト: hosivan90/toxotes
 public function executeCreate()
 {
     $this->setView('Category/form');
     $inputTerm = new \stdClass();
     $taxonomy = $this->request()->get('taxonomy', 'STRING', 'category');
     $error = array();
     $term = new \Terms();
     if ($taxonomy == 'category') {
         $this->view()->assign('page_title', t('Add Category'));
     } else {
         $this->view()->assign('page_title', Plugin::applyFilters('custom_' . $taxonomy . '_create_page_title'));
     }
     $parent = $this->request()->post('term_parent', 'INT', 0);
     if (0 == $parent) {
         if ($term->getLevelValue() > 1) {
             $parent = $term->getParent()->getId();
         }
     }
     if ($this->request()->isPostRequest()) {
         //submit new Term
         //assign $inputTerm value
         $inputs = $this->request()->post('term', 'ARRAY', array());
         foreach ($inputs as $input => $value) {
             $inputTerm->{$input} = $value;
         }
         $inputTerm = Plugin::applyFilters('handling_' . $taxonomy . '_term_form_input', $inputTerm);
         if ($this->_save($term, $error)) {
             $session = Session::getInstance();
             $session->setFlash('term', ['type' => 'SUCCESS', 'message' => t('Save successful!')]);
             $this->redirect($this->createUrl('category/default', array('taxonomy' => $taxonomy)));
         }
     }
     $this->dispatch('onBeforeEditTerm', new CMSBackendEvent($this, ['term' => $term]));
     $proControl = $this->_propertyForm($term, $taxonomy);
     $this->view()->assign(array('term' => $term, 'inputTerm' => $inputTerm, 'taxonomy' => $taxonomy, 'parent' => $parent, 'error' => $error, 'propertiesControl' => $proControl));
     return $this->renderComponent();
 }