public function module_block_setup()
 {
     global $CFG, $COURSE, $DB;
     $cm = $this->get_cm();
     $customlabel = $DB->get_record('customlabel', array('id' => $cm->instance));
     $instance = customlabel_load_class($customlabel, $customlabel->labelclass);
     $block = null;
     if ($customlabel and !customlabel_is_hidden_byrole($block, $cm->id)) {
         $this->append_content($instance->get_content());
     }
 }
/**
* this function makes a last post process of the cminfo information
* for module info caching in memory when course displays. Here we
* can tweek some information to force cminfo behave like some label kind
*/
function customlabel_cm_info_dynamic(&$cminfo)
{
    global $DB, $PAGE, $CFG;
    static $customlabelscriptsloaded = false;
    static $customlabelcssloaded = array();
    // load some js sripts once
    if (!$customlabelscriptsloaded) {
        $PAGE->requires->js('/mod/customlabel/js/custombox.js', true);
        $customlabelscriptsloaded = true;
    }
    // $bt = debug_backtrace();
    // print_r($bt);
    // print_object(debug_backtrace());
    // apply role restriction here
    $block = null;
    if (customlabel_is_hidden_byrole($block, $cminfo->id)) {
        // set no chance to see anything from it
        $cminfo->set_no_view_link();
        $cminfo->set_content('');
        $cminfo->visible = 0;
        $cminfo->visibleold = 0;
        return;
    }
    if ($customlabel = $DB->get_record('customlabel', array('id' => $cminfo->instance))) {
        //
        $cssurl = '/mod/customlabel/type/' . $customlabel->labelclass . '/customlabel.css';
        if (!$PAGE->requires->is_head_done()) {
            $PAGE->requires->css($cssurl);
        } else {
            // late loading
            // less clean but no other way in some cases
            echo "<link rel=\"stylesheet\" href=\"{$CFG->wwwroot}{$cssurl}\" />\n";
        }
        // disable url form of the course module representation
        $cminfo->set_no_view_link();
        $cminfo->set_content($customlabel->processedcontent);
        $cminfo->set_extra_classes('label');
        // important, or customlabel WILL NOT be deletable in topic/week course
    }
    // print_object($cminfo);
}