Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Base class for common support when editing a multiblock subblock.
19
 *
20
 * @package   block_multiblock
21
 * @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace block_multiblock\form;
26
 
27
use block_multiblock_proxy_edit_form;
28
 
29
/**
30
 * Base class for common support when editing a multiblock subblock.
31
 *
32
 * Note that this extends block_multiblock_proxy_edit_form - this does
33
 * not actually exist. This is an alias to whichever edit_form that the
34
 * subblock would instantiate, so that we can overlay our settings on
35
 * top and not deal with the full set of block settings which won't be
36
 * relevant.
37
 *
38
 * @package   block_multiblock
39
 * @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
40
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
42
class editblock_base extends block_multiblock_proxy_edit_form {
43
    /** @var block_base $block The block class instance that belongs to the block type being edited */
44
    public $block;
45
 
46
    /** @var object The page object for the page which contains the block being edited */
47
    public $page;
48
 
49
    /** @var object The multiblock object being edited */
50
    public $multiblock;
51
 
52
    /**
53
     * Creates the instance-specific editing form.
54
     *
55
     * @param string|moodle_url $actionurl The form action to submit to
56
     * @param block_base $block The block class being edited
57
     * @param object $page The contextually appropriate $PAGE type object of the block being edited
58
     * @param object $multiblock The multiblock object being edited (mostly for its configuration
59
     */
60
    public function __construct($actionurl, $block, $page, $multiblock = null) {
61
        $this->block = $block->blockinstance;
62
        $this->block->instance->visible = true;
63
        $this->block->instance->region = $this->block->instance->defaultregion;
64
        $this->block->instance->weight = $this->block->instance->defaultweight;
65
        $this->page = $page;
66
        $this->multiblock = $multiblock;
67
 
68
        if (!empty($this->block->configdata)) {
69
            $this->block->config = @unserialize(base64_decode($this->block->configdata));
70
        }
71
 
72
        parent::__construct($actionurl, $this->block, $this->page);
73
    }
74
 
75
    /**
76
     * Provides the save buttons for the edit-block form.
77
     */
78
    public function add_save_buttons() {
79
        // Now we add the save buttons.
80
        $mform =& $this->_form;
81
 
82
        $buttonarray = [];
83
        $buttonarray[] = &$mform->createElement('submit', 'saveandreturn',
84
            get_string('saveandreturntomanage', 'block_multiblock'));
85
 
86
        // If the page type indicates we're not on a wildcard page, we can probably* go back there.
87
        // Note: * for some definition of probably.
88
        if (strpos($this->multiblock->instance->pagetypepattern, '*') === false) {
89
            $buttonarray[] = &$mform->createElement('submit', 'saveanddisplay', get_string('savechangesanddisplay'));
90
        }
91
 
92
        $buttonarray[] = &$mform->createElement('cancel');
93
        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
94
        $mform->closeHeaderBefore('buttonar');
95
    }
96
}