Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce predefined path in templates xml file for custom fields #4295

Closed
wants to merge 2 commits into from
Closed

Introduce predefined path in templates xml file for custom fields #4295

wants to merge 2 commits into from

Conversation

dgrammatiko
Copy link
Contributor

Introduces the same functionality as PR #4294

How to test:
edit template xml [isis.xml] file adding
<field name="compile" type="compile" label="TPL_ISIS_COMPILE_LABEL" /> under a fieldset
create a folder fields and a file in that fodder named compile.php
and paste this code:

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  Templates.isis
 *
 * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

jimport('joomla.filesystem.file');

class JFormFieldCompile extends JFormField
{
    protected function getInput()
    {

        $app         = JFactory::getApplication();
        $template    = $app->getTemplate(true);
        $params      = $template->params;
        $jinput      = $app->input;
        $compile     = 0;
        $compile     = $jinput->get('compileless');
        $currentpath = dirname(realpath(__DIR__));
        $pageurl     = str_replace('&amp;compileless=1', '', JURI::getInstance());

        if ($compile)
        {
            // Load the RAD layer to use its LESS compiler
            if (!defined('FOF_INCLUDED'))
            {
                require_once JPATH_LIBRARIES . '/fof/include.php';
            }

            $less = new FOFLess;
            $less->setFormatter(new FOFLessFormatterJoomla);

            //update variables.less
            $less->setVariables(array(
                "templateColor"    => $params->get('templateColor'),
                "headerBackground" => $params->get('headerColor'),
                "sidebarColor"     => $params->get('sidebarColor')
            ));

            try
            {
                $less->compileFile($currentpath . '/less/template.less', $currentpath . '/css/template.css');
            } catch (Exception $e)
            {
                $app->enqueueMessage($e->getMessage(), 'error');
            }
        }

        return '<button onclick="window.location.href=\'' . $pageurl . '\'+\'&amp;compileless=1\'" class="btn btn-primary" type="button">Compile Less</button>';
    }

}

Visiting the admin -> templates -> isis [style] you should see the compile button. Press it an you will recompile the template.css

@Bakual
Copy link
Contributor

Bakual commented Sep 18, 2014

Same comment here as in the other PR.

I'm not sure what the purpose is. It's already possible to use custom fields by providing the addfieldpath to the XML.
If I understand that correct, you just want to automate this so you don't have to define the path yourself?

@dgrammatiko
Copy link
Contributor Author

@Bakual Sorry for providing little info. What this and also the previous PR try to solve is remove the hardcoded code from xml's, so let's say is a sortcut and an easier way to introduce custom fields.

@dgrammatiko dgrammatiko changed the title Allow custom fields in templates installation file [xml] Introduce predefined path in templates xml file for custom fields Sep 18, 2014
@dgrammatiko
Copy link
Contributor Author

Closing this so we don’t have multiple PR’s for one proposal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants