How to keep blank lines around array in PhpStorm - ide

I use PhpStorm 2019.1.
I need to set up code style with new lines around arrays. Keep it always.
$smt = $value;
$ss = [
'pr' => '4_',
'r5d' => '4_n',
'm4q' => '6_n',
'p3e' => '3_n',
'ctu' => '4_pn',
'orv' => '4on',
'eem' => '4on'
];
$smth = [];
I was seeking of these settings in Settings > Editor > Code style > PHP > Blank lines. Apparently It has to be there. But I didn`t find it. There were only settings to insert new lines around functions and classes but not around arrays.
Where is the settings which would help me with it? Or is this feature deprecated in this editor version?

Related

Add a new global variable in smarty? available on all pages. (prestashop)

I am looking to add a global variable in smarty.
I added css styles with {$urls.css_url} in stylesheep.tpl
<link rel="stylesheet" type="text/css" href="{$urls.css_url}my.css">
It works very well, except that if I put the shop on debug mode, I have this error:
ContextErrorException in smarty_internal_templatebase.php(157) : eval()'d code line 393: Notice: Undefined index: css_url
What does that mean? that this variable will not be available in smarty?, so if I put the cache, it will not be loaded?
How to make variable {$ urls.css_url} available with smarty? everywhere on the site?
Which code should I put and where to put it so that the variable (url_css) remains available in debug mode?
Thanks for your help
Thank you for your help, you have a high level compared to me.
In fact the variable is already defined and is available everywhere.
In frontcontroler.php, I had this:
$assign_array = array(
'img_ps_url' => _PS_IMG_,
'img_cat_url' => _THEME_CAT_DIR_,
'img_lang_url' => _THEME_LANG_DIR_,
'img_prod_url' => _THEME_PROD_DIR_,
'img_manu_url' => _THEME_MANU_DIR_,
'img_sup_url' => _THEME_SUP_DIR_,
'img_ship_url' => _THEME_SHIP_DIR_,
'img_store_url' => _THEME_STORE_DIR_,
'img_col_url' => _THEME_COL_DIR_,
'img_url' => _THEME_IMG_DIR_,
'css_url' => _THEME_CSS_DIR_,
'js_url' => _THEME_JS_DIR_,
'pic_url' => _THEME_PROD_PIC_DIR_,
);
I then added the next line below to assign it in smarty.
$this->context->smarty->assign(array('urls' => $urls));
The variable is displayed, no problem but if I put the shop in debug mode:
/* Debug only */
if (!defined('_PS_MODE_DEV_')) {
define('_PS_MODE_DEV_', true);
}
I always have this:
ContextErrorException in smarty_internal_templatebase.php(157) : eval()'d code line 393: Notice: Undefined index: css_url
Does this indicate that there is no value? Why does its value disappear? (when I activate PS_MODE_DEV)
Thanks again.
{$urls.css_url} means to retrieve the the css_url value from the urls array.
Also the Notice you receive means the variable has no value, so it can't work at all, so maybe what you think is correct, but what you see comes from other variable / hook.
How to set a Smarty Variable
In case you want to set a smarty variable you will have first to assign it.
You can do it through a module, controller or a TPL.
From a module or a controller it will be available as soon as you declare it. To print or to debug it.
So, for example if you add it in the hookDisplayHeader or in actionFrontControllerSetMedia hooks the variable will available where you want to use it.
Also, to assign the value in a module or controller you will have to use a code like this:
$urls = array (
'css_url' => 'The URL to your CSS'
...
);
$this->context->smarty->assign(array('urls' => $urls));
Then you will be able to access it using {$urls.css_url}
How to know the already defined variables in Smarty
Enable the debug mode of your shop and then just add {debug} in any of your TPLs, this will show a Pop Up (remember to allow popups from your URL) with all the variables assigned to Smarty.
Maybe this is what you are looking for:
Version: Prestashop 1.7.2.4
We are going to do this overriding a class, in this case the following file: classes/controller/FrontController.php, this file assigns global variables for Prestashop.
Create a file: override/classes/controller/FrontController.php
Copy all the contents from: classes/controller/FrontController.php to our recently created file.
Check the following line: 1444, there is a function called getTemplateVarUrls(), inside this function there is already a variable css_url that points to theme css default dir : /public_html/themes/theme_name/assets/css
If you want to create a custom url variable write the code there, i.e:
public function getTemplateVarUrls()
{
$http = Tools::getCurrentUrlProtocolPrefix();
$base_url = $this->context->shop->getBaseURL(true, true);
//custom css url var points to a folder called "my_custom_css" in the root of the project
$customCssFolderUrl = $base_url.'/my_customs_css';
$urls = array(
'base_url' => $base_url,
'current_url' => $this->context->shop->getBaseURL(true, false).$_SERVER['REQUEST_URI'],
'shop_domain_url' => $this->context->shop->getBaseURL(true, false),
'custom_css_url' => $customCssFolderUrl ,
);
After we finish all this steps we proceed to delete public_html/app/cache/prod/class_index.php file, this to prevent Prestashop from ignoring our new file, to read more about this: http://doc.prestashop.com/display/PS16/Overriding+default+behaviors
Use your new variable: {$urls.custom_css_url} on any .tpl file
Hope this helps.

Yii 1 Pagination takes every params user inserted

I have my pagination url set to
www...com/category/detail.html?page=2
For which my code is,
$dataProvider = new CActiveDataProvider('Page', array('criteria' => array('condition' => 'status=1', 'condition' => 'category_id=' . $categoryObject -> id, 'order' => 'postDate DESC'), 'pagination' => array('pageSize' => 4,'pageVar'=>'page'), ));
$dataProvider->getData();
var_dump $dataProvider->totalItemCount;
I am getting the exact data counts and my pagination url seems working. I have my URL rule configured as
'index'=>'site/index',
'contact'=>'site/contact',
'privacy'=>'site/privacy',
'sitemap.xml'=>'site/sitemap',
'<category:\w+>' => 'category/detail',
'<category>/page/<page:\d+>' => 'category/detail',
'<category>'=>'category/detail',
'<category:\w+>/<postTitle:.+>' => 'category/post',
'<category:\w.+>/<postTitle:.+>'=>'category/post',
my auto generated pagination URl are working fine but,
If I manually insert url something like
www......com/category/detail.html?Page_page&page=2
www......com/category/detail.html?Page_pizza&page=2
or any stupid things I can put they navigates to the page.
Now, here I want to remove these extra parameters or I want my pagination url to be strict to
www...com/category/detail.html?page=2
and if I put any additional params I want an error page.
I have been working in this for 2 weeks and tried every possible ways I could.
You should set the "params" property of the pagination to an empty array:
'pagination' => array('pageSize' => 4,'pageVar'=>'page', 'params' => array()),
This will avoid exclude any GET parameters from pagination links(if you need any included, add their name there).
To throw an error, you need to check for the parameters in your action.
// remove valid prameters from get array.
$arr = array_diff_key($_GET, array_flip(array('page', 'postTitle', 'category')));
// if still there are parameters left, throw an error.
if(count($arr) > 0) {
throw new CHttpException('invalid parameter');
}

Escape attribute value / prevent html sanitization in Haml

Here is my Haml:
%a{:href => "/settings", "data-icon" => "⚙"}
Which outputs:
<a data-icon='&#9881;' href='/settings'>Settings</a>
I want to output:
<a data-icon='⚙' href='/settings'>Settings</a>
So I've tried escaping the ampersand:
%a{:href => "/settings", "data-icon" => "\⚙"}
But it seems escapes only work for the first character of a line.
I've also tried different methods of interpolation/escaping with no success:
"#{"⚙"}"
Using plain html (Settings) is a stopgap measure that I do not consider a solution. What if I want to set the data-icon programatically?
Another option is:
%a{:href => "#", "data-icon" => "⚙"} Settings
But what if I want to use PUA characters? It also makes it a lot harder to tell what the character is in the markup.
Demo
You need to set the escape_attrs option to false or :once.
$ haml --no-escape-attrs
%a{:href => "/settings", "data-icon" => "⚙"}
output:
<a data-icon='⚙' href='/settings'></a>
--no-escape-attrs sets the escape_attrs option to false from the command line. See the docs for info on how to set options in other cases.
(It doesn’t look like codepen.io lets you specify Haml options, so I can’t provide a demo there).

Accessing content of textarea in Drupal-7-Theme-Form

in my custom theme-settings.php (zen-subtheme) i put following code to get a new textarea with textformat in my theme-settings:
<?php
function paper_form_system_theme_settings_alter(&$form, &$form_state) {
$form['paper_data'] = array(
'#type' => 'text_format',
'#title' => 'Put Text in here:',
'#rows' => 5,
'#resizable' => FALSE,
'#default_value' => 'xyz..',
'#format' => 'full_html'
);
}
the form is working perfektly, but when i want to access the variable by writing
<?php
$pdata = theme_get_setting('paper_data');
echo $pdata;
?>
in my page.tpl.php, the content of the variable is not rendered - instead the word "Array" is printed ...
What's wrong and why? (If i use 'textarea' as type instead of 'text_format', all is rendered well.)
You will understand when you use something like the Devel module's dpm() function to check the variable rather than echo(). Coding Drupal without the Devel module is, IMHO, folly.
The issue very likely stems from your use of the text_format type. As you can see, it saves both the textarea value as well as an associated text format. When this is used Drupal returns the data in structured form which varies depending on the type of format.
dpm() is your friend :)

Remove line numbers from SyntaxHighlighter

Is there any way to remove the line numbers of SyntaxHighlighter?
Thanks!
You can set the SyntaxHighliter's gutter configuration to false. This will remove the line number from your code.
<pre class="brush: java; gutter: false;"></pre>
Hit the "view plain" link?
Taking a look at the SyntaxHighlighter demo you will see it has buttons in the top right corner which you can click to either copy the code to your clipboard, see the actual source code (removing markup) and or print it.
Are you asking us how to remove the actual feature that adds the line numbers while still keeping the rest of the functionality in place? Are you asking us to do this for you?
In response to comment:
If you want to keep the functionality in place, and just remove the line numbers you will need to download a copy of the javascript file for yourself and remove the features you don't want. the SyntaxHighlighter download page allows you to download your very own version of the highlighter, it also tells you that is is licensed under the LGPL 3, which means you have to follow those rules when you make and use your modifications.
If you want, you may come back and ask individual Javascript questions, if you get stuck in a particular spot, but we are not TopCoder nor will we re-write code for you.
If you don't want to edit your existing markup, you can turn it off globally by editing the shCore.js file:
var sh = {
defaults : {
...
...
...
/** Enables or disables gutter. */
'gutter' : false,
...
...
...
},
...
...
...
}
You can set the default of 'gutter' => 0 in SyntaxHighlighter Evolved version 3.2.1 by editing the file syntaxhighlighter.php. Look for this in the file:
// Create array of default settings (you can use the filter to modify these)
$this->defaultsettings = (array) apply_filters(
'syntaxhighlighter_defaultsettings', array(
'theme' => 'default',
'loadallbrushes' => 0,
'shversion' => 3,
'title' => '',
'autolinks' => 1,
'classname' => '',
'collapse' => 0,
'firstline' => 1,
'gutter' => 0,
'htmlscript' => 0,
'light' => 0,
'padlinenumbers' => 'false',
'smarttabs' => 1,
'tabsize' => 4,
'toolbar' => 0,
'wraplines' => 1, // 2.x only
) );