/** * Object creating view * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ public function _handler_create($handler_id, array $args, array &$data) { $this->_new_type = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($args[0]); if (!$this->_new_type) { throw new midcom_error_notfound('Failed to find type for the new object'); } midcom::get('dbclassloader')->load_mgdschema_class_handler($this->_new_type); if (!class_exists($this->_new_type)) { throw new midcom_error_notfound("Component handling MgdSchema type '{$args[0]}' was not found."); } $data['new_type_arg'] = $args[0]; midcom::get('auth')->require_user_do('midgard.admin.asgard:manage_objects', null, 'midgard_admin_asgard_plugin'); $data['defaults'] = array(); if ($handler_id == '____mfa-asgard-object_create_toplevel' || $handler_id == '____mfa-asgard-object_create_chooser') { midcom::get('auth')->require_user_do('midgard:create', null, $this->_new_type); $data['view_title'] = sprintf($this->_l10n_midcom->get('create %s'), midgard_admin_asgard_plugin::get_type_label($data['new_type_arg'])); } else { $this->_object = midcom::get('dbfactory')->get_object_by_guid($args[1]); $this->_object->require_do('midgard:create'); midgard_admin_asgard_plugin::bind_to_object($this->_object, $handler_id, $data); // FIXME: Make a general case for all objects that are linked by guid to any other class if ($this->_new_type == 'midcom_db_parameter') { // Parameters are linked a bit differently $parent_property = 'guid'; $data['defaults']['parentguid'] = $this->_object->{$parent_property}; } else { // Set "defaults" $link_info = $this->_find_linking_property($this->_new_type); if (!is_array($link_info)) { throw new midcom_error("Could not establish link between {$this->_new_type} and " . get_class($this->_object)); } $parent_property = $link_info[1]; $data['defaults'][$link_info[0]] = $this->_object->{$parent_property}; } } $this->_load_schemadb($this->_new_type); if (isset($this->_schemadb['object']->fields['guid'])) { $this->_schemadb['object']->fields['guid']['hidden'] = true; } // Allow setting defaults from query string, useful for things like "create event for today" and chooser if (isset($_GET['defaults']) && is_array($_GET['defaults'])) { foreach ($_GET['defaults'] as $key => $value) { if (!isset($this->_schemadb['object']->fields[$key])) { // No such field in schema continue; } $data['defaults'][$key] = trim($value); } } $this->_controller = midcom_helper_datamanager2_controller::create('create'); $this->_controller->schemadb =& $this->_schemadb; $this->_controller->schema = 'object'; $this->_controller->callback_object =& $this; $this->_controller->defaults = $data['defaults']; if (!$this->_controller->initialize()) { throw new midcom_error("Failed to initialize a DM2 create controller."); } switch ($this->_controller->process_form()) { case 'edit': if ($this->_new_object) { $this->_new_object = null; } break; case 'save': if (is_a($this->_new_object, 'midcom_db_style') || is_a($this->_new_object, 'midcom_db_element')) { mgd_cache_invalidate(); } // Reindex the object //$indexer = midcom::get('indexer'); //net_nemein_wiki_viewer::index($this->_request_data['controller']->datamanager, $indexer, $this->_topic); // *** FALL-THROUGH *** $this->_new_object->set_parameter('midcom.helper.datamanager2', 'schema_name', 'default'); if ($handler_id != '____mfa-asgard-object_create_chooser') { $redirect_url = str_replace('//', '/', "__mfa/asgard/object/edit/{$this->_new_object->guid}/"); return new midcom_response_relocate($redirect_url); } break; case 'cancel': $data['cancelled'] = true; if ($this->_object) { $objecturl = "object/{$this->_request_data['default_mode']}/{$this->_object->guid}/"; } else { $objecturl = $args[0]; } if ($handler_id != '____mfa-asgard-object_create_chooser') { return new midcom_response_relocate("__mfa/asgard/{$objecturl}/"); } } $this->_prepare_request_data(); }