Back to ModuleHelper class

Method getModuleById

public static \stdClass
getModuleById
(mixed $id)
Get module by id
Parameters
  • string $id The id of the module
Returns
  • \stdClass The Module object
Since
  • 3.9.0
Class: ModuleHelper
Project: Joomla

Method getModuleById - Source code

/**
 * Get module by id
 *
 * @param   string  $id  The id of the module
 *
 * @return  \stdClass  The Module object
 *
 * @since   3.9.0
 */
public static function &getModuleById($id)
{
    $modules =& static::load();
    $total = \count($modules);
    for ($i = 0; $i < $total; $i++) {
        // Match the id of the module
        if ((string) $modules[$i]->id === $id) {
            // Found it
            return $modules[$i];
        }
    }
    // If we didn't find it, create a dummy object
    $result = static::createDummyModule();
    return $result;
}