/** * Bootstrap the module * * @param Application $application * @return void */ public static function bootstrap(Application $application) { $forms = $application->config()['forms']; $cat = new Model\Category(); $cat->getAll(); if (count($cat->getFlatMap()) > 0) { $categoryValues = $cat->getCategoryValues(); if (isset($forms['Phire\\Content\\Form\\Content'])) { $forms['Phire\\Content\\Form\\Content'][0]['categories'] = ['type' => 'checkbox', 'label' => 'Categories', 'value' => $categoryValues]; $forms['Phire\\Content\\Form\\Content'][0]['category_type'] = ['type' => 'hidden', 'value' => 'content']; } if (isset($forms['Phire\\Media\\Form\\Media'])) { $forms['Phire\\Media\\Form\\Media'][0]['categories'] = ['type' => 'checkbox', 'label' => 'Categories', 'value' => $categoryValues]; $forms['Phire\\Media\\Form\\Media'][0]['category_type'] = ['type' => 'hidden', 'value' => 'media']; } if (isset($forms['Phire\\Media\\Form\\Batch'])) { $forms['Phire\\Media\\Form\\Batch'][0]['categories'] = ['type' => 'checkbox', 'label' => 'Categories', 'value' => $categoryValues]; $forms['Phire\\Media\\Form\\Batch'][0]['category_type'] = ['type' => 'hidden', 'value' => 'media']; } $application->mergeConfig(['forms' => $forms], true); } }
/** * Edit action method * * @param int $id * @return void */ public function edit($id) { $category = new Model\Category(); $category->getById($id); if (!isset($category->id)) { $this->redirect(BASE_PATH . APP_URI . '/categories'); } $categories = new Model\Category(); $categories->getAll(); $parents = []; foreach ($categories->getFlatMap() as $c) { if ($c->id != $id) { $parents[$c->id] = str_repeat(' ', $c->depth) . ($c->depth > 0 ? '→ ' : '') . $c->title; } } $this->prepareView('categories/edit.phtml'); $this->view->title = 'Categories'; $this->view->category_title = $category->title; $fields = $this->application->config()['forms']['Phire\\Categories\\Form\\Category']; $fields[0]['category_parent_id']['value'] = $fields[0]['category_parent_id']['value'] + $parents; $fields[1]['slug']['label'] .= ' [ <a href="#" class="small-link" onclick="phire.createSlug(jax(\'#title\').val(), \'#slug\');' . ' return phire.changeCategoryUri();">Generate URI</a> ]'; $fields[1]['title']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);'; $fields[1]['slug']['attributes']['onkeyup'] = "phire.changeCategoryUri();"; $this->view->form = new Form\Category($fields); $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($category->toArray()); if ($this->request->isPost()) { $this->view->form->setFieldValues($this->request->getPost()); if ($this->view->form->isValid()) { $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter(); $category = new Model\Category(); $category->update($this->view->form->getFields()); $this->view->id = $category->id; $this->sess->setRequestValue('saved', true); $this->redirect(BASE_PATH . APP_URI . '/categories/edit/' . $category->id); } } $this->send(); }