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

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
......@@ -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();
}
}
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeNavigation extends SystemBlocktype {
class PluginBlocktypeNavigation extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.navigation');
......@@ -185,4 +185,13 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
$bi->commit();
}
/**
* 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 PluginBlocktypeNewViews extends SystemBlocktype {
class PluginBlocktypeNewViews extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title1', 'blocktype.newviews');
......@@ -87,4 +87,14 @@ class PluginBlocktypeNewViews 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();
}
}
......@@ -12,7 +12,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeRecentForumPosts extends SystemBlocktype {
class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.recentforumposts');
......@@ -210,4 +210,14 @@ class PluginBlocktypeRecentForumPosts 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();
}
}
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeText extends SystemBlocktype {
class PluginBlocktypeText extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.text');
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
class PluginBlocktypeWall extends SystemBlocktype {
class PluginBlocktypeWall extends MaharaCoreBlocktype {
public static function should_ajaxify() {
return false;
......@@ -301,4 +301,13 @@ EOF;
$wallowner == $USER->get('id');
}
/**
* 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 PluginBlocktypeWatchlist extends SystemBlocktype {
class PluginBlocktypeWatchlist extends MaharaCoreBlocktype {
public static function single_only() {
return true;
......@@ -109,4 +109,14 @@ class PluginBlocktypeWatchlist extends SystemBlocktype {
public static function get_instance_title(BlockInstance $instance) {
return get_string('title', 'blocktype.watchlist');
}
/**
* 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();
}
}
......@@ -7,7 +7,11 @@
<a class="blocktype-drag blocktypelink btn btn-default hide-title-collapsed text-left" href="#" title="{$blocktype.description}">
<span class="icon icon-arrows icon-sm left move-indicator"></span>
<input type="radio" id="blocktype-list-radio-{$blocktype.name}" class="blocktype-radio" name="blocktype" value="{$blocktype.name}">
<span class="icon icon-{$blocktype.name} block-icon" title="{$blocktype.title}"></span>
{if $blocktype.cssicon}{*
*}<span class="icon icon-{$blocktype.cssicon} block-icon" title="{$blocktype.title}"></span>{*
*}{else}{*
*}<img class="icon block-icon" src="{$blocktype.thumbnail_path}" title="{$blocktype.description}" alt="{$blocktype.description}" width="14" height="14">{*
*}{/if}
<label for="blocktype-list-radio-{$blocktype.name}" class="blocktypetitle title">{$blocktype.title}</label>
<span class="sr-only">({$blocktype.description})</span>
</a>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment