CoreFiles by mySites.guru
SiteTemplateTrait.php64 lines, 1,641 bytes, from Joomla_4.2.0-Stable-Full_Package.zip
Raw History Compare with 4.1.5
md5
c2ad0b6e3e3c17ca41662a90300496dd
sha1
bf6ee43d935c863ccdd6cbf184884184c4c92c67
sha256
3d4dbdc98dfa59951685e8f6f8a5be3fadaf39f9e5895a476f2df4036878df93
<?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_users
 *
 * @copyright   (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Users\Administrator\View;

use Exception;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use ReflectionException;
use ReflectionObject;

/**
 * Dynamically modify the frontend template when showing a MFA captive page.
 *
 * @since 4.2.0
 */
trait SiteTemplateTrait
{
    /**
     * Set a specific site template style in the frontend application
     *
     * @return  void
     * @throws  Exception
     * @since   4.2.0
     */
    private function setSiteTemplateStyle(): void
    {
        $app           = Factory::getApplication();
        $templateStyle = (int) ComponentHelper::getParams('com_users')->get('captive_template', '');

        if (empty($templateStyle) || !$app->isClient('site')) {
            return;
        }

        $itemId = $app->input->get('Itemid');

        if (!empty($itemId)) {
            return;
        }

        $app->input->set('templateStyle', $templateStyle);

        try {
            $refApp      = new ReflectionObject($app);
            $refTemplate = $refApp->getProperty('template');
            $refTemplate->setAccessible(true);
            $refTemplate->setValue($app, null);
        } catch (ReflectionException $e) {
            return;
        }

        $template = $app->getTemplate(true);

        $app->set('theme', $template->template);
        $app->set('themeParams', $template->params);
    }
}

The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.