XMF Cookbook
  • Introduction
  • XMF Cookbook
  • Basic Ingredients
    • Namespaces
    • Autoloading
    • Debugging
    • Forward Compatibility
  • Recipes
    • Introducing Module Helpers
    • Using the Permission Helper
      • Checking Permissions
      • Managing Item Permissions
    • Using the Session Helper
    • Using JSON Web Tokens
    • Altering Database Tables
    • Migrating a Module's Database
    • Loading Initial Data
    • Module Admin Pages
      • Hide and Seek with Icons
      • Standard Admin Pages
    • Manage Metadata
    • Highlighting Content
  • Reference
    • Assert
      • Assertions
    • Database
      • Migrate
      • TableLoad
      • Tables
        • Getting Started
        • Table Operations
        • Working with Columns
        • Working with Indexes
        • Changing Table Data
        • Interacting with the Work Queue
        • Error Info and Debugging
    • Debug
    • FilterInput
    • Highlighter
    • IPAddress
    • Jwt
      • JsonWebToken
      • KeyFactory
      • TokenFactory
      • TokenReader
    • Key
      • ArrayStorage
      • Basic
      • FileStorage
      • KeyAbstract
      • StorageInterface
    • Language
    • Metagen
      • Extracting Data
      • Applying Data
    • Module
      • Admin
      • Helper
      • Helper
        • AbstractHelper
        • Cache
        • GenericHelper
        • Permission
        • Session
    • ProxyCheck
    • Random
    • Request
    • StopWords
    • Uuid
    • Yaml
  • Credits
  • License:
  • Table of Content
Powered by GitBook
On this page
  • Where are the icons?
  • menu.php
  1. Recipes
  2. Module Admin Pages

Hide and Seek with Icons

PreviousModule Admin PagesNextStandard Admin Pages

Last updated 6 years ago

As XOOPS matures, the icons won't be in the same place. There are static methods in to help you win the game of hide and seek once and for all.

Where are the icons?

You might have had some code that looks like this:

$dirname         = basename(dirname(dirname(__FILE__)));
$module_handler  = xoops_gethandler('module');
$module          = $module_handler->getByDirname($dirname);
$pathIcon16      = $module->getInfo('icons16');
$img_src         = $pathIcon16 . '/delete.png';

Here is an XMF version that accomplishes the same thing, in a migration ready way:

$img_src = \Xmf\Module\Admin::iconUrl('delete.png', 16);

You can also specify 32 for the size to get the larger size. And you don't have to worry about where the system icon library is hiding this time, as you will get back a full URL.

menu.php

Administration area menus are one place where icon location changes cause problems.

Here is an example of an old menu.php:

$dirname = basename(dirname(dirname(__FILE__)));
$module_handler = xoops_gethandler('module');
$module = $module_handler->getByDirname($dirname);
$pathIcon32 = $module->getInfo('icons32');

$adminmenu=array();
// Index
$adminmenu[] = array(
    'title'    => _MI_DEMO_ADMIN_INDEX ,
    'link'    => 'admin/index.php' ,
    'icon'    => '../../' . $pathIcon32 . '/home.png'
) ;
// About
$adminmenu[] = array(
    'title'    => _MI_DEMO_ADMIN_ABOUT ,
    'link'    => 'admin/about.php' ,
    'icon'    => '../../' . $pathIcon32 . '/about.png'
) ;

Here is a sample of how we can rewrite menu.php to work now and later with XMF.

// get path to icons
$pathIcon32='';
if (class_exists('Xmf\Module\Admin', true)) {
    $pathIcon32 = \Xmf\Module\Admin::menuIconPath('');
}

$adminmenu=array();
// Index
$adminmenu[] = array(
    'title'    => _MI_DEMO_ADMIN_INDEX ,
    'link'    => 'admin/index.php' ,
    'icon'    => $pathIcon32.'home.png'
) ;
// About
$adminmenu[] = array(
    'title'    => _MI_DEMO_ADMIN_ABOUT ,
    'link'    => 'admin/about.php' ,
    'icon'    => $pathIcon32.'about.png'
) ;
Xmf\Module\Admin