public function executeEditCf() { $session = Session::getInstance(); $cf = \TermCustomFields::retrieveById($this->request()->get('id')); $term_id = $this->request()->get('term_id'); if (!$cf) { $session->setFlash('cf_error', t('Custom field not found')); $this->redirect($this->createUrl('category/custom_field', array('id' => $term_id))); } $error = array(); if ($this->request()->isPostRequest()) { $cf->hydrate($this->request()->post('custom_fields', 'ARRAY', array())); $acceptValues = explode("\n", $this->request()->post('accept_values')); $cf->setAcceptValue(json_encode($acceptValues)); if ($cf->save()) { } } $formData = (object) $cf->toArray(); $formData['accept_values'] = implode("\n", json_decode($formData['accept_values'])); $this->setView('cf_form'); $this->view()->assign(array('data' => $formData, 'custom_fields' => $cf)); }
public function executeLoadCustomFieldFrm() { $category_id = $this->request()->post('category_id'); $category = \Terms::retrieveById($category_id); if (!$category) { //error return $this->renderText(''); } $post_id = $this->request()->post('post_id'); //load category custom fields $categoryCfs = \TermCustomFields::findByTermId($category_id); if (empty($categoryCfs)) { return $this->renderText(''); } /** @var \PostCustomFields[] $postCfs */ $postCfs = array(); //load item custom field value if exist if ($post_id) { $_postCfs = \PostCustomFields::findByPostId($post_id); for ($i = 0, $size = sizeof($_postCfs); $i < $size; ++$i) { $postCfs[$_postCfs[$i]->getCfId()] = $_postCfs; } unset($_postCfs); } //end load item custom field value $data = array(); foreach ($categoryCfs as $catCf) { $d = (object) $catCf->toArray(); $d->value = ''; if (isset($postCfs[$catCf->getId()])) { //exist items $i = $postCfs[$catCf->getId()]; switch ($catCf->getFormat()) { case 'NUMBER': $d->value = (double) $i->getNumberValue(); break; case 'BOOL': $d->value = (bool) $i->getBoolValue(); break; case 'DATETIME': $d->value = $i->getDatetimeValue(); break; default: $d->value = $i->getTextValue(); } } $data[] = $d; } $data = Plugin::applyFilters('custom_' . $category->getTaxonomy() . '_cf_form_data', $data); $buf = $this->renderPartial(array('data' => $data)); $buf = Plugin::applyFilters('custom_' . $category->getTaxonomy() . '_cf_form', $buf); return $buf; }