Commit 4f849ed2 authored by Aaron Wells's avatar Aaron Wells

Display icons for 3rd-party blocktypes plugins

Bug 1510421

Defines a new static PluginBlocktype method, get_css_icon(), which
fetches the name of the CSS icon to use for this blocktype. It returns
false by default, which tells the theme to "fall back" to the old
thumbnail.png instead. 3rd-party plugins can override this to
specify a particular icon to use.

All the core blocktypes have been refactored to extend
MaharaCoreBlocktype, which uses the blocktype name as the name
of the CSS icon to use. I also deprecated the "SystemBlocktype"
class while I was at it.

PluginBlocktype::get_blocktypes_for_category() now returns both
the results of get_css_icon() and the thumbnail.png path, so that
themes can decide which they want to use. (And of course
thumbnail.png is served via thumbnail.php, so 3rd party themes
can provide their own custom image files if they wish.)

behatnotneeded: Requires installing third-party plugins to test

Change-Id: Idb1ecfc7b21175913708e695788906c11133b0c0
parent ac365767
......@@ -11,7 +11,7 @@
defined ('INTERNAL') || die();
class PluginBlocktypeAnnotation extends SystemBlocktype {
class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
public static function single_only() {
return false;
}
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeBlog extends PluginBlocktype {
class PluginBlocktypeBlog extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.blog/blog');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeBlogpost extends PluginBlocktype {
class PluginBlocktypeBlogpost extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.blog/blogpost');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeRecentposts extends PluginBlocktype {
class PluginBlocktypeRecentposts extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.blog/recentposts');
......@@ -153,7 +153,7 @@ class PluginBlocktypeRecentposts extends PluginBlocktype {
'rules' => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 100),
),
);
return $elements;
}
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeTaggedposts extends SystemBlocktype {
class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
const TAGTYPE_INCLUDE = 1;
const TAGTYPE_EXCLUDE = 0;
......
......@@ -11,7 +11,7 @@
defined ('INTERNAL') || die();
class PluginBlocktypeComment extends SystemBlocktype {
class PluginBlocktypeComment extends MaharaCoreBlocktype {
public static function should_ajaxify() {
// TinyMCE doesn't play well with loading by ajax
return false;
......@@ -93,4 +93,14 @@ class PluginBlocktypeComment extends SystemBlocktype {
public static function has_instance_config() {
return false;
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeFiledownload extends PluginBlocktype {
class PluginBlocktypeFiledownload extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.file/filedownload');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeFolder extends PluginBlocktype {
class PluginBlocktypeFolder extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.file/folder');
......
......@@ -13,7 +13,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeGallery extends PluginBlocktype {
class PluginBlocktypeGallery extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.file/gallery');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeHtml extends PluginBlocktype {
class PluginBlocktypeHtml extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.file/html');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeImage extends PluginBlocktype {
class PluginBlocktypeImage extends MaharaCoreBlocktype {
public static function should_ajaxify() {
// Most of the load time for an image block is waiting for
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeInternalmedia extends PluginBlocktype {
class PluginBlocktypeInternalmedia extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.file/internalmedia');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypePdf extends PluginBlocktype {
class PluginBlocktypePdf extends MaharaCoreBlocktype {
public static function single_only() {
return false;
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeProfileinfo extends PluginBlocktype {
class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.internal/profileinfo');
......
......@@ -12,7 +12,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeSocialprofile extends PluginBlocktype {
class PluginBlocktypeSocialprofile extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.internal/socialprofile');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeTextbox extends PluginBlocktype {
class PluginBlocktypeTextbox extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.internal/textbox');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypePlans extends PluginBlocktype {
class PluginBlocktypePlans extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.plans/plans');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeEntireresume extends PluginBlocktype {
class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.resume/entireresume');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeResumefield extends PluginBlocktype {
class PluginBlocktypeResumefield extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.resume/resumefield');
......
......@@ -12,7 +12,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeCreativecommons extends SystemBlocktype {
class PluginBlocktypeCreativecommons extends MaharaCoreBlocktype {
// Standard Creative Commons naming scheme
const noncommercial = 'nc';
......@@ -185,4 +185,13 @@ class PluginBlocktypeCreativecommons extends SystemBlocktype {
return 'full';
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -13,7 +13,7 @@ defined('INTERNAL') || die();
require_once('XML/Feed/Parser.php');
class PluginBlocktypeExternalfeed extends SystemBlocktype {
class PluginBlocktypeExternalfeed extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.externalfeed');
......@@ -594,4 +594,13 @@ class PluginBlocktypeExternalfeed extends SystemBlocktype {
return $bi;
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -20,7 +20,7 @@ defined('INTERNAL') || die();
* - i18n
* - minvalue/maxvalue rules
*/
class PluginBlocktypeExternalvideo extends SystemBlocktype {
class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
private static $media_sources = array(
'youtube',
......@@ -343,4 +343,13 @@ class PluginBlocktypeExternalvideo extends SystemBlocktype {
}
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -12,7 +12,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeGoogleApps extends SystemBlocktype {
class PluginBlocktypeGoogleApps extends MaharaCoreBlocktype {
private static $default_height = 500;
......@@ -370,4 +370,13 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
return 'full';
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -13,7 +13,7 @@
defined('INTERNAL') || die();
require_once('group.php');
class PluginBlocktypeGroupInfo extends SystemBlocktype {
class PluginBlocktypeGroupInfo extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.groupinfo');
......@@ -78,4 +78,14 @@ class PluginBlocktypeGroupInfo extends SystemBlocktype {
return group_get_groupinfo_data($group);
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -12,7 +12,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeGroupMembers extends SystemBlocktype {
class PluginBlocktypeGroupMembers extends MaharaCoreBlocktype {
private static $default_numtoshow = 12;
......@@ -123,4 +123,14 @@ class PluginBlocktypeGroupMembers extends SystemBlocktype {
public static function get_instance_title () {
return get_string('Members', 'group');
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -13,7 +13,7 @@
defined('INTERNAL') || die();
require_once('group.php');
class PluginBlocktypeGroupViews extends SystemBlocktype {
class PluginBlocktypeGroupViews extends MaharaCoreBlocktype {
const SORTBY_TITLE = 0;
const SORTBY_LASTUPDATE = 1;
......@@ -397,4 +397,14 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
public static function get_instance_title() {
return get_string('title', 'blocktype.groupviews');
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeInbox extends SystemBlocktype {
class PluginBlocktypeInbox extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.inbox');
......@@ -198,4 +198,14 @@ class PluginBlocktypeInbox extends SystemBlocktype {
public static function should_ajaxify() {
return true;
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -50,24 +50,6 @@ interface IPluginBlocktype {
public static function get_categories();
public static function render_instance(BlockInstance $instance, $editing=false);
/**
* If this blocktype contains artefacts, and uses the artefactchooser
* Pieform element to choose them, this method must return the definition
* for the element.
*
* This is used in view/artefactchooser.json.php to build pagination for
* the element.
*
* The element returned MUST have the name key set to either 'artefactid'
* or 'artefactids', depending on whether 'selectone' is true or false.
*
* The element must also have the 'blocktype' key set to the name of the
* blocktype that the form is for.
*
* @param mixed $default The default value for the element
*/
public static function artefactchooser_element($default=null);
}
/**
......@@ -84,6 +66,12 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
*/
public static $DEFAULT_SORTORDER = 100000;
/**
* Used in the get_blocktype_list_icon() method
*/
const BLOCKTYPE_LIST_ICON_PNG = 0;
const BLOCKTYPE_LIST_ICON_FONTAWESOME = 1;
public static function get_plugintype_name() {
return 'blocktype';
}
......@@ -108,6 +96,30 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
}
}
/**
* If the theme wants to display CSS icons for Mahara blocks, then it will
* call this method to find out the name of the CSS icon to use. If this
* method returns false, it will fall back to using the thumbnail.png
*
* In the core themes, these icons come from FontAwesome.
* See htdocs/theme/raw/sass/lib/font-awesome/_icons.scss
* for the full list of icons loaded by Mahara. (Note that this may change
* from one Mahara version to another, as we upgrade FontAwesome.)
* (Also note that the .scss files are stripped from the Mahara packaged
* ZIP file. IF you don't have them, look in our git repository:
* https://git.mahara.org/mahara/mahara/blob/master/htdocs/theme/raw/sass/lib/font-awesome/_icons.scss
*
* For the core blocktypes, we have "aliased" the name of the block
* to the appropriate icon. See theme/raw/sass/lib/typography/_icons.scss.
*
* @param string $blocktypename The name of the blocktype
* (since blocktype classes don't always know their own name as a string)
* @return mixed Name of icon, or boolean false to fall back to thumbnail.png
*/
public static function get_css_icon($blocktypename) {
return false;
}
public static function extra_xmldb_substitution($xml) {
return str_replace(
'<!-- PLUGINTYPE_INSTALLED_EXTRAFIELDS -->',
......@@ -236,10 +248,30 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
}
/**
* this is different to has_config - has_config is plugin wide config settings
* this is specific to this TYPE of plugin and relates to whether individual instances
* can be configured within a view
*/
* If this blocktype contains artefacts, and uses the artefactchooser
* Pieform element to choose them, this method must return the definition
* for the element.
*
* This is used in view/artefactchooser.json.php to build pagination for
* the element.
*
* The element returned MUST have the name key set to either 'artefactid'
* or 'artefactids', depending on whether 'selectone' is true or false.
*
* The element must also have the 'blocktype' key set to the name of the
* blocktype that the form is for.
*
* @param mixed $default The default value for the element
*/
public static function artefactchooser_element($default=null) {
}
/**
*
* this is different to has_config - has_config is plugin wide config settings
* this is specific to this TYPE of plugin and relates to whether individual instances
* can be configured within a view
*/
public static function has_instance_config() {
return false;
}
......@@ -294,14 +326,16 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
// blocktypes, we can add $view->get('template') here as part of
// the condition, and also to View::addblocktype and
// View::get_category_data
if (call_static_method(generate_class_name('blocktype', $namespaced), 'allowed_in_view', $view)) {
$classname = generate_class_name('blocktype', $namespaced);
if (call_static_method($classname, 'allowed_in_view', $view)) {
$blocktypes[] = array(
'name' => $bt->name,
'title' => call_static_method(generate_class_name('blocktype', $namespaced), 'get_title'),
'description' => call_static_method(generate_class_name('blocktype', $namespaced), 'get_description'),
'singleonly' => call_static_method(generate_class_name('blocktype', $namespaced), 'single_only'),
'title' => call_static_method($classname, 'get_title'),
'description' => call_static_method($classname, 'get_description'),
'singleonly' => call_static_method($classname, 'single_only'),
'artefactplugin' => $bt->artefactplugin,
'thumbnail_path' => get_config('wwwroot') . 'thumb.php?type=blocktype&bt=' . $bt->name . ((!empty($bt->artefactplugin)) ? '&ap=' . $bt->artefactplugin : ''),
'cssicon' => call_static_method($classname, 'get_css_icon', $bt->name),
);
}
}
......@@ -537,15 +571,45 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
}
abstract class SystemBlockType extends PluginBlockType {
/**
* Mahara core blocks should extend this class. (Currently it only controls styling,
* useful as a way of mapping the behavior of core blocks to theme items that are
* not easily queried by the code.)
*/
abstract class MaharaCoreBlocktype extends PluginBlockType {
/**
* Use a css icon based on the name of the block
* (These are defined in typography.scss)
*
* @param string $blocktypename
* @return string
*/
public static function get_css_icon($blocktypename) {
return $blocktypename;
}
}
/**
* Old half-used "SystemBlockType" class. Deprecated, but still included because
* some 3rd-party blocktypes use it.
*
* It was never clearly described what the purpose of this blocktype is; but most
* likely its purpose was to indicate blocks that don't "contain" artefacts, such
* as the "new views" block.
*
* But as long as your block isn't storing an item called "artefactid" or "artefactids"
* in its blocktype.config field, then the default implementation of get_artefacts()
* doesn't really matter.
*/
abstract class SystemBlockType extends PluginBlockType {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public final static function artefactchooser_element($default=null) {
}
}
......
......@@ -13,7 +13,7 @@ defined('INTERNAL') || die();
define('MAXFRIENDDISPLAY', 16);
class PluginBlocktypeMyfriends extends SystemBlocktype {
class PluginBlocktypeMyfriends extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.myfriends');
......@@ -163,4 +163,13 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
return get_string('otherusertitle', 'blocktype.myfriends', display_name($ownerid, null, true));
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeMyGroups extends SystemBlocktype {
class PluginBlocktypeMyGroups extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.mygroups');
......@@ -167,4 +167,13 @@ class PluginBlocktypeMyGroups extends SystemBlocktype {
return get_string('otherusertitle', 'blocktype.mygroups', display_name($ownerid, null, true));
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeMyviews extends SystemBlocktype {
class PluginBlocktypeMyviews extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title1', 'blocktype.myviews');
......@@ -134,4 +134,13 @@ class PluginBlocktypeMyviews extends SystemBlocktype {
return get_string('otherusertitle1', 'blocktype.myviews', display_name($ownerid, null, true));
}
/**
* Shouldn't be linked to any artefacts via the view_artefacts table.
*
* @param BlockInstance $instance
* @return multitype:
*/
public static function get_artefacts(BlockInstance $instance) {
return array();
}
}