From 83f337f5c45c7945f1858dc0d5268209744826bb Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 12 Jul 2018 16:12:24 +0800 Subject: [PATCH] #154 Don't display 'Add page' link for unsaved templates --- classes/edit_form.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/classes/edit_form.php b/classes/edit_form.php index c586778..50f642c 100644 --- a/classes/edit_form.php +++ b/classes/edit_form.php @@ -80,18 +80,20 @@ class edit_form extends \moodleform { $this->add_customcert_page_elements($page); } - // Link to add another page. - $addpagelink = new \moodle_url('/mod/customcert/edit.php', - array( - 'tid' => $this->tid, - 'aid' => 1, - 'action' => 'addpage', - 'sesskey' => sesskey() - ) - ); - $icon = $OUTPUT->pix_icon('t/switch_plus', get_string('addcertpage', 'customcert')); - $addpagehtml = \html_writer::link($addpagelink, $icon . get_string('addcertpage', 'customcert')); - $mform->addElement('html', \html_writer::tag('div', $addpagehtml, array('class' => 'addpage'))); + // Link to add another page, only display it when the template has been created. + if (isset($this->_customdata['tid'])) { + $addpagelink = new \moodle_url('/mod/customcert/edit.php', + array( + 'tid' => $this->tid, + 'aid' => 1, + 'action' => 'addpage', + 'sesskey' => sesskey() + ) + ); + $icon = $OUTPUT->pix_icon('t/switch_plus', get_string('addcertpage', 'customcert')); + $addpagehtml = \html_writer::link($addpagelink, $icon . get_string('addcertpage', 'customcert')); + $mform->addElement('html', \html_writer::tag('div', $addpagehtml, array('class' => 'addpage'))); + } // Add the submit buttons. $group = array();