drupal 8 set another theme for login page - drupal-modules

I'm new on drupal 8 and I've developped a custom theme, but I would like to use the bartik theme for the core module users, specially for log in (but i can accept to set it for all the module). How can I do that without touching the drupal core?
Note: Bartik is the administration theme of my site
Thanks in advance.

You want to use your admin theme for the login.logout page ?
Use the theme negociator : https://drupal.stackexchange.com/questions/201530/how-can-i-change-the-active-theme-programmatically.
Here's an old example : https://www.drupal.org/node/2158619
For the record this is the old Drupal 7 way :
/**
* Force Admin theme for user login paths
* #see hook_custom_theme()
*
* #return string
*/
function ocb_home_custom_theme() {
$admin_theme = variable_get('admin_theme', 0);
if (arg(0) == 'user' && $admin_theme !==0 ) {
return $admin_theme;
}
}

Related

Define Shortcut Keys by user (add or edit by user in web app)?

I have a web app create with angular 7.0 and Nodejs. I want to add a shortcut engine (user customizable) like Microsoft Word that user can add or edit or modify default shortcut keys for some function in this app. is there any code or tips for doing like this?
I know there is an answer here but I do my best to stay away from packages unless I'm ready to do a deep-dive on what type of code I would be adding to my project.
Here is the Angular/JavaScript way to trigger functions on keyboard events.
#HostListener('window:keyup', ['$event']) keyEvent(event: KeyboardEvent) {
if (event.key === 27 || event.key === 13) {
// console.log(event.key);
}
}
I typically use keycode.info or logging key presses to find my key numbers.
Pseudo code based on comment question regarding user-specific key bindings.
mock user object saved in database
user {
...
bindings{
featureOne: 27 // key chosen by user for featureOne
featureTwo: 13 // key chosen by user for featureTwo
}
}
Then you can refer to those choices in the listener
if (event.keyCode === user.bindings.featureOne) {
// trigger featureOne
}
I guess this package suits your needs !

Redefine tab as 4 spaces in Gitlab CE

See this huge identations is painful (for me). Is there a way to set tab size to 4 spaces.
This picture is taken from local Gitlab CE server with minimal customization. I think tabsize 8 spaces is default.
Go to Settings -> Preferences -> Behavior and set Tab width
Yeah, gitlab uses browser CSS property tab-size which default value is 8.
There's a bug discussion about this here:
https://gitlab.com/gitlab-org/gitlab-ce/issues/2479
You can change gitlab CSS and you'll have what you want.
As of February 2021, this has not been addressed. One can check the current GitLab issue for progress, but in the meantime, this comment on the thread offers a solution via creating a UserScript via Greasemonkey / Tampermonkey with this script:
// ==UserScript==
// #name GitLab Tab Size
// #version 1
// #include https://gitlab.com/*
// #grant none
// ==/UserScript==
const TAB_SIZE = 2
window.addEventListener('load', function() {
const styleElement = document.createElement('style')
styleElement.innerHTML = `
.diff-content, pre.code {
-moz-tab-size: ${TAB_SIZE};
tab-size: ${TAB_SIZE};
}
`
document.head.appendChild(styleElement)
})
Credit to Brendan Gadd from that thread.

Way to access ModX database by including ModX core file?

I have a PHP file (that I cant make a snippet out of). I need to connect it to the database and rather then doing it the normal way was wondering if I could just include a header file of some sort that already has a DB connection.
Does anyone know of such a file in the Modx file structure?
Easy...
if you open the main index.php, you can see some hint:
/* define this as true in another entry file, then include this file to simply access the API
* without executing the MODX request handler */
if (!defined('MODX_API_MODE')) {
define('MODX_API_MODE', false);
}
// ...
/* execute the request handler */
if (!MODX_API_MODE) {
$modx->handleRequest();
}
That said, if you have a raw PHP file, let's say as an example: hello.php
<?php
define('MODX_API_MODE', true); // IMPORTANT!!!
require 'index.php'; // or give directory path, according to your need
// let's test it
$startPage = $modx->getObject('modResource', $modx->getOption('site_start', null, 1));
if (!$startPage) {
die('CRAP!');
}
$startPageArray = $startPage->toArray();
echo '<pre>';
print_r($startPageArray);
echo '</pre>';
die('WOOHOO');
And no, you don't have to define $modx again.
It's using the same object in index.php.
you can run any operations against your modx database if you load the modx module in your external script [in fact you can use any modx functions]
https://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/loading-modx-externally
once you instantiate the modx object it will handle all your database connection details. This will work in any page, not just manager pages.
The only place which allows database connections using system database config are manager pages, yet that would require more work to write a plugin to access its classes and functions.
If you want to be able to use MODX functionality to establish connection, I suggest using it's xPDO to perform queries, for security reasons at least.
Such setup would be:
define('MODX_CORE_PATH', '/path/to/revo/core/');
define('MODX_CONFIG_KEY','config');
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$dbname = 'your_database';
$port = 3306;
$charset = 'utf-8';
$dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset";
$xpdo = new xPDO($dsn, $username, $password);

