PhpStorm 2020.2: How to get caret to line break after creating a method with braces? - ide

Before I start, | represents the IDE caret.
Now my problem is that when I type the following in PhpStorm:
public function __construct() {|
it will autocomplete to this (which is fine):
public function __construct() {|}
But when I hit return, I'd expect the caret to move like this:
public function __construct() {
|
}
But instead it moves like this:
public function __construct() {}
|
I have hunted in as many code style options and settings as I can but for love nor money can I get this to work!
Any ideas? Thanks in advance

#LazyOne has helped me resolve this issue by prompting me to check Keymap.
I realised when I was typing (too fast and clumsy) my finger was still pressing Shift+Enter which triggered the Start New Line keymap.
I had to remove this mapping and additionally map Shift+Enter to the Editors' Enter keymap.

Related

How can I change the module position from code in Prestashop 1.7?

I learn actually Module Programming in Prestashop 1.7.... hard work but really good.
So, when I install my first module,
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if ( !parent::install() or
!$this->registerHook('displayTop') or
!$this->registerHook('header') or
!$this->registerHook('backOfficeHeader') )
return false;
return true;
}
the position will automatically set at the end of the hook displayTop.
Now, what must I do to set it on the first place ?
I have read it will works with the function "updatePosition", unfortunately I find only tips of 2012 and 2-3 years earlyier.
The developer docs have a hint here,
https://devdocs.prestashop.com/1.7/development/components/position-updater/
but I don't understand how to implant it into your module.
Does anyone have the time to explain me how the desired order is laid out by the code?
And does this happen in the install method or from where?
Go to your admin panel, in "**Design**" then "**Position**".
Look for '**displayTop**' in the "**Search for hook**" search bar at your top-right.
Then drag and drop your module which is in the last row and place it in the first row.
Change module's position in the hook list

How to setup IntelliJ IDEA to automatically add "final" where is possible

I have one method like this.
public void test(String name) {
}
So when I click ctrl+alt+l I expect it add final format like below.
public void test(final String name) {
}
How to set coding style like that.
Thank you.
You can enable the checkbox Preferences/Settings | Editor | Inspections | Java | Code Style issues | Local variable or parameter can be final and perform the reformat code action.
If the Code cleanup checkbox is enabled then IDEA will automatically add final where possible.

logd shortcut doesn't work in Intellij with Kotlin

Logging Java in Intellij is easy with shortcuts such as 'logt', 'logd', 'loge'... and so on. But I moved to Kotlin, I noticed that those shortcuts doesn't work anymore. I don't know if it has something to do with my configuration, but if not, how can I fix this?
You should create separate templates to make them work correctly.
Here is the step-by-step guide:
Firstly, Copy and paste AndroidLog templates to Kotlin (Just select them and use CMD+C, CMD+V (or Ctrl+C, Ctrl+V)
Secondly, You have to adjust them manually:
1. logd (and others)
Select the logd item and press "Edit variables"
Change expression to: kotlinFunctionName()
Also, remove ; from the end of the template, as you don't need it in Kotlin.
Now your method name will be shown correctly
logt
This one is a bit trickier.
Solution 1 TAG = class name.
Template text :
private val TAG = "$className$"
Edit variables -> Expression:
groovyScript("_1.take(Math.min(23, _1.length()));", kotlinClassName())
Solution 2 TAG = file name (can be used inside Companion)
Template text :
private const val TAG = "$className$
or:
companion object {
private const val TAG = "$className$"
}
Edit variables -> Expression:
groovyScript("_1.take(Math.min(23, _1.length()));", fileNameWithoutExtension())
Edit 19.02.19
Also, it might be useful for someone.
In order to avoid creating the TAG variable, you can use the class name as a variable, for instance:
Log.d("BaseActivity", "onCreate: ")
Where BaseActivity is the class name.
The template will look now as:
android.util.Log.d("$CLASS_NAME$", "$METHOD_NAME$: $content$")
Where CLASS_NAME variable is:
groovyScript("_1.take(Math.min(23, _1.length()));", fileNameWithoutExtension())
These are provided in IntelliJ as a Live Template configuration for AndroidLog (found in Preferences -> Editor -> Live Templates), and are applicable specifically to Java code:
There isn't anything broken in your configuration, but if you want to make these Live Templates available for Kotlin you will need to add new Live Template for AndroidLog and make them applicable to Kotlin code.
https://www.jetbrains.com/help/idea/2017.1/creating-and-editing-live-templates.html
There's an open feature request to have them added as defaults here: https://youtrack.jetbrains.com/issue/KT-10464
Change the scope of the template in the applicable option.
In Android Studio 4.0 there's new AndroidLogKotlin block. You can implement #LeoDroidcoder's solution there.

Prestashop 1.6 - How to add a dynamic class to the body element

In a Prestashop 1.6 site I need add a dynamic class to the body element (just in frontend).
The class should be 'group-[group-name-id]' where group-name-id is the group name id of the visitor.
Default Groups in Presashop are:
'1'--'Visitor'
'2'--'Guest'
'3'--'Costumer'
Is there a way to do this?
I found this, but it seems outdated, since it is for PS 1.4: https://www.prestashop.com/forums/topic/179593-adding-category-class-id-to-product-page-body/
UPDATE:
I almost get it thanks to #TheDrot answer (just below).
The only problem is this: [0]. I get this error: "Parse error: syntax error, unexpected '[', expecting ')' in /home/temporal-4/www/override/classes/controller/FrontController.php on line 36".
If I remove '[0]' it works but then in the class I get "group-array". I need to print all the values of the array like class="group-1 group-2 group-3".
You need to override FrontControllerCore class so create a file FrontController.php in folder 'override/classes/controller/' and put in this code
class FrontController extends FrontControllerCore {
public function init()
{
parent::init();
$this->context->smarty->assign('group_id', $this->context->customer->getGroups()[0]; // user can exist in multiple groups, so for this example im just grabbing first group id
}
}
Then open header.tpl file in 'themes/your_theme/' and add code to body class
group-{$group_id}
If in body class you only see group-, be sure to delete class_index.php from cache folder and reload page.
For PS1.7 no need to override anything, perhaps it works for PS1.6
Add $groupid = "group-1" or "group-2", ect. to smarty params by using assign() function in your controller and in your template add on top
{$page["body_classes"][$groupid] = 'true'}
Let us know about this tricks

How do I get the Intellij code autoformatter to keep an annotated field on one line?

Whenever I run the IntelliJ autoformatter - it converts this:
#Autowired private CustomerDao customerDao;
into this:
#Autowired
private CustomerDao customerDao;
How can I stop it from doing that?
Navigate to Preferences → Editor → Code Style → Java → Wrapping and Braces tab, then locate the section Field annotations and check the option Do not wrap after single annotation.
In IntelliJ v14: