Put node add form in module - module

I want to include a node add form within a module page, but I'm not sure exactly how to make Drupal happy - if i do something like
global $user;
module_load_include('inc', 'node', 'node.pages');
$form = drupal_get_form("project_node_form", $node_form);
$rtn .= drupal_render($form);
I get the error Call to undefined function user_access()
Should I wrap it in a function? how to call it?

Did you try to embed it into the hook: template_preprocess_page ?

Related

Cypress, how to check property exists

I'm new to cypress and am trying a couple of different methods to get a checkbox property...
checkBox().should('have.prop', 'checked')
checkBox().its('checked').should('exist')
The first line works fine but I was expecting the second to also pass but I get a "expected Undefined to exist" response.
Thanks
Assuming checkBox() function returns cy.get('.checkbox'), I think
checkBox().its('checked').should('exist')
fails because checkBox() does not return an object containing just the attributes. It returns the whole element (I think as an array). so you can't use its('checked') directly on checkbox().
Anyways, to do what you are expecting to do, you can use several methods,
using invoke('attr', 'checked')
checkBox().invoke('attr', 'checked')
.should('exist')
using getAttribute js function and expect chai assertion
checkBox().then($el => {
expect($el[0].getAttribute('checked')).to.exist;
})
using attributes in js and (its, wrap) in cypress.
Note: As mentioned earlier, you can't directly use its on the cy.get(). You need to extract the attributes from the object and use cy.wrap()
checkBox().then($el => {
cy.wrap($el[0].attributes)
.its('checked')
.should('exist')
})
you can use any of those methods, but the one I recommend is your first method.
cheers. Hope it helps.

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.

How can I hide a dijit/form/button?

I think it is a common sense that providing a simple way to hide/show and enable/disable a button, but I cannot find any document that describe dojo has done such thing.
Any way, I hope it is my fault that I have missed out something while googling, thanks!
The following coding is what I have tried but they just make the button's text invisible:
dojo.style(btnInsert, {'visibility':'hidden'});
dojo.style(btnInsert, {'display':'none'});
UPDATE Question:
To oborden2:
I have tried your code, the result is same as the above code, here is the captured screen:
To MiBrock:
I have also tried your code and also get the result that same as the above code:
Form widgets in Dijit are special. For all normal Dijit widgets, the domNode (outermost node) of the widget receives the id property. However, with form widgets, the focusNode (which corresponds to the <input> element) receives the ID instead, so that things like <label for="foo"> work properly. In this case, the outermost node has no ID, and you’re actually just hiding the inner HTML input element.
If you already have reference to the widget:
require([ 'dojo/dom-style' ], function (domStyle) {
domStyle.set(widget.domNode, 'display', 'none');
});
If you only have a reference to the ID of the widget/original DOM node:
require([ 'dojo/dom-style', 'dijit/registry' ], function (domStyle, registry) {
domStyle.set(registry.byId(nodeId).domNode, 'display', 'none');
});
Try
require(["dojo/dom-style","dojo/domReady!"], function(domStyle){
domStyle.set(dojo.byId(domNode),'display','none');
});
The variable "domNode" stays for the id of the Node that should be influenced. This is the way we make it.
Regards, Miriam
Try using the Toggler module
require(["dojo/fx/Toggler"], function(Toggler),{
// Create a new Toggler with default options
var toggler = new Toggler({
node: "btnInsert"
});
// Hide the node
toggler.hide();
// Show the node
toggler.show();
});
http://dojotoolkit.org/reference-guide/1.9/dojo/fx/Toggler.html
I imagine you would want to link this to some event using Dojo's on module. Link it up to whatever condition triggers the button's need to be hidden.

How to use the var_dump output directly from the controller?

class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
$custom = "Custom variable";
var_dump($custom);
}
}
How to display the result not using the variables in the template?
P.S. The result of the Echo function is also suppressed. I understand that this is the wrong approach, but it is a quick way to debug the variables.
if you don't see output from controller check if in your template file you have this line:
{{ content() }}
you can use php's var_dump in any place of your code:
var_dump($var);exit;
exit; is to stop anything what happens after this line.
You can also dump your vars in volt's template with volt's function:
{{dump(var)}}
dump() is same as var_dump()
Here are some more useful volt functions:
http://docs.phalconphp.com/en/latest/reference/volt.html#functions
There is an implicit rendering level in the controller, in the first view that is rendered, you must call the getContent() method:
<div class="controller-output"><?php echo $this->getContent(); ?></div>
Or in Volt:
{{ content() }}
Ok, thx twistedxtra for the tip!
In my case, I use Twig.
To resolve my issue I've added a feature to Twig:
$function = new \Twig_SimpleFunction('content', function() use($view) {
return $view->getContent();
});
$this->_twig->addFunction($function);
Now it can be used in templates:
{{ content()|raw }}
Based on your above code , i understand that your required to execute the $custom value.
There are 2 ways as follow
1 - You can write var_dump($custom); and after that put die(); so that after it no code can be executed.
You can write echo $custom , for execute the value of $custom. But you have to stop script execution after it.
May be some times it happen that code as been written but due to template or view file execution it will overwrite your code. You must check the source code does anything printed above tag that you have written in controller.
May this will help you........:)
I know I'm a little late, but, just call
exit;
after your var_dump()
You can totally disable view in the action:
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
$custom = "Custom variable";
$this->view->disable();
var_dump($custom);
}
}
Or even use own debug method:
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
$custom = "Custom variable";
$this->debug($custom);
}
public function debug($data)
{
$this->view->disable();
var_dump($data);
}
}
Phalcon\Mvc\View\Engine\Twig() change to:
https://gist.github.com/4690638
and use:
{{condent()|raw}}
{{linkTo('#', 'title')|raw}}
This is my fork ;-)
An even simpler approach would be to set "$this->view->disable()" just above your var_dump expression when using volt. Maybe this would also work with other template engines.
Why not use good old
echo "<pre>" . print_r($custom,TRUE) . "</pre>";
Prints nice and ordered array. Have to add it works from both Controllers and Views. In case of Controller, output is placed on top of Controller's view.

Access ExtJS grid's column model from other file

I have an ExtJS grid that has a button set up in it. The button triggers a function that's defined into other JS file that's included in the grid page. The function triggers ok but in that function I want to get the columns count like this:
grid.getColumnModel().getColumnCount()
The problem is that I get an error like: grid.getColumnModel is not a function.
In PHP I would make a "global $ext" and then access that function. How can I do this in Ext ? How can I access the grid from other file ? What needs to be defined ?
Thank you.
How did you define the grid object? Did you do it like this:
var grid = new Ext.grid.GridPanel(...);
If so, the grid object is not in global scope. Remove the "var" and see if it helps.
This looks like a scope issue. See variable scope in JavaScript.
Basically, you can do:
my_global_grid = ... // accessible in the current ~global~ context (document, window)
var my_local_grid = ... // accessible only in the function
window.my_window_global_grid = ... // accessible in the same window
You might also pass the grid object into your function as an argument:
function myFunction(arg1,arg2,grid){
...
var count = grid.getColumnModel().getColumnCount();
...
}