Customizing theme issues

Customizing theme issues

by Brandon Jimenez -
Number of replies: 12

Hello, I'm customizing a theme based on bootstrap 3 and the Elegance theme. The previous version of said theme was running with a few issues and once I started debugging I opened a can of worms. I installed it, by cloning it, and is being recognized by the LMS. However, when I make changes to the configuration in the LMS, it shows me the following messages:


Notice: Trying to get property of non-object in /xxxxx/htdocs/admin/settings.php on line 102
Warning: array_reverse() expects parameter 1 to be array, null given in /xxxx/htdocs/admin/settings.php on line 102
Warning: implode(): Invalid arguments passed in /xxxxx/htdocs/admin/settings.php on line 104


Changes saved

Notice: Trying to get property of non-object in /xxxx/htdocs/admin/settings.php on line 122
Fatal error: Call to a member function output_html() on a non-object in /xxxx/htdocs/admin/settings.php on line 124

The changes, as can be imagined, are being made, but the page doesn't reload and it goes from:

http://xxx/admin/settings.php?section=theme_xxxx_generic

to

http://xxx/admin/settings.php

As usual, I'm open to suggestions. Thanks


My moodle is 2.9.1.

Average of ratings: -
In reply to Brandon Jimenez

Re: Customizing theme issues

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Well I guess it would help to know what the settings.php looks like. Assuming you have altered it?

Thanks

Mary

In reply to Mary Evans

Re: Customizing theme issues

by Brandon Jimenez -

admin/settings.php


<?php
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
$section = required_param('section', PARAM_SAFEDIR);
$return = optional_param('return','', PARAM_ALPHA);
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
/// no guest autologin
require_login(0, false);
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/admin/settings.php', array('section' => $section));
$PAGE->set_pagetype('admin-setting-' . $section);
$PAGE->set_pagelayout('admin');
$PAGE->navigation->clear_cache();
navigation_node::require_admin_tree();
$adminroot = admin_get_root(); // need all settings
$settingspage = $adminroot->locate($section, true);
if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) {
    print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
    die;
}
if (!($settingspage->check_access())) {
    print_error('accessdenied', 'admin');
    die;
}
/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
$statusmsg = '';
$errormsg  = '';
if ($data = data_submitted() and confirm_sesskey()) {
    if (admin_write_settings($data)) {
        $statusmsg = get_string('changessaved');
    }
    if (empty($adminroot->errors)) {
        switch ($return) {
            case 'site': redirect("$CFG->wwwroot/");
            case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
        }
    } else {
        $errormsg = get_string('errorwithsettings', 'admin');
        $firsterror = reset($adminroot->errors);
    }
    $settingspage = $adminroot->locate($section, true);
}
if ($PAGE->user_allowed_editing() && $adminediting != -1) {
    $USER->editing = $adminediting;
}
/// print header stuff ------------------------------------------------------------
if (empty($SITE->fullname)) {
    $PAGE->set_title($settingspage->visiblename);
    $PAGE->set_heading($settingspage->visiblename);
    echo $OUTPUT->header();
    echo $OUTPUT->box(get_string('configintrosite', 'admin'));
    if ($errormsg !== '') {
        echo $OUTPUT->notification($errormsg);
    } else if ($statusmsg !== '') {
        echo $OUTPUT->notification($statusmsg, 'notifysuccess');
    }
    // ---------------------------------------------------------------------------------------------------------------
    echo '<form action="settings.php" method="post" id="adminsettings">';
    echo '<div class="settingsform clearfix">';
    echo html_writer::input_hidden_params($PAGE->url);
    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
    echo '<input type="hidden" name="return" value="'.$return.'" />';
    echo $settingspage->output_html();
    echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
    echo '</div>';
    echo '</form>';
} else {
    if ($PAGE->user_allowed_editing()) {
        $url = clone($PAGE->url);
        if ($PAGE->user_is_editing()) {
            $caption = get_string('blockseditoff');
            $url->param('adminedit', 'off');
        } else {
            $caption = get_string('blocksediton');
            $url->param('adminedit', 'on');
        }
        $buttons = $OUTPUT->single_button($url, $caption, 'get');
        $PAGE->set_button($buttons);
    }
    $visiblepathtosection = array_reverse($settingspage->visiblepath);
    $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
    $PAGE->set_heading($SITE->fullname);
    echo $OUTPUT->header();
    if ($errormsg !== '') {
        echo $OUTPUT->notification($errormsg);
    } else if ($statusmsg !== '') {
        echo $OUTPUT->notification($statusmsg, 'notifysuccess');
    }
    // ---------------------------------------------------------------------------------------------------------------
    echo '<form action="settings.php" method="post" id="adminsettings">';
    echo '<div class="settingsform clearfix">';
    echo html_writer::input_hidden_params($PAGE->url);
    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
    echo '<input type="hidden" name="return" value="'.$return.'" />';
    echo $OUTPUT->heading($settingspage->visiblename);
    echo $settingspage->output_html();
    if ($settingspage->show_save()) {
        echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
    }
    echo '</div>';
    echo '</form>';
}
$PAGE->requires->yui_module('moodle-core-formchangechecker',
        'M.core_formchangechecker.init',
        array(array(
            'formid' => 'adminsettings'
        ))
);
$PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
echo $OUTPUT->footer();


