The short answer.
The long answer.
Drupal 7 brought us Entities, and wіth them the powerful Field API fоr 'storing, loading, editing, and rendering field data.' attached tо them. If yоu're managing еverуthіng thrоugh 'manage fields' and 'manage display' tabs of yоur content type, then еverу part оf that process is rаthеr wonderfully tаkеn care оf fоr you.
We often, however, cоmе aсrоѕs the nеed tо render a field оutsіdе the context of іt'ѕ entity. A common еxаmplе mіght include rendering a node's author іn а sidebar block. Sure, modules lіke Panels аnd CCK Blocks wіll do thiѕ for you, but dоing it manually is actually not that hard.
You may wеll hаvе ѕееn (or written!) code that loоks sоmеthing lіkе this:
// This іѕ WRONG example.
$block['content'] = $node->field_name['und']['safe_value'];
Poking around thе node object for thе vаlue you wanted tо print was fairly common іn Drupal 6, and thе '...
Wow, so I've been dealing with Drupal for pretty much 5 years now since the days of 4.7. As all of the veterans might know by now, its a pain in the a$$ to upgrade a Drupal install from an old release. Recently one of my clients wanted me to update her site to incorporate new features, but I told her I would need to update her site in order for that to happen as the old drupal was quite outdated without the new features as we see today. I built the site back in 2010 when Drupal 6 was quite relatively new. Back in the days I used to just use the Acquia Drupal 6 package which included most of the popular modules needed to build a robust site. Oh and I forgot to mention I also had it on a Multi-Site setup, man what a pain it is to tear sites out of that central code base.
Well as for upgrading an old Drupal site to the lastest code, you must have a development environment to test it on. Don't even think about doing it on a live site, because I guarantee there will be errors....
Currently I replicated an existing site and now I want to clear out all the nodes that aren't relevant. Yes, you can easily use VBO (Views Bulk Operations) module, but its very cumbersome if you you just want to delete a bunch of stuff, because you'll have to download it and configure it to start deleting. Currently, core drupal has its own content list view, but doesnt give you the option to set how many to view at a time. Well, as a quick fix without installing the VBO module, you can just hack core temporarily in the node.admin.inc file on line 427. Let me know if this helped you or if you have a better method.
Apparently there's no way to set a breadcrumb for a views page via any module like "custom breadcrumb" or "hansel breadcrumb". As it seem there is a way to set it if you knew about internal drupal functions by using the drupal_set_breadcrumb() and placing the code inside the views header. Of course you will need to know some php for this. If you find another solution please post it. Hope this helps someone.
I just recently got put back on an old project that I haven't worked on for a couple of months. The code base and database on my development machine is outdated, now i go update my code via 'svn up' which goes ok! Now I go grab a copy of the database on the staging server via the module 'project/demo' which takes a snapshot of the database and lets you download it or restore it on the existing site. After downloading the database file and proceed to load it into my dev environement I get hit with junk! See here: http://prntscr.com/5ejbb
To keep things short, if you see your D7 site isn't loading any CSS or JS scripts. The culprit could very well be in the performance settings page where you would have to uncheck all of the caching methods. What I didnt realize was the staging server had Varnish setup for caching while my dev doesnt. And when loading up the staging database it was referencing varnish cache when I didnt have any!...
How do you get the vocabulary id in Drupal 7 ? Easy, you cant not through the normal methods that is. You'll have to look in the database for the vid if you need it for say as a parameter in taxonomy_get_tree(). Well, Drush to the rescue again or you can just look it up in your mysql gui.
So one of my clients needed a list view of events categorized by month and then by day. At first I thought it was going to be a simple solution with Views for Drupal 7, but apparently Views only support grouping by only 1 field. This particular problem usually involves multiple loops as a solution to most developers approaching this situation if they are not versed in scripting. I too thought this had to be accomplished with running a view in a view to get the multiple group by effect. I researched all over as of 12/12/2011 and it seems that most people in the Drupal community resorted to nested views with the views_field_view module to do muli-group by.
My solution after spending an entire day messing with all these crazy recipes was just using the Global: PHP field and group by this. First you need to figure out what is the deepest field you need to group by. In my case it was "Days" and then Months. So I added both of these fields and set them as "Exclude from Display",...
You'll need to expose the $entity object first to see what you want to copy to where using the print_r($entity) or dsm($entity) first.
You want to copy the contents of the core node title into a CCK field with the machine readable name field_title.
Select the nodes you want to process with VBO as usual;
Select the VBO action "Execute arbitrary PHP script";
For Drupal 7, enter the following PHP snippet into the textarea:
$entity->field_title['value'] = $entity->title;
Make sure to replace field_title with the actual machine name of your field, which you can find on the CCK manage fields page.
A short video showing how to install Drush on a local development machine (Ubuntu 11.10) but the steps should be similar for OS X users.
I'm sure this has happened to many people when they forget their passwords and try numerous times to find out they just got locked out of their accounts. Well, there is a cool drush command to resolve that issue by deleting all the flood entires within the "flood" table of the drupal database. If you don't have drush access you might have to go through your mysql gui to clear that up. But the table your looking for is "flood" to solve this issue!
KISS = Keep it Simple, Stupid!
I looked around the net and all i want is just a simple truncating php snippet, and most people has all these crazy methods of doing where it takes more than 3 lines to complete. Well, here it is. A super simple to the point php snippet to solve your truncating to word boundary problem. Found it useful? Let me know what you used it for if you have a better method.
Just when I was looking into NoSQL or MongoDB as something new to learn. Luckily I bumped into Adrians article about the big downfalls and vulnerabilities of this up and coming new NoSQL movement. I guess it really isnt ready for primetime yet while it still has all these security problems.
1 2 3 4 56 7 8
/** * Displays the cart contents for review during checkout. --- UBERCART/UC_CART/...
Quick and dirty explanation of how to alter a form in your Drupal 7 site. Basically you will need to name the function the same as your theme with _form_alter() in it. From there you can write a conditional to target the form_id that loads and edit the variables you want to edit. To see these variables you'll have to do a dsm($form) to expose the form array. This goes in the template.php file in your theme folder.
1 2 3 4 56 7 8 9
Quick and Dirty Explanation! Everywhere I look online they get too detailed and I get confused.
While modifying drupal 7/6 modules, I come across many functions with the & in their functions. I always wondered what does it mean and I finally got it cleared up today. It's basically just linking the variables together, or think of them as a symbolic links as how its done in the command line. You change the variable in the function you will also change it outside of the function. In a way it could be seen as a global variable.
<ivanjaros> Hi. This is more general question then Drupal question but ... I have node type that can be created by anonymous and auth. users. The thing is that I need to know which anonymouse person created which node. It doesnt have to be known for ever just a week or so. So session/cookie come to mind. How would you identify certain user in such way ?
<darkflare> ive just found the variable table in the ui
<DanielHarvey> nice, I've been seriously considering switching to Ubuntu but the multi monitor support is so lacking and 11.04 is pretty immature
<-- kallepersson has quit (Remote host closed the connection)
<duckxx> ivanjaros, i too would like to kno this<duckxx> DanielHarvey, work out of vbox ?
<-- rcross has quit (Ping timeout: 252 seconds)
* ryancross is now known as rcross
<DanielHarvey> good call, yeah, I have vmplayer just no time right now
<ivanjaros> duckxx for now I...
Audio Link: http://media.geeksandgod.com/episode143.m4a
Here are some commonly used path variables for Drupal 7/6. This was kind of annoying to find via Google since most sites just lists out the variables, and not showing you the output of them. Well here they are:
This is in reference to a drupal 7 installed in a sub directory. Example used: http://www.foo.com/bar
[Sites Files Path]
Drupal 7 -- variable_get('file_public_path', conf_path() . '/files') = sites/default/files
Drupal 6 -- file_directory_path()
Found this useful? All I ask is just comment to show your appreciation if this helped you out.
View the node date of a node page and display it in the shell. Very useful if your trying to reference variables in your tpl files or what not.
drush -u admin php-eval "print_r(node_load(17));" | ack -A20 'body'
Another thing I find my self frequently doing is deleting Nodes. I hate it where I have to go the Node page, click on edit, click on delete, and then click on confirm. All that time just takes way too long. Here's an awesome Drush command for deleting nodes via the shell. There is a drush add on for it, but that's just extra work downloading it. I'm being lazy. =P
drush -u admin php-eval "node_delete(17);"
Leave a comment if you found this useful!
If you manage many Drupal 7/6 sites, there are those times you just can't remember all the password and would require a reset via email. But that just takes too long to do. Compared to 1-3 minutes for a password reset via the slow way or the fast way of at most 5 seconds. For all those Drush users, this is a handy command to use:
drush user-password username --password="new_password"
If your drush command is not working you can also do this by generating a URL link where you can reset through the browser:
drush php-eval 'echo user_pass_reset_url(user_load(1));'
The link that it outputs you will have to append it to the end of your domain name.
I've been waiting for 2 step authentication security for some time. Seems like the duo security guys finally did it right. If you value your site or server, this is a must install module. I'll be giving a quick presentation on this at the NYC meetup for this coming August 2011 meetup.
check it out yourself: http://drupal.org/project/duo
ncftp -u "userid" example.com
Handy ncftp command compared to the regular ftp command as this lets you upload/put directories recursively to a remote server.
drush ev 'print_r(theme_get_registry())' | ack -A10B5 '\[table\]'
drush with php command to print out the drupal's theme functions via the command line. And then pipe it through ack, which is just a better version of grep. It just searches for the theme your looking for and outputs it with 10 lines After it and 5 lines Before it.
Greate little tool to convert your fonts to use with the css font face property!
great video about theming fields using templates.
Please use with caution as this is still an Alpha release! Drupal 7 version is on the way.
Great little tip on passing varibles from the page to the node templates.
This is awesome the jBart Module just got updated, you can download it from here:
or you can just get it from the sandbox page on d.o