4 years 5 months ago

The short answer.

Use field_view_field()!

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'][0]['safe_value'];
Poking around thе node object for thе vаlue you wanted tо print was fairly common іn Drupal 6, and thе '...

4 years 6 months ago

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....

4 years 6 months ago

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.

4 years 7 months ago

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.

4 years 7 months ago

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!

...
4 years 8 months ago

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.

4 years 8 months ago

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",...

4 years 8 months ago

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[0]['value'] = $entity->title;
node_save($entity);

Make sure to replace field_title with the actual machine name of your field, which you can find on the CCK manage fields page.

4 years 8 months ago

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.

4 years 9 months ago

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!

4 years 11 months ago

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.

5 years 2 weeks ago

 

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.
------------------

Of all оf the presentations аt Black Hat USA 2011, I found Brian Sullivan’s presentation on “Server-Side JavaScript Injection: Attacking NoSQL аnd Node.js” thе moѕt startling. While I wаs aware оf thе poor security оf most NoSQL database installations – еspесіallу thеіr lack оf support fоr authorization and authentication – I wаѕ not aware of their susceptibility tо injection оf both commands and code. Apparently Mongo аnd mаny оf the NoSQL databases аrе nоthіng mоre thаn JavaScript processing engines, wіthout the stigma of authentication. Most оf thеse products аrе subject tо sеverаl classes оf attack, including injection, XSS, аnd CSRF. Brian...

5 years 1 month ago
1
2
3
4
56
7
8
/**                                                                                                                                                          
 * Displays the cart contents for review during checkout. --- UBERCART/UC_CART/...
5 years 1 month ago

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
...
5 years 1 month ago

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.
 

5 years 1 month ago

<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...

5 years 1 month ago

On this week's podcast, Rob and Matt return to talk about the importance of making the front end of your website faster with things like CSS sprites and minimized javascript, ebooks vs. print books, and other completely unrelated ramblings. Oh, and Rob reminds you that if you're reading this, you should probably be outside instead.

Audio Link: http://media.geeksandgod.com/episode143.m4a

5 years 1 month ago

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

$base_root = http://www.foo.com
$base_url = http://www.foo.com/bar
$base_path = /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.

5 years 1 month ago

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.

1
 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

1
drush -u admin php-eval "node_delete(17);"

Leave a comment if you found this useful!

5 years 1 month ago

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.

5 years 1 month ago

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

5 years 1 month ago

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.

5 years 1 month ago

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.

5 years 2 months ago

Greate little tool to convert your fonts to use with the css font face property!

http://www.fontsquirrel.com/fontface/generator

5 years 2 months ago

great video about theming fields using templates.

5 years 3 months ago

http://dl.dropbox.com/u/22745533/jbart_view-6.x-1.04.zip

Please use with caution as this is still an Alpha release! Drupal 7 version is on the way.

5 years 3 months ago

http://cheekymonkeymedia.ca/blog/gene/drupal-7-passing-page-level-variab...

Great little tip on passing varibles from the page to the node templates.

5 years 3 months ago

This is awesome the jBart Module just got updated, you can download it from here:

http://dl.dropbox.com/u/22745533/jbart_view-6.x-1.04.zip

or you can just get it from the sandbox page on d.o

http://drupal.org/sandbox/shaibenyehuda/1112148

5 years 4 months ago
Below is a demo of a jBart widget i made using drupal xml feed data generated using views and adding a new feed display. A jBart module was created to output this feed and you can download it here: jBart Drupal Module

Install Instructions:
1. install module.
2. create a feed view/display with jBart-Xml style.
3. add the relevant fields for the view
4. open the new display/view.
5. copy the source of it
6. open artwaresoft.com
7. create my first widget.
8. create widget from xml
9. paste the xml.
10. customize it inside the jBart studio (i want us to do it together in the first time, maybe with teamviewer or other program)
11. embed it back in any place in your drupal site.
12. Have Fun!
More information you can contact: Erez - http://drupal.org/user/1195872
Presentation slides given at the NYC Drupal meetup:...
5 years 4 months ago
...