Typo3 Extbase: get domain in CommandController

I'm trying to access the base url of my site inside a command action like this:
namespace Vendor\TxTest\Command;
class TestCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController
{
/**
* logger
*
* #var \TYPO3\CMS\Core\Log\LogManager
*/
protected $logger;
/**
* Class constructor
*/
public function __construct()
{
$this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Core\\Log\\LogManager' )->getLogger( __CLASS__ );
}
/**
* Test command
*/
public function testCommand()
{
$homeUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl( '/' );
$this->logger->info( 'url: ' . $homeUrl );
$this->logger->info( "\n\r\n\r" );
}
}
When I run the command from the Scheduler backend module, the domain looks ok, but when it runs automatically, the result is:
Mon, 10 Mar 2014 ... component="Vendor.TxNews.Command.TestCommandController": url: http:///
What is the correct way to get the domain in this context?
PHP knows the domain from the server-call. If your site is on a specific server, you might have several urls pointing to this server. Your PHP does not know by itself which domain he has. Only from the request that the user is doing PHP is getting this information in the $_SERVER-var that Typo3/Extbase can read. I assume your script is running on different servers if you want to get the url? Can you put a configuration on the server that is different for each server?
One approach to do this would be to store the url from a user-call and read this in your Background-Module.
to put it clear: If you run the scheduler automatically and therefore trigger PHP in CLI mode, there is no request URL / it is empty, as like the name already suggests u run in command line interface mode.
Typoscript has the baseURL settable and switchable, but even there the domain of the call is undefined, which is perfectly right.

How can I change Magento theme via query string?

Is it possible to change Magento template via query string?
I am developing a custom template and sometimes I want to check if I broke something, so I want to change via query string the theme for the default one.
I am looing for something like this:
?_theme=default
Does something like this exists?
Programmatically:
You could write an observer that is listening to event <controller_action_predispatch>
The observer method could look like this:
public function changeTheme(){
if (Mage::app()->getRequest()->getParam('layout_switch') == '1'){
Mage::getDesign()->setArea(‘frontend’)
->setPackageName(Mage::app()->getRequest()->getParam('package'))
->setTheme(Mage::app()->getRequest()->getParam('theme'));
}
return;
}
}
Then you would just need to call your page with e.g.
yourdomain.com/index.php/layout_switch/1/package/default/theme/default
The short answer is no you can't (as far as I know)
However if it's your local installation (which you use only as a development enviroment!) you can use a trick:
Create another Store view and assign whatever theme you want to that store view and then access it like yourstore.com/?___store=storecode
as simple as 1-2-3.:) Create a new dev theme and copy all the files from the current live theme to the new one (both app/design and sking). Then observe controller_action_predispatch event and then in the observer function simply:
$controllerAction = $observer->getControllerAction();
if ($controllerAction->getLayout()->getArea() == Mage_Core_Model_App_Area::AREA_FRONTEND) {
$ipAddress = Mage::helper('core/http')->getRemoteAddr();
$ipAddresses = array('xxx.xxx.xxx.xxx');
if (in_array($ipAddress, $ipAddresses)) {
Mage::getDesign()->setTheme('theme-wanted');
}
}
Very helpful for design tweaks indeed. After the work is finished the observer should be disabled or module deactivated until next time

Resources