Often while building a Drupal website, you'll need to create a custom Block containing HTML and content. Completely standard right? It's a problem when your client or the site maintainer needs to change some of that content. They are forced to wade through significant amounts of HTML to find that little bit of content to update. Instead, why don't you build a custom settings page? Your site maintainer gets a simple form to update and you get variables to output.
The Node, Views and Panels modules can (and should!) handle most pages you need on a site, but sometimes you need complete control of a "hard coded" content area. You could create a new Page node with a Full HTML text format. Instead, how about putting the whole thing in code? Your work will be in version control and much more straightforward to maintain. Imagine editing HTML in a text editor rather than in the Drupal admin! So much better.
Sometimes you need to script a git pull or you just want to completely reset a repo to HEAD. You there are loads of errors git can throw you in the process; such as error: unable to unlink old 'sites/default/settings.php' or error: The following untracked working tree files would be overwritten by checkout. Below is my take on the complete repository reset/clean/pull. Let me know in the comments if you've got a better way or find errors I'm missing.
Let's say you have a content type, containing a Field Collection which itself contains an Addressfield and you have to create the node programmatically. Complicated enough? Just imagine the rest of the content type I've got here! Below is how to do it without spending hours sailing the seas of che... PHP Exceptions.
Creating nodes via the UI in Drupal is easy, creating or updating them programmatically(in code) has always been a tedious. I've nearly lost my mind staring into the depths of a dpm($node);
The problem was the lack of straightforward API to handle the field level CRUD. You had to manually shove correctly formatted data into an object, often by comparing against an existing node's array. The correct old process went(and still can if you want!) like this:
I need to insert a key/value at a certain position in an associative array. It seems like a common issue. I was surprised to discover there wasn't a straightforward answer. Here is the method I created. If you know of a more efficient method, please let me know in the comments.
A common issue when building a site in Drupal: you've got a $node, $vars['node'], or $form_state['node'] and need to render an image (with image style) from one of the fields. I am building a custom form in this instance, and need to show the first image stored in some loaded nodes.
Update: Dave Reid just added basic field token support to Token. Try the beta4 of Token (http://drupal.org/project/token) before Entity Tokens. I worked out what needed to happen a few weeks ago, and finally wrote it up. I didn't realize there was an update the Token when I posted. Haha! Internet moves quick!
I'm building an interface to simplify the user experience during content creation. Users select options in three <select> fields, then on submit, they are forwarded to the correct content type add node form for the options selected. Some of the values from the original form will be be pre-filled in the new node add form.
To create this new form, I need fields from the content types and user profile. Given a content type, field name, and field instance, this is the code you need to get the Form API renderable array for the field.