Implement Country and Province dropdown list in drupal 7 programmatically using Location module - api

I am implementing a Drupal 7 signup form (through a custom module) where users should be able to indicate their location (Country + Province/State) using dropdown lists.
From the description of Location module, this seems possible (by using APIs or someother way). I am new to Drupal and have no idea of how to implement this in the custom module programatically (using location module's APIs). I've googled about this for a couple of days, but couldn't make much progress.
Any sample code or leads would be greatly appreciated.
Thanks a Ton.

If location module provides what you what, you should use it. Otherwise try with address field module.

Ok I finally figured out how this is done. We just need to call the api function like here $country = array(location_get_provinces("us"));
This returns the provinces of the country which is supplied as a parameter.

Related

Showing Status-field as dropdown in Directus 7?

is there a way to make a Status-field display like an dropdown/select-box instead of radio-buttons? I have about 10 status' and I would like to display them as a dropdown instead.
I wasn't able to find anything about this in the documentation, did I miss something?
Thank you in advance!
Not the "core" status interface, but you can duplicate the code and create a custom one in a select instead. The new interface would go into the custom extensions directory in the API. Should be pretty straightforward.
https://docs.directus.io/extensions/interfaces.html

Can add my own custom snippets to Big Commerce

I have tried to upload my own snippet that replaces the create new account text that is held in the %%LNG_NewCustomerIntro2%% variable. Of course I am thinking this would be as simple as 123 but I guess not.
Does a snippet have to be registered? Or should I just comment out the current code in the snippet I need (or hide it with css) and then add in my code?
It seems this is common with bigcommerce....
Any suggestions
No, you can not introduce custom snippets to BigCommerce. Snippets refer to a function in the core application to supply data (thus requiring core code). It is better to remove the existing snippet and provide your own code within the panel or layout file.

SilverStripe 3: Can a module extend mysite/code/Page.php?

Good afternoon,
I don't know if what I want to do is possible, so here goes.
I have a module that extends Page_Controller, but I want certain functions to be accessible via the site root.
Eg: getMyDataObjectList();
Currently, they only work if I go through the normal MVC routing structure.
I've found that when I place the function 'getMyDataObjectList' within '/mysite/code/Page.php' it works.The problem is, I don't want to place the code in there. I want it bundled with my Custom Module, but to work the same as though it was in 'mysite/code/Page.php'
[Example Scenario]
site root: http://[somesite].com
By default, the 'Page.ss' template loads.
I would like the theme developer to be able to call my module functions (API) within any template/Layout page, and have the result returned from the site root
Currently, this only works if I move the "API" functions to '/mysite/code/Page.php'
If the code is in my module, then data is only returned when you go to:
http://[somesite].com/[module_controller]
Can this be achieved? If so, how?
Thanks for your assistance.
[Update - Code Solution]
///>MyExtension.php
class MyExtension extends Extension{
public function getMyDataObjectList(){
return 'object list goes here!';
}
}//class
///>[Module] => _config.php
Object::add_extension('Page_Controller', 'MyExtension');
And as always, I do a (/dev/build?flush=1) just in case.
Thanks to: 'simon_w'
Yes, this is relatively straightforward. Simply, create an Extension subclass with your methods in them and then add that to Page_Controller. An Extension subclass is almost exactly the same as a DataExtension, they're just for classes other than DataObjects.

Bigcommerce - Side Cart Total always shows $29.00

I am having some issues with a BigCommerce theme. It is an exact copy of a working theme, but on the new site, the mini basket/cart always shows $29.00 no matter what is in the cart (site is also set up to use £)
The issue lies with %%LNG_SideCartTotalCost%%.
Whats odd is that I checked the language file (via the url) and the text for this variable should be:
"Your sub total is <strong>%s</strong>."
Yet its coming through as:
"Total: <strong>%s</strong>."
I'm unsure who this was changed (the site is a clients, who has had work done by other developers)
How would someone change this language variable in BigCommerce? I was under the impression you could only edit themes, and not code?
So, any thoughts on how to fix this?
Thanks!
I work at Bigcommerce. The file you will need to edit is the sidecartcontents.html file. You are able to customize HTML, CSS, Javascript and JQuery. The only thing you don't have access to is any global variables that require PHP files. As a SaaS platform, we don't provide our clients access to the PHP files.
Turns out is was an issue with the language file. The support staff had to update it.

How to stop firefox from downloading and applying CSS via a firefox extension?

Thanks to everyone in advance -
So I have been banging on this issue for quite a while now and have burned through all my options. My current approach to canceling css requests is with nsIRequest.cancel inside of nsIWebProgressListener.onStateChange. This works most of the time, except when things are a little laggy a few will slip through and jump out of the loadgroup before I can get to them. This is obviously a dirty solution.
I have read through the following links to try and get a better idea of how to disable css before a nsIRequest is created...no dice.
https://developer.mozilla.org/en/Document_Loading_-_From_Load_Start_to_Finding_a_Handler
https://developer.mozilla.org/en/The_life_of_an_HTML_HTTP_request
https://developer.mozilla.org/en/Bird's_Eye_View_of_the_Mozilla_Framework
How do I disable css via presentation objects/interfaces? Is this possible? Inside of nsIDocShell there are a few attributes that kind of imply you can disable css via the browsers docshell - allowPlugins, allowJavascript, allowMetaRedirects, allowSubframes, allowImages.
Any suggestions?
Thanks,
Sam
The menu option that disables style sheets uses a function
setStyleDisabled(true)
so you probably can just call this function whenever new browser tab is created. Style sheets are still requested from server, but not applied. This function is not very sophisticated and doesn't mess with nsIRequest, source:
function setStyleDisabled(disabled) {
getMarkupDocumentViewer().authorStyleDisabled = disabled;
}
Digging in Web Developer Toolbar source code I have noticed that their "disable stylesheets" function loops trough all document.styleSheets and sets the disabled property to true, like:
/* if DOM content is loaded */
var sheets = document.styleSheets;
for(var i in sheets){ sheets[i].disabled = true; }
So if the key is to not apply CSS to pages, one of the above solutions should work. But if you really need to stop style sheets from being downloaded from servers, I'm affraid nsIRequest interception is your only option.
Set permissions.default.stylesheet to 2 and voilà!
You can actually use the permissions manager to block or allow stylesheets on a host-by-host basis.
Unfortunately there doesn't seem to be a simple flag like allowImages. The bugzilla adding for that is https://bugzilla.mozilla.org/show_bug.cgi?id=340746. You can now vote for it using the new bugzilla voting functionality. You can also add yourself to the CC list to be notified if anyone ever works on it.
A related request is to just give us basic HTML parsing support, which may be what you are trying to do. Unfortunately that isn't supported yet either, but you can vote/track the bugzilla for that at https://bugzilla.mozilla.org/show_bug.cgi?id=102699.
So the only workable solution seems to be some sort of interception as #pawal suggests. Here is a link that talks about the basics of interception to at least get you/us started https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads. It lists several options that I list below.
These first few seem to just be at the page/document level so I don't think they help:
Load Events (addEventListener load)
Web Progress Listeners (nsIWebProgressListener) - I tried this approach, it only seems to be called for the page itself, not for content within the page.
Document Loader Service - A global version of nsIWebProgressListener so I think it has the same problem (page level only)
That leaves two others I have not tried yet. They work globally so you would need to filter them to just the browser/pages you care about.
HTTP Observers - Seems like it might work, need to verify it calls back for CSS
Content Policy - Seems like the best option to me since it explicitly is called for CSS, someday I hope to try it :)