Beispiel #1
0
 if ($action == 'edit') {
     $instance = portfolio_instance($portfolio);
     $plugin = $instance->get('plugin');
     // Since visible is being passed to form
     // and used to set the value when a new
     // instance is created - we must also
     // place the currently visibility into the
     // form as well
     $visible = $instance->get('visible');
 } else {
     $instance = null;
     $plugin = $portfolio;
 }
 $PAGE->set_pagetype('admin-portfolio-' . $plugin);
 // Display the edit form for this instance
 $mform = new portfolio_admin_form('', array('plugin' => $plugin, 'instance' => $instance, 'portfolio' => $portfolio, 'action' => $formaction, 'visible' => $visible));
 // End setup, begin output
 if ($mform->is_cancelled()) {
     redirect($baseurl);
     exit;
 } else {
     if (($fromform = $mform->get_data()) && confirm_sesskey()) {
         // Unset whatever doesn't belong in fromform
         foreach (array('pf', 'action', 'plugin', 'sesskey', 'submitbutton') as $key) {
             unset($fromform->{$key});
         }
         // This branch is where you process validated data.
         if ($action == 'edit') {
             $instance->set_config((array) $fromform);
             $instance->save();
         } else {
Beispiel #2
0
$baseurl = "{$CFG->wwwroot}/{$CFG->admin}/settings.php?section=manageportfolios";
$sesskeyurl = "{$CFG->wwwroot}/{$CFG->admin}/portfolio.php?sesskey=" . sesskey();
$configstr = get_string('manageportfolios', 'portfolio');
$return = true;
// direct back to the main page
if (!empty($edit) || !empty($new)) {
    if (!empty($edit)) {
        $instance = portfolio_instance($edit);
        $plugin = $instance->get('plugin');
    } else {
        $plugin = $new;
        $instance = null;
    }
    $PAGE->set_pagetype('admin-portfolio-' . $plugin);
    // display the edit form for this instance
    $mform = new portfolio_admin_form('', array('plugin' => $plugin, 'instance' => $instance));
    // end setup, begin output
    if ($mform->is_cancelled()) {
        redirect($baseurl);
        exit;
    } else {
        if ($fromform = $mform->get_data()) {
            // unset whatever doesn't belong in fromform
            foreach (array('edit', 'new', 'plugin', 'sesskey', 'submitbutton') as $key) {
                unset($fromform->{$key});
            }
            //this branch is where you process validated data.
            if ($edit) {
                $instance->set_config($fromform);
                $instance->save();
            } else {
Beispiel #3
0
 /**
  * Test submitting a form for editing an instance
  */
 public function test_edit_form()
 {
     $this->resetAfterTest();
     $instance = $this->enable_plugin();
     $formdata = ['name' => 'New name', 'clientid' => 'CLIENT', 'secret' => 'SECRET'];
     portfolio_admin_form::mock_submit($formdata);
     $form = new portfolio_admin_form('', array('plugin' => $this->pluginname, 'instance' => $instance, 'portfolio' => $instance->get('id'), 'action' => 'edit', 'visible' => $instance->get('visible')));
     $this->assertTrue($form->is_validated());
     $this->assertTrue($form->is_submitted());
     $data = $form->get_data();
     $this->assertEquals('edit', $data->action);
     $this->assertEquals($instance->get('visible'), $data->visible);
     $this->assertEquals($this->pluginname, $data->plugin);
     foreach ($formdata as $key => $value) {
         $this->assertEquals($value, $data->{$key});
     }
 }