Block Settings Not Appearing in Admin Tree

Block Settings Not Appearing in Admin Tree

by Amy Stewart -
Number of replies: 4

I have tried everything I know to get my block's settings to appear in the Site Administration --> Plugins --> Blocks tree.  My code is below:


<?php

defined('MOODLE_INTERNAL') || die();

$settings->add(new admin_settingpage('vlrssettings',get_string('report', 'block_vlrs')));

$report = new moodle_url($CFG->wwwroot.'/blocks/vlrs/report.php');

$report = html_writer::link($report, get_string('report_url', 'block_vlrs'));

$settings->add(new admin_setting_heading('vlrsheading',get_string('report_heading', 'block_vlrs'), get_string('report_desc', 'block_vlrs', array($url=>$report))));


I would love it if someone could tell me what I'm missing here!  Ideally, I'd like to add a folder under Site Administration --> Plugins --> Blocks with my plugin's name, and links to different reports.  However, I can't even get a simple setting page to show up!  Any help is GREATLY appreciated!

Average of ratings: -
In reply to Amy Stewart

Re: Block Settings Not Appearing in Admin Tree

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Amy

I am not sure about the admin_setting_heading off the top of my head, I have not seen used it like that.
But assuming its right, perhaps something like this would work?

<?php
defined('MOODLE_INTERNAL') || die();
$settings = null;
$vlrs_category = new admin_category('block_vlrs_topcat', 'VRLS');
$ADMIN->add('blocksettings', $vlrs_category);
$vlrs_settings = new admin_settingpage('vlrssettings',get_string('report', 'block_vlrs')));
$ADMIN->add('block_vlrs_topcat', $vlrs_settings);
$report = new moodle_url($CFG->wwwroot.'/blocks/vlrs/report.php');
$report = html_writer::link($report, get_string('report_url', 'block_vlrs'));
$report_heading = new admin_setting_heading('vlrsheading',get_string('report_heading', 'block_vlrs'), 
    get_string('report_desc', 'block_vlrs', array($url=>$report))));
$ADMIN->add('block_vlrs_topcat', $report_heading);
In reply to Justin Hunt

Re: Block Settings Not Appearing in Admin Tree

by Amy Stewart -

Thanks, Justin, but that isn't working either.  It's like the setttings.php isn't getting read at all.  I've added a line above the defined('MOODLE_INTERNAL') || die(); entry with an error_log() message, and it isn't showing up in the error log.  I've also tried to use an echo statement to see if the file is being read, and I'm not seeing anything.  I'm really unsure what to do!


I took your Moodle Development class recently, and I even tried to model this settings.php file after the superiframe settings.php, and it didn't show up in the Blocks settings folder either.  I've checked and rechecked to make sure that I have no coding errors.  Any other thoughts?

In reply to Amy Stewart

Re: Block Settings Not Appearing in Admin Tree

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Did you remember to add this function to your main block class?

function has_config() {
  return true;
}

Without it, Moodle doesn't look at settings.php (a hangover from how global config used to work for blocks, back in the Moodle 1.9 days).

Also - you shouldn't need to create a new admin_settingspage - just add settings to the $settings object and Moodle should do the rest (see blocks/rss_client/settings.php for an example).

Average of ratings: Useful (3)
In reply to Davo Smith

Re: Block Settings Not Appearing in Admin Tree

by Amy Stewart -

That did it!  I built the main class so long ago, I forgot about adding that little tidbit.  Thanks so much for your help!!


Amy