ElkArte Community

Project Support => Support => Topic started by: Lou on February 07, 2016, 04:36:02 pm

Title: Placement of ManageLanguages.controller.php for custom theme
Post by: Lou on February 07, 2016, 04:36:02 pm
I made a few edits to sources/admin/ManageLanguages.controller.php to satisfy a custom theme I am working on. I placed the edited file in the theme root directory and changes did not appear. Of course if left in the sources/admin directory the changes are visible.

How do I get around leaving the edited ManageLanguages.controller.php file in sources/admin? I would like to leave it in the theme directory if it is possible.

thanks
Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: Joshua Dickerson on February 07, 2016, 04:40:47 pm
Not really understanding what you're asking but what changes did you need to make? If it can be done using the event system you future proof your mod and make it more likely to install.
Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: Lou on February 07, 2016, 04:53:07 pm
Hello Joshua,

I added 'class' => 'centertext' to 5 or so lines so the title and text in the Languages>Edit Languages would center properly. Well, properly in my mind anyway.

Not sure about the event system you are talking about. 

Thanks
Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: Joshua Dickerson on February 07, 2016, 05:05:35 pm
Can you post the file or tell me which lines or what function(s)? There are a bunch of hooks that will make that possible without needing to actually edit the files. Then in your package, you'd add those hooks.

Are you editing any other files (besides theme files)?
Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: emanuele on February 07, 2016, 05:12:56 pm
I have the feeling createList (or actually the class equivalent), should not allow to specify class names. It should generate "standard" class names and assign them to the columns (rows should be easy to target with css), so the it is not necessary to do what Lou is trying to do, it will be enough to add some css code with proper selectors.

ETA: BTW, Lou, what you are trying to do may be possible with some trick, I'd have to check the code you changed. ;)
Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: Lou on February 07, 2016, 05:15:53 pm
Code: [Select]
    /**
     * This lists all the current languages and allows editing of them.
     */
    public function action_edit()
    {
        global $txt, $context, $scripturl, $language;

        require_once(SUBSDIR . '/Language.subs.php');

        // Setting a new default?
        if (!empty($_POST['set_default']) && !empty($_POST['def_language']))
        {
            checkSession();
            validateToken('admin-lang');

            $lang_exists = false;
            $available_langs = getLanguages();
            foreach ($available_langs as $lang)
            {
                if ($_POST['def_language'] == $lang['filename'])
                {
                    $lang_exists = true;
                    break;
                }
            }

            if ($_POST['def_language'] != $language && $lang_exists)
            {
                require_once(SUBSDIR . '/SettingsForm.class.php');
                Settings_Form::save_file(array('language' => '\'' . $_POST['def_language'] . '\''));
                $language = $_POST['def_language'];
            }
        }

        // Create another one time token here.
        createToken('admin-lang');

        $listOptions = array(
            'id' => 'language_list',
            'items_per_page' => 20,
            'base_href' => $scripturl . '?action=admin;area=languages',
            'title' => $txt['edit_languages'],
            'data_check' => array(
                'class' => create_function('$rowData', '
                    if ($rowData[\'default\'])
                        return \'highlight2\';
                    else
                        return \'\';
                ')
            ),
            'get_items' => array(
                'function' => 'list_getLanguages',
            ),
            'get_count' => array(
                'function' => 'list_getNumLanguages',
            ),
            'columns' => array(
                'default' => array(
                    'header' => array(
                        'value' => $txt['languages_default'],
                        'class' => 'centertext',
                    ),
                    'data' => array(
                        'function' => create_function('$rowData', '
                            return \'<input type="radio" name="def_language" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'default\'] ? \'checked="checked"\' : \'\') . \' class="input_radio" />\';
                        '),
                        'style' => 'width: 8%;',
                        'class' => 'centertext',
                    ),
                ),
                'name' => array(
                    'header' => array(
                        'value' => $txt['languages_lang_name'],
                        'class' => 'centertext',
                    ),
                    'data' => array(
                        'class' => 'centertext',
                        'function' => create_function('$rowData', '
                            global $scripturl;
                            return sprintf(\'<a href="%1$s?action=admin;area=languages;sa=editlang;lid=%2$s">%3$s</a>\', $scripturl, $rowData[\'id\'], $rowData[\'name\']);
                        '),
                    ),
                ),
                'count' => array(
                    'header' => array(
                        'value' => $txt['languages_users'],
                        'class' => 'centertext',
                    ),
                    'data' => array(
                        'db_htmlsafe' => 'count',
                        'class' => 'centertext',
                    ),
                ),
                'locale' => array(
                    'header' => array(
                        'value' => $txt['languages_locale'],
                        'class' => 'centertext',
                    ),
                    'data' => array(
                        'db_htmlsafe' => 'locale',
                        'class' => 'centertext',
                    ),
                ),
            ),
            'form' => array(
                'href' => $scripturl . '?action=admin;area=languages',
                'token' => 'admin-lang',
            ),
            'additional_rows' => array(
                array(
                    'position' => 'bottom_of_list',
                    'value' => '
                        <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
                        <input type="submit" name="set_default" value="' . $txt['save'] . '"' . (is_writable(BOARDDIR . '/Settings.php') ? '' : ' disabled="disabled"') . ' class="right_submit" />',
                ),
            ),
            // For highlighting the default.
            'javascript' => '
                initHighlightSelection(\'language_list\');
            ',
        );

        // Display a warning if we cannot edit the default setting.
        if (!is_writable(BOARDDIR . '/Settings.php'))
            $listOptions['additional_rows'][] = array(
                'position' => 'after_title',
                'value' => $txt['language_settings_writable'],
                'class' => 'smalltext alert',
            );

        require_once(SUBSDIR . '/GenericList.class.php');
        createList($listOptions);

        $context['sub_template'] = 'show_list';
        $context['default_list'] = 'language_list';
    }

This is the only function in ManageLanguages.controller.php that I edited. Only added the 'class' => 'centertext' . 

Also edited PackageServers.template.php and ProfileInfo.template.php but they are in the theme directory already. No idea about hooks to be honest. But I do appreciate the help and the lesson. 

thanks

Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: Lou on February 07, 2016, 05:18:10 pm
Quote from: emanuele – I have the feeling createList (or actually the class equivalent), should not allow to specify class names. It should generate "standard" class names and assign them to the columns (rows should be easy to target with css), so the it is not necessary to do what Lou is trying to do, it will be enough to add some css code with proper selectors.

ETA: BTW, Lou, what you are trying to do may be possible with some trick, I'd have to check the code you changed. ;)
Here is an image. Just center aligned the text.

Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: Joshua Dickerson on February 08, 2016, 07:24:06 pm
I think you could use #wrapper_language_list to do that with some simple CSS.

Alternatively, the hook is 'integrate_list_language_list'. I don't know if we have a tutorial on how to use hooks. Would be good.
Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: Lou on February 08, 2016, 07:45:28 pm
Hi Joshua,

Thank you for the reply. I will give your suggestion a go and see how it turns out.  :)

Title: Re: Placement of ManageLanguages.controller.php for custom theme
Post by: emanuele on February 09, 2016, 02:25:05 am
Yep, I forgot about that!
Code: [Select]
#language_list .standard_row td:nth-child(n+1) {
text-align: center;
}

or just:
Code: [Select]
#language_list .standard_row td {
text-align: center;
}