Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home1/tylerfra/public_html/includes/common.inc).

drupal 7.x

Headless Drupal Web App with Angular JS and DrupalGap

In this tutorial (for NYC CAMP 2015) we'll explore how to use Drupal 7 and DrupalGap 2 (powered by Angular JS) to build a decoupled ("headless") web application for Drupal. In a nutshell, here is what the app will do:

  1. A user runs the app in their browser
  2. The browser asks the user for access to their current location
  3. The app passes their location to Drupal
  4. Drupal will return nearby content (if any) to the app
  5. The app will display the locations on a map and let the user click on them to see more details

Ready? Let's rock and roll, no time to fiddle...

Headless Drupal with Angular JS and Bootstrap - Hello World

This tutorial describes how to build a very simple de-coupled Drupal web application powered by Angular JS and Bootstrap. The inspiration for writing this tutorial came after completing my first Angular JS module (angular-drupal), which of course is for Drupal!

To keep things simple, and in the spirit of "Hello World", the application will let us login using credentials from the Drupal website, and then say hello to the user upon successful login.

The complete code for this example app is available here: https://github.com/signalpoint/headless-drupal-angular-bootstrap-hello-w...

Ready? Alright, let's go headless...

Build a Mobile App to Geo Locate Nearby Places with Drupal

In this tutorial (for DrupalCamp Ohio 2014) we'll explore how to build a mobile application and website that can geo locate places near our current position. The nearby location results will be displayed on a map, and will allow us to click on a result item to view its complete details.

The website will be powered by Drupal 7. The mobile application will be built using DrupalGap, which is powered by PhoneGap and jQuery Mobile. Let's get started!

Drupal Address Field Component Names in Plain English

Even after many years of using the Address Field moule, I still forget what the component names mean in English from time to time. So here's a list to help me (and you) remember (some of them are super obvious, so I'll leave them blank, others I'll leave up to your interpretation and let you figure it out for fun):

Drupal - Change the Output of "Member for" on User Profiles

When viewing a user account profile page in Drupal, by default the "History" field is displayed like so:

Drupal Commerce Order Owner Autocomplete with E-mail Address

When creating an order as an admin in Drupal Commerce, we can specify the user that owns the order if we know their user name. This works well in most cases, but to be able to search by the user's e-mail address would be helpful too. I've had a few requests from clients for this feature. So without further ado, let's ado it!

/**
 * Implements hook_menu().
 */
function my_module_menu() {
  $items = array();
  $items['my_module/commerce/order-owner/autocomplete'] = array(
    'page callback' => 'my_module_commerce_order_owner_autocomplete',
    'access arguments' => array('configure order settings'),
    'type' => MENU_CALLBACK
  );
  return $items;
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function my_module_form_commerce_order_ui_order_form_alter(&$form, &$form_state, $form_id) {
  // Attach our custom autocomplete to the order owner name input so we can
  // search by e-mail address.
  $form['user']['name']['#autocomplete_path'] = 'my_module/commerce/order-owner/autocomplete';
}

/**
 * Queries results for the commerce order owner autocomplete.
 */
function my_module_commerce_order_owner_autocomplete($string) {
  $matches = array();
  $query = db_select('users', 'u');
  $query
    ->fields('u', array('uid', 'name', 'mail'))
    ->condition(db_or()
      ->condition("u.mail", '%' . db_like($string) . '%', 'LIKE')
      ->condition("u.name", '%' . db_like($string) . '%', 'LIKE')
    )
    ->condition('u.uid', 0, '<>')
    ->range(0, 10);
  $results = $query->execute();
  foreach ($results as $row) {
    $key = "$row->name";
    $matches[$key] = "$row->name - $row->mail ($row->uid)";
  }
  drupal_json_output($matches);
}

Drupal User Entity Reference Field with Custom Autocomplete that uses an Address Field

User reference fields (aka entity reference fields) are great. As you may have guessed, we can use these fields to reference users on other entities (e.g. nodes).

Say we had a user reference field on the Article content type... by default, when selecting a user to reference, we could configure the field widget to be an autocomplete. This allows us to begin typing the user's login name as a way to reference them. This works well in most cases.

What if we had an address field on our user entities, and collected the user's first and last names? It may be more usable for site administrators to be able to search across the user's actual name instead of their user name for logging in.

We can use hook_menu(), hook_form_BASE_FORM_ID_alter(), and a custom callback function to provide a custom autocomplete widget that searches across our address field's values instead...

EntityMetadataWrapperException: Unknown data property commerce_product. in EntityStructureWrapper->getPropertyInfo()

After struggling with this issue for days, and days, and days, and more days, I was finally able to debug it by placing the following line of code in the getPropertyInfo() function inside of the sites/all/modules/entity/includes/entity.wrapper.inc file (be sure to have the Devel module enabled on your Drupal site):

dpm(debug_backtrace());

The code above should go right before this line:

When should I use t() in Drupal?

This page contains information about when, and when not to use the t() function in Drupal 7 (and beyond). I learned this information from the Localization API, and will add more tid-bits as I learn them. Until then, t('thanks for stopping by!');

When to use it...

drupal_set_message(t('Hello'));
l(t('Hello'));

When to NOT use it...

In hook_menu() and/or hook_perm()

Text declared in hook_menu() and hook_perm() are automatically translated when displayed.

Drupal - Views Calendar Theme "Page by date" Navigation Title

I was using Views to display a calendar of events. I then attached a date navigation pager to the calendar. By default, the navigation title was coming out looking like this:

Pages

Subscribe to RSS - drupal 7.x