Back to ModuleHelper class

Method cleanModuleList

public static array
cleanModuleList
(mixed $modules)
Clean the module list
Parameters
  • array $modules Array with module objects
Returns
  • array
Class: ModuleHelper
Project: Joomla

Method cleanModuleList - Source code

/**
 * Clean the module list
 *
 * @param   array  $modules  Array with module objects
 *
 * @return  array
 */
public static function cleanModuleList($modules)
{
    // Apply negative selections and eliminate duplicates
    $Itemid = Factory::getApplication()->input->getInt('Itemid');
    $negId = $Itemid ? -(int) $Itemid : false;
    $clean = array();
    $dupes = array();
    foreach ($modules as $i => $module) {
        // The module is excluded if there is an explicit prohibition
        $negHit = $negId === (int) $module->menuid;
        if (isset($dupes[$module->id])) {
            // If this item has been excluded, keep the duplicate flag set,
            // but remove any item from the modules array.
            if ($negHit) {
                unset($clean[$module->id]);
            }
            continue;
        }
        $dupes[$module->id] = true;
        // Only accept modules without explicit exclusions.
        if ($negHit) {
            continue;
        }
        $module->name = substr($module->module, 4);
        $module->style = null;
        $module->position = strtolower($module->position);
        $clean[$module->id] = $module;
    }
    unset($dupes);
    // Return to simple indexing that matches the query order.
    return array_values($clean);
}