/** * Get the instance of the current fieldtype */ protected function getFieldtypeInstance($field_type = NULL, $changed = array()) { $field_type = $field_type ?: $this->getFieldType(); $values = array_merge($this->getValues(), $changed); $facade = new FieldFacade($this->getId(), $values); $facade->setContentType($this->getContentType()); return $facade->getNativeField(); }
/** * AJAX return body for adding a new category via the publish form; when a * new category is added, we have to refresh the category list */ private function categoryGroupPublishField($group_id, $entry_id = NULL) { // Initialize a new category group field so we can return its publish form $category_group_field = array('field_id' => 'categories', 'cat_group_id' => $group_id, 'field_label' => lang('categories'), 'field_required' => 'n', 'field_show_fmt' => 'n', 'field_instructions' => lang('categories_desc'), 'field_text_direction' => 'ltr', 'field_type' => 'checkboxes', 'string_override' => '', 'field_list_items' => '', 'field_maxl' => 100); $field_id = 'cat_group_id_' . $group_id; $field = new FieldFacade($field_id, $category_group_field); $field->setName($field_id); if (is_numeric($entry_id)) { $entry = ee('Model')->get('ChannelEntry', $entry)->first(); } else { $entry = ee('Model')->make('ChannelEntry'); $entry->Categories = NULL; } $entry->populateCategories($field); // Reset the categories they already have selected $selected_cats = ee('Model')->get('Category')->filter('cat_id', 'IN', ee()->input->post('categories'))->all(); $field->setData(implode('|', $selected_cats->pluck('cat_name'))); return $field->getForm(); }
/** * Turn a field into a facade for more consistent access. */ protected function addFacade($id, $info, $name_prefix = '') { $name = $name_prefix . $id; $format = NULL; if (array_key_exists('field_fmt', $info)) { $format = $info['field_fmt']; } if ($this->hasProperty('field_ft_' . $id)) { $format = $this->getProperty('field_ft_' . $id) ?: $format; $this->setProperty('field_ft_' . $id, $format); } $facade = new FieldFacade($id, $info); $facade->setName($name); $facade->setContentId($this->getId()); if (isset($format)) { $facade->setFormat($format); } $this->_field_facades[$name] = $facade; }