Joomla 3.9.19 get the constants from global configuration in component display function - constants

I have created a component and need to get a constant value in the component administrator and list the item according to it. I have tried different ways to get the constant value in the 'display()' function in 'view.html.php'. I am expecting the value will be available in the default.php with $this.
I have defined the constant in the configuration.php file, A URL is supposed to define.
define('CONSTANTVALUE', 'the URL string');
in the display() function,
$config = JFactory::getConfig();
$constantvalue = $config->get('CONSTANTVALUE');
$this->constantvalue= $constantvalue;
Seems this is not working.
Then, I have tried
JFactory::getApplication()->get('CONSTANTVALUE');
That also not working.
I have referred to this thread, Joomla 3 - How to get value from configuration file?
How can I get the constant from configuration to component view file?

Related

FuelPHP \URI::current() does not get file extension

My project requires me to know what file extension was used while calling a route.
For example,
If the route was 127.0.0.1/controller/action/filea.json
Then then I would need to have a function that returns ".json" when called from inside action function "get_action".
If the route was 127.0.0.1/controller/action2/fileb.xml
Then then the function should return ".xml" when called from inside action function "get_action2".
Right now, I tried using \URI::current(), but that only gets me "127.0.0.1/controller/action/filea" or "127.0.0.1/controller/action2/fileb"
Whether or not the extension is used is controlled by the config key routing.strip_extension, which is true by default.
The current extension can be retrieved using \Input::extension().

Getting properties from AEM multifieldpanel dialog stops working when a second entry is added

I have created an AEM Dialog which prompts the user for a set of links and labels.
These links and labels are stored in a jcr node and are used to generate a menu.
To avoid having to create a custom xtype, I am using the acs-commons multifieldpanel solution, which enables me to nest children under the fieldConfig node.
This works great with only 1 Label/Link pair, but when I add a second one - the property cannot be fetched anymore, since instead of a String, it returns the String hashcode.
The property generated by the multifieldpanel in the jcr node is of type String and is filled correctly when inspecting in CRXDE. The problem occurs when I try to fetch the value from within a Sightly HTML file.
Code
Dialog:
Definitions.js:
"use strict";
use(function () {
var CONST = {
PROP_URLS: "definitions",
};
var json = granite.resource.properties[CONST.PROP_URLS];
log.error(json);
return {
urls: json
};
});
Log output
1 element in multifieldpanel
jcr node variable content
definitions: {"listText": "facebook", "listPath": "/content/en"}
log output
{"linkText":"facebook","linkPath":"/content/en"}
Multiple elements in multifieldpanel
jcr node variable content
definitions: {"listText": "facebook", "listPath": "/content/en"},{"listText": "google", "listPath": "/content/en"}
log output
[Ljava.lang.String;#7b086b97
Conclusion
Once the multifieldpanel has multiple components and stores it, when accessing the property the node returns the String hashcode instead of the value of the property.
A colleague has pointed out that I should use the MultiFieldPanelFunctions class to access the properties, but we are using HTML+Sightly+js and are trying to avoid .jsp files at all cost. In JavaScript, this function is not available. Does anyone have any idea how to solve this issue?
That is because, when there is a single item in the multifield, it returns a String, where as it returns a String[] when there is more than a single item configured.
Use the following syntax to read the property as a String array always.
var json = granite.resource.properties[CONST.PROP_URLS] || [];
Additionally, you can also use TypeHints to make sure your dialog saves the value as String[] always, be it single item or multiple items that is configured.
Don't forget that the use() in JS is compiled into Java Byte code and if you are reading Java "primitives", make sure you convert them to JS types. It's part of the Rhino subtleties.
On another note, I tend to not use the granite.* because they are not documented no where, I use the Sightly global objects instead https://docs.adobe.com/content/docs/en/aem/6-0/develop/sightly/global-objects.html
To access properties, I use properties.get("key")
Hope this help.

Accessing value by javascript Play Framework/Scala

First of all I am using Play framework with scala.
I am creating a graph and with the node id I would like to show some information at the same page.
In order to do that, first I need to get node.name but for some reasons #node.name function is not working. When searching for it I learnt that it's because play is server-side and js is client-side. However I need to get the data somehow.
I also cannot access:
var html = "<h4>" + node.name + "</h4><b> connections:</b><ul><li>"
How can I access this through the view?
My second question is after reaching the js node.name, I need to access to controller and do the same action one more time but this time with the new node.name .
View Part:
onClick: function(node) {
#node.name
}
1) Is this code in your controller? And are the node variable in scope? If so this should be perfectly legal code, since it will be evaluated as pure scala.
2) The templates are a different story however. You probably know they parse everything as normal html, unless escaped. To use a variable you have to bring it into scope by either:
defining a 'constructor' for the template at the absolute beginning of the file:
#(node : Node)
...
#node.name // later in the file
See http://www.playframework.com/documentation/2.0/ScalaTemplates
or define a variable inside the template:
#defining( Get.node.from.somewhere ) { node =>
#node.name
}
See Play! framework: define a variable in template?
If you did either of the two, you should have no problem accessing the node variable. Even in scripts. But note that external scripts does not have access to the same variables. It is thus very common to use inline scripts or import it as another template if you need to access a variable from JavaScript.
Edit: I've made a gist of a template, controller and routes file: https://gist.github.com/Jegp/5732033

Which file contains function of core/session in magento?

I need to customize other's code,
so I found they used
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
in Order.php file for custom order email
so I can't find this function getMyCustomBlockInfo();
Can anyone tell me where this function reside?
Thanks
those are magic functions get() and set() and you are asking a session variable there that is set as
Mage::getSingleton('core/session')->setMyCustomBlockInfo();
somewhere in your code. If you use terminal you can easily find by making a following grep:
grep '>setMyCustomBlockInfo(' . -rsni
and it will list the files where your variable is set to session.
example :
Mage::getModel('catalog/product'); //or
Mage::getSingleton('catalog/product');
the code must be in '../app/core/Mage/Catalog/Model/Product.php' file
then
Mage::getSingleton('core/session');
the code must be in '../app/core/Mage/Core/Model/Session.php' file
because the class Mage_Core_Model_Session's parent::parent is Varien_Object, then you can do all magic functions and you can ->getData() to see the Data inside.
Mage::getSingleton('core/session')->getData();
on your problem when go call ->getData() you can see data : [my_custom_block_info]
you can set it with call
Mage::getSingleton('core/session')->setMyCustomBlockInfo('what');
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
// will return 'what'

How to use form validation with the file uploader to make sure a file is uploaded

Can anyone suggest how using the form validation rules I can say the following:-
If no file is uploaded - then create a rule to say 'no file uploaded' using the form validator library.
I am using CodeIgniter 2.
For instance - it is simple to validate on a text input field using the following, but I cannot understand how this is done with upload (that uses the $_FILES array rather than $_POST)
eg.
$this->form_validation->set_rules('title', 'Title', 'required'); // input field named 'title' is required
CodeIgniter's File Uploading class handles its own validation - no need to use the Form Validation class.
Per the documentation,
$this->upload->display_errors()
Retrieves any error messages if the do_upload() function returned
false. The function does not echo automatically, it returns the data
so you can assign it however you need.
In your example above, if the file input is left empty, $this->upload->display_errors() will return the following:
You did not select a file to upload.
So, set your preferences (see the "Setting Preferences" section of the documentation for exactly what is available):
// The following are just examples from the documentation...
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
// ... other preferences as necessary
If any of the above fail during the attempted upload, $this->upload->display_errors() will retrieve the appropriate error message. Simply pass it to your view to display the error(s).
Hope that helps.