I haven't changed anything here (as far as i can remember). I updated the Moodle, and then i cloned the previous theme i was using, so i could start editing but saving the old one (just in case). However, once the new one is activated, this happens, and I tried my best to follow the instructions on cloning a theme available on MoodleDocs, so I'm not really sure what (or where) I made a mistake.

---------------

EDIT:

Doing a little debugging i figured out that the problem is associated with this object $settingspage, since every error report deals with it, i tried echoing a part of it to see what is there and it shows me nothing. Once i click on the "Save changes" button, it disappears, and therefore the information is not passed through (although, as i first mentioned, the changes are being made)


Thanks

In reply to Brandon Jimenez

Re: Customizing theme issues

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Sorry, I was meaning the theme's settings.php!

In reply to Mary Evans

Re: Customizing theme issues

by Brandon Jimenez -

No problemo....here it is


$settings = null;
defined('MOODLE_INTERNAL') || die;
global $PAGE;
$ADMIN->add('themes', new admin_category('theme_xxx', 'xxx'));
require_once('settings/generic.php');
require_once('settings/color_logo.php');
require_once('settings/user_menu.php');
require_once('settings/banner.php');
require_once('settings/marketing.php');
require_once('settings/quick_links.php');
require_once('settings/login.php');
require_once('settings/social_network.php');
require_once('settings/category_icons.php');
require_once('settings/disclaimer.php');

 


I haven't changed anything (as far as I can remember) but i'm open to suggestions. Thanks smile

In reply to Brandon Jimenez

Re: Customizing theme issues

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

I am not sure I have seen a settings.php page like this before.

I presume you have or is this just a whim on your part?

So that we can help, perhaps it may help if you could add a section of the settings/generic.php file so that I for one can begin to comprehend how you are managing your theme settings?

Thanks

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Customizing theme issues

by John Chavez -

Hi i'm customizing the settings.php for elegance, i actually made a new theme out of it. Configuring the theme settings in Moodle works fine. But when i modify the settings.php code i didn't get the result i've been expecting its seems that my code is not reflecting. Can you shed some light on me please. 


Here is a sample code i just modify simple as changing the default for the container

FROM:

$default = '0';

TO

$default = '1';


Thanks in adavance!

In reply to John Chavez

Re: Customizing theme issues

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

That value is only used when the setting is installed.  When changing it in code you need to remove the setting from the DB (config_plugins table I think (from memory)) then do a 'Purge all caches', then Site administration -> notifications to reinstall it, hopefully with the new value.

In reply to Brandon Jimenez

Re: Customizing theme issues

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

NOTE: The theme you have based your custom theme on (Elegance) is only identified as suitable for upto Moodle 2.7 in the plugins database. It has not been updated for some time and that is quite likely to be the cause of this problem.

I have been using Elegance with no such problems on 2.7 for some time, but have not tested it on 2.9

Have you tried Elegance itself with your settings changes to see if the issue exists with the theme you are customising before any of your own changes?


Average of ratings: Useful (1)
In reply to Richard Oelmann

Re: Customizing theme issues

by Brandon Jimenez -

Hi, thanks for your suggestions. As I mentioned, I cloned the theme the previous developer had been using to start modifying it to fit the new GUI needs. So it was something like

Theme 2 (cloned from 1)
Theme 1 (cloned from Elegance)

He even started changing the Elegance theme directly, instead if cloning it, but anyway, I tested the three and Theme 1 and 2 are presenting that issue, so it's probably not a Moodle 2.9 - Theme incompatibility, as Elegance itself seems to be running ok. However, I'm gonna do a couple more test to see if based on this I can figure it out while I keep being attentive. Thanks! smile

In reply to Brandon Jimenez

Re: Customizing theme issues

by Brandon Jimenez -

Yeap, using both of your suggestions I figured out that the previous programmer did split the code in several files, just to make it easier to debug (very ironically). So I went back and replaced the file with the original settings.php file from the Elegance theme, and it worked!!!

Thanks Mary and Richard!!

smile

In reply to Brandon Jimenez

Re: Customizing theme issues

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

I'd suggest there is a bug within one of the required files then as there's nothing wrong with splitting the settings file in that way and I have previously done it (for example in my flexibase theme) and that technique works fine - but obviously not if there is a bug in the code somewhere anyway smile

Average of ratings: Useful (1)
In reply to Brandon Jimenez

Re: Customizing theme issues

by Jez H -

I just had the same problem in another theme using "require_once".

For the time being I changed to include and it was ok (include is more tollerant of errors).