主题

主题中获取文件

if ($ADMIN->fulltree) {

  $name = 'theme_boost/preset'; //
  $title = get_string('preset', 'theme_boost');//【该设置的标题】主题预设

  //[对该设置描述]选择一个预设来明显的改变主题的外观
  $description = get_string('preset_desc', 'theme_boost');

  $default = 'default.scss';

  /*上下文环境*/
  $context = context_system::instance();

  /*返回本地文件存储实例*/
  $fs = get_file_storage();
  /*获取改上下文区域的文件*/
  $files = $fs->get_area_files($context->id, 'theme_boost', 'preset', 0, 'itemid, filepath, filename', false);


  $choices = [];
  foreach ($files as $file) {

    $choices[$file->get_filename()] = $file->get_filename();
  }
  // These are the built in presets.
  //这些是预置的
  $choices['default.scss'] = 'default.scss';
  $choices['plain.scss'] = 'plain.scss';
  //实例化一个下拉框
  $setting = new admin_setting_configselect($name, $title, $description, $default, $choices);
  //调用清除主题缓存的函数
  $setting->set_updatedcallback('theme_reset_all_caches');//函数调用,如果设置更新-清除,缓存重置等
  $page->add($setting);//将admin_setting添加到这个admin_settingpage

}

原文地址:https://www.cnblogs.com/lichihua/p/7300057.html