Skip to content

Commit

Permalink
MDL-56994 course: Show News field only if course format supports news
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Nov 21, 2016
1 parent 87799e9 commit e47d61e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions course/edit_form.php
Expand Up @@ -217,11 +217,6 @@ function definition() {
$mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars);
}

$options = range(0, 10);
$mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
$mform->addHelpButton('newsitems', 'newsitemsnumber');
$mform->setDefault('newsitems', $courseconfig->newsitems);

$mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
$mform->addHelpButton('showgrades', 'showgrades');
$mform->setDefault('showgrades', $courseconfig->showgrades);
Expand Down Expand Up @@ -372,6 +367,21 @@ function definition_after_data() {
$mform->insertElementBefore($mform->removeElement($elements[$i]->getName(), false),
'addcourseformatoptionshere');
}

if ($courseformat->supports_news()) {
// Show the news items select field if the course format supports news.
$options = range(0, 10);
$newsitems = $mform->createElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
$mform->insertElementBefore($newsitems, 'showgrades');
$courseconfig = get_config('moodlecourse');
$mform->setDefault('newsitems', $courseconfig->newsitems);
$mform->addHelpButton('newsitems', 'newsitemsnumber');
} else {
// Otherwise, create a hidden newsitems element and set its value to 0.
$newsitems = $mform->addElement('hidden', 'newsitems', 0);
$mform->setType('newsitems', PARAM_INT);
$newsitems->setValue(0);
}
}
}

Expand Down

0 comments on commit e47d61e

Please sign in to comment.