Drupal 7 Strongarm module
Share with Others
In this episode we go over the Drupal 7 Strongarm module and how it can be used to manage variables and configuration on your Drupal website. This episode looks at how the Drupal 7 Features modules can be used with the Drupal 7 Strongarm module to manage the exporting of the Drupal variables table.
In this episode you will learn:
- An overview of what the Drupal 7 Strongarm module is and how it can be helpful when developing a Drupal site
- How to use the Drupal Features module and the Drupal Strongarm module work together to allow easy exporting of variables
Code Karate's 5 Secrets to Becoming a Drupal 7 Ninja ebook contains a complete Introduction to the Drupal Features and Strongarm modules.
Hello there and welcome to another Daily Dose of Drupal, my name is Shane and today we’re on Episode Number 23. This is a little bit of a special episode because this will be the 100th post I believe on codekarate.com.
So if you haven’t look at that already, check out some of the other videos and post that are on Drupal and a whole bunch of other development topics. So we’ll go ahead and get started, we’re going to take in a little bit of detour from the Module Development tutorials we have in the past and we’re going to look at the Strong Arm Module and we’re going to talk about how strong our module can be used to export Drupal Variables.
In Drupal there’s a database table called Variables in which a lot of the core modules and contributed modules use to store different configurations and settings and what the strong our module does is it gives you a basically way for you to store those into code. So you takeout similar to how the Features Module works and it actually interacts with the features module but it basically takes that variables table and allows you store those values into an actual modules code.
In this case we’ll be using the Features Module in conjunction with the stronger module and we’ll show you how that works. The first thing you want to make sure is you have the features module installed, the C Tools module installed and I also have the Diff Module installed just so we can show the differences in between the Features Module we’re going to create and the actual database settings and if you haven’t watched my other videos on the Features Module you may want to do that as it might give you a good primer as to what we’re going to be going over here.
First is; we’re going to hop into our command line and we’re going to download the Strong Arm Module, I am the going to enable it, go ahead and say yes and now we have downloaded and enabled the Strong Arm, I’m going to go to our Modules page and show you where that is and you can see it’s been enabled, you can see the version were using requires C tools, it does not require the Features module but the Features Module is hopeful to actually allow you to easily export these variables and if you look on drupal.org at the Strong Arm page it gives you an example of one variable that you can export but these variables could be things like your … the e-mail address for the website for example or settings for your Content Types or anything else that could be configuration that is stored in the variables table.
So I’m going to click on this little Help section here and this gives you some information on installation how Strong Arm works, how to actually export the variables, there’s also an Administration page so I’m going to click this link and you can see that there’s nothing is currently showing up. So what I’m going to do is I’m going to open up a new tab and we’re going to go into the features module and I’m going to go ahead and create a new feature. I’m just going to go ahead and call this My Variables and keep everything else the same and not too concerned about that stuff right now and you’ll notice in this dropdown there’s a section now for Strong Arm.
This allows us to actually export these variables and you can see there is a large list of different variables you can export. Some of them you’ll noticed related to comments and comments on specific … for example comment page would be comment settings for that page content type but one thing we’re going to look at is Site Mail, Site Nam, as you can see we can do Site Front Page and you could do Use Registration Settings and what this can do is you can export this into code, you can bring this to another site, maybe you have a development and a live site and when you change the site name on the development site and you push this up into your live site you want that change to be represented.
That’s one alternative, there’s a whole bunch of different things you can do and we’ll go ahead and hit Download; and now we have our myvariables.tar file that has been downloaded. S I’m going to go ahead and hop into the Modules Directory for this website and I’m going to paste in this my variables.tar file that I had just downloaded and I’m going to extract it here, you can see it’s now listed there, I’ll go ahead and get rid of this and we can now come back into Drush and I’m going to go ahead and enable that new module.
And the Features Module is just like any other Drupal module so go ahead and just enable it. Now if we come back to this Features page and click on Manage, you’ll see that My Variable module is there, if I click on this, you can see my three variables are exported with this module, if i come back to the Strong Arm Settings and I refresh, you’ll notice that now it shows me that these variables are being Strong Armed and you can see it’s saved to the database.
What we’re going to eventually show you here in a second is that we can actually change this values and it’ll show us both on the Strong Arm page and on the Features page that these variables have been overwritten. So you can see currently the site name variable is saved in the database as test.codekarate.com.
So that means my code in my module file inside the My Variables folder that I’ve just extracted from that tar file is set to this value and that’s the same and matched as the database. So if I come in to Site Information and I change my site name to codekarate, that’s going to actually change this variable in the variables table in the database. So now that’s changed, if I come back here and refresh, you’ll see it says it’s overwritten, it also gives me the option to restore the value to what it is in the code, if I come over back to My Variables Feature it also shows that it’s overwritten and because I have the Diff Module installed I can click on this and it will show me that the default which is what is in code says test.codekarate.com, the override says it is codekarate.
So that’s really all there is to the Strong Arm Module and you could of course open the files up inside that module that was downloaded from Features and you can see how the module or how Features actually exports this in order to get this whole thing to work. But just keep in mind it’s important for using when you’re transferring data between different developments and staging in live websites, I generally install the Strong Arm Module on any site the install Features module on because it’s that useful.
If you have not already, follow me on Twitter @smthomas3 and we’ll be back next time with another video on the Daily Dose of Drupal. Thanks for watching.