diff --git a/README.txt b/README.txt
index aef579f..da43ba5 100644
--- a/README.txt
+++ b/README.txt
@@ -1,4 +1,4 @@
-Automatic Entity Labels Module
+Automatic Entity Title Module
 ------------------------------
 by Benedikt Forchhammer, b.forchhammer@mind2.de
 
@@ -7,22 +7,22 @@ Initial port to entities by Vasi Chindris, https://drupal.org/user/342104
 
 Description
 -----------
-This is a small and efficient module that allows hiding of entity label fields.
-To prevent empty labels it can be configured to generate the label
-automatically by a given pattern. The module can be used for any entity type
-that has a label, including e.g. for node titles, comment subjects, taxonomy
-term names and profile2 labels.
+This is a small and efficient module that allows hiding of entity title fields.
+To prevent empty titles it can be configured to generate the title automatically
+by a given pattern. The module can be used for any entity type that has a title,
+including e.g. for node titles, comment subjects, taxonomy term names and
+profile2 titles.
 
-Patterns for automatic labels are constructed with the help of tokens. Drupal
+Patterns for automatic titles are constructed with the help of tokens. Drupal
 core provides a basic set of tokens [1]. For a token selection widget install
 the token module [2]. Some entity types (e.g. profile2) provide tokens via the
 entity_token module, which is part of the entity module [3].
 
-Advanced users can use PHP code for automatically generating labels. See below
+Advanced users can use PHP code for automatically generating titles. See below
 for more information.
 
 
-Installation 
+Installation
 ------------
  * (optional) Download and install the token module in order to get token
    replacement help.
@@ -44,10 +44,10 @@ Notes
    are automatically migrated to this module and deleted to prevent conflicts
    between both modules. There is currently no way to undo this process.
 
-3) Automatic entity labels also works with title replacements provided by the
+3) Automatic entity titles also works with title replacements provided by the
    Title module [5].
 
-4) When you change the pattern for automatic labels, existing entities are not
+4) When you change the pattern for automatic titles, existing entities are not
    updated automatically. For 'node' entities you can use the 'batch update'
    feature on the 'admin/content' page to update the title of existing nodes to
    your new pattern. This is currently not possible for other entity types.
@@ -56,25 +56,25 @@ Notes
 Advanced Use: PHP Code
 ----------------------
 
-Users which have the 'use PHP for label patterns' permission can use PHP code
-within patterns for automatic label genereration.
+Users which have the 'use PHP for title patterns' permission can use PHP code
+within patterns for automatic title genereration.
 
 Here is a simple example, which just adds the node's author as title:
 
 	<?php return "Author: $entity->name"; ?>
 
 Two variables are available for use:
-- $entity : the entity for which the label is generated
-- $language : the intended language of the label
+- $entity : the entity for which the title is generated
+- $language : the intended language of the title
 
 You can also combine tokens with PHP evaluation. Be aware that this can lead to
 security holes if you use textual values provided by users. If in doubt, avoid
 combining tokens with php evaluation.
 
-Here is an example, which sets an entity label to the value of a field
+Here is an example, which sets an entity title to the value of a field
 (field_testnumber), or the entity bundle (node type) if the field value is
 empty.
- 
+
 <?php
   $token = '[field_testnumber]';
   if (empty($token)) {
@@ -82,12 +82,12 @@ empty.
   }
   else {
     return $token;
-  } 
+  }
 ?>
 
 
 [1] http://drupal.org/documentation/modules/token
 [2] http://drupal.org/project/token
-[3] http://drupal.org/project/entity 
+[3] http://drupal.org/project/entity
 [4] http://drupal.org/node/1445124
 [5] http://drupal.org/project/title
diff --git a/auto_entity_title.admin.inc b/auto_entity_title.admin.inc
new file mode 100644
index 0000000..72bc6b6
--- /dev/null
+++ b/auto_entity_title.admin.inc
@@ -0,0 +1,105 @@
+<?php
+
+/**
+ * @file
+ *   Contains administration forms.
+ */
+
+/**
+ * Administration form for each bundle.
+ */
+function auto_entity_title_settings_form($form, $form_state, $entity_type, $bundle_arg) {
+  $info = entity_get_info($entity_type);
+  $bundle_name = is_object($bundle_arg) ? $bundle_arg->{$info['bundle keys']['bundle']} : $bundle_arg;
+  $bundle_title = $info['bundles'][$bundle_name]['label'];
+  $key = $entity_type . '_' . $bundle_name;
+  $default_value = auto_entity_title_get_setting($key);
+  $form['auto_entity_title'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Automatic title generation for @type', array('@type' => $bundle_title)),
+    '#weight' => 0,
+    /* '#attached' => array( // Not needed anymore at the moment.
+      'js' => array(
+        'auto-entity-title' => drupal_get_path('module', 'auto_entity_title') . '/auto_entity_title.js',
+      ),
+    ),*/
+  );
+  $form['auto_entity_title']['auto_entity_title_' . $key] = array(
+    '#type' => 'radios',
+    '#default_value' => $default_value,
+    '#options' => _auto_entity_title_options($entity_type, $bundle_name),
+  );
+  $form['auto_entity_title']['auto_entity_title_pattern_' . $key] = array(
+    '#type' => 'textarea',
+    '#title' => t('Pattern for the title'),
+    '#description' => t('Leave blank for using the per default generated title. Otherwise this string will be used as title. Use the syntax [token] if you want to insert a replacement pattern.'),
+    '#default_value' => variable_get('auto_entity_title_pattern_' . $key, ''),
+  );
+  // Don't allow editing of the pattern if PHP is used, but the users lacks
+  // permission for PHP.
+  if (variable_get('auto_entity_title_php_' . $key, '') && !user_access('use PHP for title patterns')) {
+    $form['auto_entity_title']['auto_entity_title_pattern_' . $key]['#disabled'] = TRUE;
+    $form['auto_entity_title']['auto_entity_title_pattern_' . $key]['#description'] = t('You are not allow the configure the pattern for the title, as you lack the %permission permission.', array('%permission' => t('Use PHP for title patterns')));
+  }
+  // Display the list of available placeholders if token module is installed.
+  if (module_exists('token')) {
+    $form['auto_entity_title']['token_help'] = array(
+      '#theme' => 'token_tree',
+      '#token_types' => array($info['token type']),
+    );
+  }
+
+  $form['auto_entity_title']['auto_entity_title_php_' . $key] = array(
+    '#access' => user_access('use PHP for title patterns'),
+    '#type' => 'checkbox',
+    '#title' => t('Evaluate PHP in pattern.'),
+    '#description' => t('Put PHP code above that returns your string, but make sure you surround code in <code>&lt;?php</code> and <code>?&gt;</code>. Note that <code>$entity</code> and <code>$language</code> are available and can be used by your code.'),
+    '#default_value' => variable_get('auto_entity_title_php_' . $key, ''),
+  );
+  return system_settings_form($form);
+}
+
+/**
+ * Constructs the list of options for the given bundle.
+ */
+function _auto_entity_title_options($entity_type, $bundle_name) {
+  $options = array(
+    AUTO_ENTITYLABEL_DISABLED => t('Disabled'),
+  );
+  if (auto_entity_title_entity_title_visible($entity_type, $bundle_name)) {
+    $options += array(
+      AUTO_ENTITYLABEL_ENABLED => t('Automatically generate the title and hide the title field'),
+      AUTO_ENTITYLABEL_OPTIONAL => t('Automatically generate the title if the title field is left empty'),
+    );
+  }
+  else {
+    $options += array(
+      AUTO_ENTITYLABEL_ENABLED => t('Automatically generate the title'),
+    );
+  }
+  return $options;
+}
+
+/**
+ * Check if given entity bundle has a visible title on the entity form.
+ *
+ * @param $entity_type
+ *   The entity type.
+ * @param $bundle_name
+ *   The name of the bundle.
+ *
+ * @return
+ *   TRUE if the title is rendered in the entity form, FALSE otherwise.
+ *
+ * @todo
+ *   Find a generic way of determining the result of this function. This
+ *   will probably require access to more information about entity forms
+ *   (entity api module?).
+ */
+function auto_entity_title_entity_title_visible($entity_type, $bundle_name) {
+  $hidden = array(
+    'profile2' => TRUE,
+  );
+
+  return empty($hidden[$entity_type]);
+}
diff --git a/auto_entity_title.info b/auto_entity_title.info
new file mode 100644
index 0000000..daaf67a
--- /dev/null
+++ b/auto_entity_title.info
@@ -0,0 +1,3 @@
+name = Automatic Entity Titles
+description = Allows hiding of entity title fields and automatic title creation.
+core = 7.x
diff --git a/auto_entity_title.install b/auto_entity_title.install
new file mode 100644
index 0000000..f2299f1
--- /dev/null
+++ b/auto_entity_title.install
@@ -0,0 +1,159 @@
+<?php
+
+/**
+ * @file
+ * Installation file for the automatic entity titles module
+ */
+
+/**
+ * Implements hook_install().
+ */
+function auto_entity_title_install() {
+  // Make sure hooks are invoked after cck main hooks.
+  db_query("UPDATE {system} SET weight = 5 WHERE name = 'auto_entity_title'");
+
+  // Migrate settings (variables) from the auto_nodetitle module.
+  _auto_entity_title_ant_migrate();
+
+  // Migrate settings (permission+variable) from the auto_nodetitle module.
+  _auto_entity_title_auto_entitylabel_migrate();
+
+  // Notify the user they may want to install token.
+  if (!module_exists('token')) {
+    $t = get_t();
+    drupal_set_message($t('If you install the <a href="!url">Token module</a>, Automatic Entity Title will be able to use token patterns.', array('!url' => 'http://drupal.org/project/token')));
+  }
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function auto_entity_title_uninstall() {
+  static $variables = array(
+    'auto_entity_title',
+    'auto_entity_title_pattern',
+    'auto_entity_title_php',
+  );
+
+  foreach (entity_get_info() as $entity_type => $entity_info) {
+    foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
+      foreach ($variables as $variable) {
+        variable_del($variable . '_' . $entity_type . '_' . $bundle_name);
+      }
+    }
+  }
+}
+
+/**
+ * Migrate settings from the automatic nodetitle module.
+ */
+function _auto_entity_title_ant_migrate() {
+  // Stop migration if no ant_* variables exist.
+  $ant_variables_exist = db_select('variable', 'v')->fields('v', array('name'))->condition('name', 'ant_%', 'LIKE')->execute()->rowCount();
+  if (!$ant_variables_exist) {
+    return;
+  }
+
+  $types = node_type_get_types();
+  $php_types = array();
+  foreach ($types as $key => $value) {
+    // Import auto_nodetitle variables (ant_*)
+    if (variable_get('ant_' . $key)) {
+      variable_set('auto_entity_title_node_' . $key, variable_get('ant_' . $key));
+    }
+    if (variable_get('ant_pattern_' . $key)) {
+      variable_set('auto_entity_title_pattern_node_' . $key, variable_get('ant_pattern_' . $key));
+    }
+    if (variable_get('ant_php_' . $key)) {
+      variable_set('auto_entity_title_php_node_' . $key, variable_get('ant_php_' . $key));
+    }
+    variable_del('ant_' . $key);
+    variable_del('ant_php_' . $key);
+    variable_del('ant_pattern_' . $key);
+
+    // Import variables from vasi1186's intial entitylabel patch (see #1124484)
+    if (variable_get('ant_node_' . $key)) {
+      variable_set('auto_entity_title_node_' . $key, variable_get('ant_node_' . $key));
+    }
+    if (variable_get('ant_pattern_node_' . $key)) {
+      variable_set('auto_entity_title_pattern_node_' . $key, variable_get('ant_pattern_node_' . $key));
+    }
+    if (variable_get('ant_php_node_' . $key)) {
+      variable_set('auto_entity_title_php_node_' . $key, variable_get('ant_php_node_' . $key));
+    }
+    variable_del('ant_node_' . $key);
+    variable_del('ant_php_node_' . $key);
+    variable_del('ant_pattern_node_' . $key);
+
+    // Create list of types using php patterns for warning.
+    if (variable_get('auto_entity_title_php_node_' . $key)) {
+      $php_types[] = $value->name;
+    }
+  }
+
+  drupal_set_message(t('All settings from the <em>Automatic Nodetitles</em> module have been migrated to the entity titles module. You can disable the <em>Automatic Nodetitles</em> module now if you have it installed.'));
+  if (!empty($php_types)) {
+    $php_types = '<em>' . implode('</em>, <em>', $php_types) . '</em>';
+    drupal_set_message(t('Please check all title patterns which use PHP evaluation! Any patterns using the <code>$node</code> variable need to be updated to use the <code>$entity</code> variable instead. The following node types have php evaluation enabled at the moment: !types', array('!types' => filter_xss($php_types, array('em')))), 'warning');
+  }
+}
+
+/**
+ * Migrate settings from the automatic entitylabel module.
+ */
+function _auto_entity_title_auto_entitylabel_migrate() {
+  // Grant the entitylabel permission to all roles which had the nodetitle one.
+  $roles = user_roles(TRUE, 'use PHP for label patterns');
+  foreach ($roles as $rid => $role) {
+    user_role_grant_permissions($rid, array('use PHP for title patterns'));
+  }
+
+  // Stop migration if no auto_entitylabel_* variables exist.
+  $auto_entitylabel_variables_exist = db_select('variable', 'v')->fields('v', array('name'))->condition('name', 'auto_entitylabel_%', 'LIKE')->execute()->rowCount();
+  if (!$auto_entitylabel_variables_exist) {
+    return;
+  }
+
+  $types = node_type_get_types();
+  $php_types = array();
+  foreach ($types as $key => $value) {
+    // Import auto_entitylable variables
+    if (variable_get('auto_entitylabel_' . $key)) {
+      variable_set('auto_entity_title_node_' . $key, variable_get('auto_entitylabel_' . $key));
+    }
+    if (variable_get('auto_entitylabel_pattern_' . $key)) {
+      variable_set('auto_entity_title_pattern_node_' . $key, variable_get('auto_entitylabel_pattern_' . $key));
+    }
+    if (variable_get('auto_entitylabel_php_' . $key)) {
+      variable_set('auto_entity_title_php_node_' . $key, variable_get('auto_entitylabel_php_' . $key));
+    }
+    variable_del('auto_entitylabel_' . $key);
+    variable_del('auto_entitylabel_php_' . $key);
+    variable_del('auto_entitylabel_pattern_' . $key);
+
+    // Import variables from vasi1186's intial entitylabel patch (see #1124484)
+    if (variable_get('auto_entitylabel_node_' . $key)) {
+      variable_set('auto_entity_title_node_' . $key, variable_get('auto_entitylabel_node_' . $key));
+    }
+    if (variable_get('auto_entitylabel_pattern_node_' . $key)) {
+      variable_set('auto_entity_title_pattern_node_' . $key, variable_get('auto_entitylabel_pattern_node_' . $key));
+    }
+    if (variable_get('auto_entitylabel_php_node_' . $key)) {
+      variable_set('auto_entity_title_php_node_' . $key, variable_get('auto_entitylabel_php_node_' . $key));
+    }
+    variable_del('auto_entitylabel_node_' . $key);
+    variable_del('auto_entitylabel_php_node_' . $key);
+    variable_del('auto_entitylabel_pattern_node_' . $key);
+
+    // Create list of types using php patterns for warning.
+    if (variable_get('auto_entity_title_php_node_' . $key)) {
+      $php_types[] = $value->name;
+    }
+  }
+
+  drupal_set_message(t('All settings from the <em>Automatic Entitylabels</em> module have been migrated to the entity titles module. You can disable the <em>Automatic Entitylabels</em> module now if you have it installed.'));
+  if (!empty($php_types)) {
+    $php_types = '<em>' . implode('</em>, <em>', $php_types) . '</em>';
+    drupal_set_message(t('Please check all title patterns which use PHP evaluation! Any patterns using the <code>$node</code> variable need to be updated to use the <code>$entity</code> variable instead. The following node types have php evaluation enabled at the moment: !types', array('!types' => filter_xss($php_types, array('em')))), 'warning');
+  }
+}
diff --git a/auto_entity_title.js b/auto_entity_title.js
new file mode 100644
index 0000000..6bf811e
--- /dev/null
+++ b/auto_entity_title.js
@@ -0,0 +1,23 @@
+(function ($) {
+
+Drupal.behaviors.autoEntityTitle = {
+  attach: function (context) {
+    $('fieldset#edit-auto-entity-title', context).drupalSetSummary(function (context) {
+
+      // Retrieve the value of the selected radio button
+      var ant = $("input[@name=#edit-auto-entity-title-ant]:checked").val();
+
+      if (ant==0) {
+        return Drupal.t('Disabled')
+      }
+      else if (ant==1) {
+        return Drupal.t('Automatic (hide title field)')
+      }
+      else if (ant==2) {
+        return Drupal.t('Automatic (if title empty)')
+      }
+    });
+  }
+};
+
+})(jQuery);
diff --git a/auto_entity_title.module b/auto_entity_title.module
new file mode 100644
index 0000000..f310105
--- /dev/null
+++ b/auto_entity_title.module
@@ -0,0 +1,398 @@
+<?php
+
+/**
+ * @file
+ * Allows hiding of entity title fields and automatic title creation.
+ */
+
+define('AUTO_ENTITY_TITLE_DISABLED', 0);
+define('AUTO_ENTITY_TITLE_ENABLED', 1);
+define('AUTO_ENTITY_TITLE_OPTIONAL', 2);
+
+/**
+ * Implements hook_permission().
+ */
+function auto_entity_title_permission() {
+  return array(
+    'use PHP for title patterns' => array(
+      'title' => t('Use PHP for title patterns'),
+      'description' => t('Use PHP evaluation for automatic entity title patterns.'),
+      'restrict access' => TRUE,
+    ),
+  );
+}
+
+/**
+ * Implements hook_menu().
+ */
+function auto_entity_title_menu() {
+  $items = array();
+  // This logic is taken from the field_ui module.
+  // Create tabs for all possible bundles.
+  foreach (entity_get_info() as $entity_type => $entity_info) {
+    if (isset($entity_info['entity keys']['label'])) {
+      foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
+        if (isset($bundle_info['admin'])) {
+          // Extract path information from the bundle.
+          $path = $bundle_info['admin']['path'];
+          // Different bundles can appear on the same path (e.g. %node_type and
+          // %comment_node_type). To allow field_ui_menu_load() to extract the
+          // actual bundle object from the translated menu router path
+          // arguments, we need to identify the argument position of the bundle
+          // name string ('bundle argument') and pass that position to the menu
+          // loader. The position needs to be casted into a string; otherwise it
+          // would be replaced with the bundle name string.
+          if (isset($bundle_info['admin']['bundle argument'])) {
+            $bundle_arg = $bundle_info['admin']['bundle argument'];
+          }
+          else {
+            $bundle_arg = $bundle_name;
+          }
+          // Extract access information, providing defaults.
+          $access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array('access callback', 'access arguments')));
+          $access += array(
+            'access callback' => 'user_access',
+            'access arguments' => array('administer site configuration'),
+          );
+
+          $items["$path/auto_title"] = array(
+            'title' => '@type Auto title',
+            'title arguments' => array('@type' => $entity_info['label']),
+            'page callback' => 'drupal_get_form',
+            'page arguments' => array('auto_entity_title_settings_form', $entity_type, $bundle_arg),
+            'type' => MENU_LOCAL_TASK,
+            'weight' => 10,
+            'file' => 'auto_entity_title.admin.inc',
+          ) + $access;
+        }
+      }
+    }
+  }
+  return $items;
+}
+
+/**
+ * Implements hook_form_alter().
+ */
+function auto_entity_title_form_alter(&$form, &$form_state, $form_id) {
+  if (isset($form['#entity_type']) && isset($form['#bundle'])) {
+    $info = entity_get_info($form['#entity_type']);
+    // Exit if there is no label field, e.g. users only have a "label callback"
+    if (!isset($info['entity keys']['label'])) return;
+    $key = $form['#entity_type'] . '_' . $form['#bundle'];
+    $title = $info['entity keys']['label'];
+    // Integration with the title module.
+    $replacement = FALSE;
+    if (module_exists('title') && (title_field_replacement_enabled($form['#entity_type'], $form['#bundle'], $title))) {
+      $title = $info['field replacement'][$title]['instance']['field_name'];
+      $replacement = TRUE;
+    }
+    if (auto_entity_title_get_setting($key) == AUTO_ENTITY_TITLE_ENABLED) {
+      // We will autogenerate the title later, just hide the title field in the
+      // meanwhile.
+      if ($replacement && isset($form[$title])) {
+        $form[$title][$form[$title]['#language']][0]['value']['#value'] = '%AutoEntityTitle%';
+        $form[$title][$form[$title]['#language']][0]['value']['#type'] = 'value';
+        $form[$title][$form[$title]['#language']][0]['value']['#required'] = FALSE;
+      }
+      else {
+        $form[$title]['#value'] = '%AutoEntityTitle%';
+        $form[$title]['#type'] = 'value';
+        $form[$title]['#required'] = FALSE;
+      }
+    }
+    elseif (auto_entity_title_get_setting($key) == AUTO_ENTITY_TITLE_OPTIONAL) {
+      if ($replacement) {
+        $form[$title][$form[$title]['#language']][0]['value']['#required'] = FALSE;
+      }
+      else {
+        $form[$title]['#required'] = FALSE;
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_entity_presave().
+ */
+function auto_entity_title_entity_presave($entity, $type) {
+  if (auto_entity_title_is_needed($entity, $type)) {
+    $settings = _auto_entity_title_get_settings($entity, $type);
+    $setting = auto_entity_title_get_setting($settings['key']);
+    if ($setting == AUTO_ENTITY_TITLE_ENABLED || ($setting == AUTO_ENTITY_TITLE_OPTIONAL && empty($entity->{$settings['title']}))) {
+      auto_entity_title_set_title($entity, $type);
+    }
+  }
+}
+
+/**
+ * Implements hook_field_attach_presave().
+ *
+ * Required for compatibility with entity_translation module, which does not
+ * invoke hook_entity_presave() when saving new translations.
+ */
+function auto_entity_title_field_attach_presave($entity_type, $entity) {
+  auto_entity_title_entity_presave($entity, $entity_type);
+}
+
+/**
+ * Returns whether the auto entity title has to be set.
+ */
+function auto_entity_title_is_needed($entity, $entity_type) {
+  $settings = _auto_entity_title_get_settings($entity, $entity_type);
+  return empty($entity->auto_entity_title_applied) && ($setting = auto_entity_title_get_setting($settings['key'])) && !($setting == AUTO_ENTITY_TITLE_OPTIONAL && !empty($entity->{$settings['title']}));
+}
+
+/**
+ * Sets the automatically generated entity title for the entity.
+ */
+function auto_entity_title_set_title(&$entity, $type) {
+  $settings = _auto_entity_title_get_settings($entity, $type);
+
+  // Generate title in different languages?
+  $multilingual = FALSE;
+
+  // Support for title module
+  $entity_info = entity_get_info($type);
+  list(, , $bundle) = entity_extract_ids($type, $entity);
+  $title_field_name = FALSE;
+  $title_languages = array();
+  if (module_exists('title') && (title_field_replacement_enabled($type, $bundle, $settings['title']))) {
+    $title_field_name = $entity_info['field replacement'][$settings['title']]['instance']['field_name'];
+    $title_languages = field_available_languages($type, $title_field_name);
+    $multilingual = count($title_languages) > 1;
+  }
+
+  // Remove LANGUAGE_NONE from array of languages
+  if (($key = array_search(LANGUAGE_NONE, $title_languages, TRUE)) && auto_entity_title_entity_language($type, $entity) !== LANGUAGE_NONE) {
+    unset($title_languages[$key]);
+  }
+
+  // Generate titles
+  $titles = array();
+  $pattern = variable_get('auto_entity_title_pattern_' . $settings['key'], '');
+  if (trim($pattern)) {
+    $entity->changed = REQUEST_TIME;
+    if ($multilingual) {
+      foreach ($title_languages as $language) {
+        $titles[$language] = _auto_entity_title_patternprocessor($pattern, $entity, $type, $language);
+      }
+    }
+    else {
+      $titles[LANGUAGE_NONE] = _auto_entity_title_patternprocessor($pattern, $entity, $type);
+    }
+  }
+  elseif ($type == 'node' && $entity->nid) {
+    $titles[LANGUAGE_NONE] = t('@bundle @node-id', array('@bundle' => $bundle, '@node-id' => $entity->nid));
+  }
+  else {
+    $titles[LANGUAGE_NONE] = t('@bundle', array('@bundle' => $bundle));
+  }
+
+  // Ensure the generated title isn't too long.
+  $max_length = auto_entity_title_max_length($type, $settings['title']);
+  foreach ($titles as $k => $v) {
+    $titles[$k] = drupal_substr($v, 0, $max_length);
+  }
+
+  // Save titles on entity (field)
+  if (module_exists('title') && (title_field_replacement_enabled($type, $bundle, $settings['title']))) {
+    foreach ($titles as $lang => $title) {
+      $entity->{$title_field_name}[$lang][0]['format'] = NULL;
+      $entity->{$title_field_name}[$lang][0]['safe_value'] = check_plain($title);
+      $entity->{$title_field_name}[$lang][0]['value'] = $title;
+    }
+  }
+
+  // Save title on entity (non-field).  This needs be done even if field_title
+  // above is updated, because the title module automatically syncs changes
+  // from the "non field title" to the "title field". Without this line we end
+  // up getting "%AutoEntityTitle%" as the title.
+  $entity_language = auto_entity_title_entity_language($type, $entity);
+  $entity->{$settings['title']} = isset($titles[$entity_language]) ? $titles[$entity_language] : $titles[LANGUAGE_NONE];
+
+  // With that flag we ensure we don't apply the title two times to the same
+  // node. See auto_entity_title_is_needed().
+  $entity->auto_entity_title_applied = TRUE;
+}
+
+/**
+ * Implements hook_node_operations().
+ */
+function auto_entity_title_node_operations() {
+  $operations = array(
+    'entity_title_update' => array(
+      'label' => t('Update automatic nodetitles'),
+      'callback' => 'auto_entity_title_operations_update',
+    ),
+  );
+  return $operations;
+}
+
+/**
+ * Callback function for updating node titles.
+ */
+function auto_entity_title_operations_update($nodes) {
+  foreach ($nodes as $nid) {
+    $node = node_load($nid);
+    if ($node && auto_entity_title_is_needed($node, 'node')) {
+      $previous_title = $node->title;
+      auto_entity_title_set_title($node, 'node');
+      // Only save if the title has actually changed.
+      if ($node->title != $previous_title) {
+        node_save($node);
+      }
+    }
+  }
+}
+
+/**
+  * Helper function to generate the title according to the settings.
+  *
+  * @return
+  *   A title string
+  */
+function _auto_entity_title_patternprocessor($pattern, $entity, $entity_type, $language = LANGUAGE_NONE) {
+  // Replace tokens.
+  $info = entity_get_info($entity_type);
+  $languages = language_list();
+  $language_obj = $language == LANGUAGE_NONE ? NULL : $languages[$language];
+  $token_data = isset($info['token type']) ? array($info['token type'] => $entity) : array();
+  $output = token_replace($pattern, $token_data, array('sanitize' => FALSE, 'clear' => TRUE, 'language' => $language_obj));
+
+  // Evalute PHP.
+  $settings = _auto_entity_title_get_settings($entity, $entity_type);
+  if (variable_get('auto_entity_title_php_' . $settings['key'], 0)) {
+    $output = auto_entity_title_eval($output, $entity, $language);
+  }
+  // Strip tags.
+  $output = preg_replace('/[\t\n\r\0\x0B]/', '', strip_tags($output));
+  return $output;
+}
+
+/**
+ * Gets the auto node title setting associated with the given content type.
+ */
+function auto_entity_title_get_setting($type) {
+  return variable_get('auto_entity_title_' . $type, AUTO_ENTITY_TITLE_DISABLED);
+}
+
+/**
+ * Evaluates php code and passes $node to it.
+ */
+function auto_entity_title_eval($code, $entity, $language = LANGUAGE_NONE) {
+  ob_start();
+  print eval('?>' . $code);
+  $output = ob_get_contents();
+  ob_end_clean();
+  return $output;
+}
+
+/**
+ * Implements hook_field_attach_delete_bundle().
+ */
+function auto_entity_title_field_attach_delete_bundle($entity_type, $bundle, $instances) {
+  static $variables = array(
+    'auto_entity_title',
+    'auto_entity_title_pattern',
+    'auto_entity_title_php',
+  );
+  foreach ($variables as $variable) {
+    variable_del($variable . '_' . $entity_type . '_' . $bundle);
+  }
+}
+
+/**
+ * Implements hook_field_attach_rename_bundle().
+ */
+function auto_entity_title_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
+  static $variables = array(
+    'auto_entity_title',
+    'auto_entity_title_pattern',
+    'auto_entity_title_php',
+  );
+  if ($bundle_old !== $bundle_new) {
+    foreach ($variables as $variable) {
+      $key_old = $variable . '_' . $entity_type . '_' . $bundle_old;
+      $key_new = $variable . '_' . $entity_type . '_' . $bundle_new;
+      variable_set($key_new, variable_get($key_old, ''));
+      variable_del($key_old);
+    }
+  }
+}
+
+function _auto_entity_title_get_settings($entity, $entity_type) {
+  $entity_info = entity_get_info($entity_type);
+  if ($entity_info['entity keys']['bundle']) {
+    $result['key'] = $entity_type . '_' . $entity->{$entity_info['entity keys']['bundle']};
+    $result['title'] = isset($entity_info['entity keys']['label']) ? $entity_info['entity keys']['label']: 'none';
+    return $result;
+  }
+  return FALSE;
+}
+
+/**
+ * Implements hook_features_pipe_node_alter().
+ *
+ * Adds auto_entity_title_* variables when exporting node types to features.
+ *
+ * @todo
+ *   Generalize for other entity types.
+ */
+function auto_entity_title_features_pipe_node_alter(&$pipe, $data, $export) {
+  if (!empty($data)) {
+    $variables = array(
+      'auto_entity_title_node',
+      'auto_entity_title_pattern_node',
+      'auto_entity_title_php_node',
+    );
+    foreach ($data as $node_type) {
+      foreach ($variables as $variable_name) {
+        $pipe['variable'][] = "{$variable_name}_{$node_type}";
+      }
+    }
+  }
+}
+
+/**
+ * Tries to extract the maximum length for the given property from the
+ * respective database schema field.
+ *
+ * Assumes that the the schema field is named identical to the property.
+ */
+function auto_entity_title_max_length($entity_type, $property_name) {
+  // Load entity and schema info.
+  $entity_info = entity_get_info($entity_type);
+  $schema = drupal_get_schema($entity_info['base table']);
+
+  // Return 'length' from schema field as maximum length, fall back to 255.
+  return isset($schema['fields'][$property_name]['length']) ? $schema['fields'][$property_name]['length'] : 255;
+}
+
+/**
+ * Returns the language code of the given entity.
+ *
+ * Backward compatibility layer to ensure that installations running an older
+ * version of core where entity_language() is not available do not break.
+ *
+ * @param string $entity_type
+ *   An entity type.
+ * @param object $entity
+ *   An entity object.
+ * @param bool $check_language_property
+ *   A boolean if TRUE, will attempt to fetch the language code from
+ *   $entity->language if the entity_language() function failed or does not
+ *   exist. Default is TRUE.
+ */
+function auto_entity_title_entity_language($entity_type, $entity, $check_language_property = TRUE) {
+  $langcode = NULL;
+
+  if (function_exists('entity_language')) {
+    $langcode = entity_language($entity_type, $entity);
+  }
+  elseif ($check_language_property && !empty($entity->language)) {
+    $langcode = $entity->language;
+  }
+
+  return !empty($langcode) ? $langcode : LANGUAGE_NONE;
+}
diff --git a/auto_entitylabel.admin.inc b/auto_entitylabel.admin.inc
deleted file mode 100644
index 056bbc8..0000000
--- a/auto_entitylabel.admin.inc
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-
-/**
- * @file
- *   Contains administration forms.
- */
-
-/**
- * Administration form for each bundle.
- */
-function auto_entitylabel_settings_form($form, $form_state, $entity_type, $bundle_arg) {
-  $info = entity_get_info($entity_type);
-  $bundle_name = is_object($bundle_arg) ? $bundle_arg->{$info['bundle keys']['bundle']} : $bundle_arg;
-  $bundle_label = $info['bundles'][$bundle_name]['label'];
-  $key = $entity_type . '_' . $bundle_name;
-  $default_value = auto_entitylabel_get_setting($key);
-  $form['auto_entitylabel'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Automatic label generation for @type', array('@type' => $bundle_label)),
-    '#weight' => 0,
-    /* '#attached' => array( // Not needed anymore at the moment.
-      'js' => array(
-        'auto-entitylabel' => drupal_get_path('module', 'auto_entitylabel') . '/auto_entitylabel.js',
-      ),
-    ),*/
-  );
-  $form['auto_entitylabel']['auto_entitylabel_' . $key] = array(
-    '#type' => 'radios',
-    '#default_value' => $default_value,
-    '#options' => _auto_entitylabel_options($entity_type, $bundle_name),
-  );
-  $form['auto_entitylabel']['auto_entitylabel_pattern_' . $key] = array(
-    '#type' => 'textarea',
-    '#title' => t('Pattern for the title'),
-    '#description' => t('Leave blank for using the per default generated title. Otherwise this string will be used as title. Use the syntax [token] if you want to insert a replacement pattern.'),
-    '#default_value' => variable_get('auto_entitylabel_pattern_' . $key, ''),
-  );
-  // Don't allow editing of the pattern if PHP is used, but the users lacks
-  // permission for PHP.
-  if (variable_get('auto_entitylabel_php_' . $key, '') && !user_access('use PHP for label patterns')) {
-    $form['auto_entitylabel']['auto_entitylabel_pattern_' . $key]['#disabled'] = TRUE;
-    $form['auto_entitylabel']['auto_entitylabel_pattern_' . $key]['#description'] = t('You are not allow the configure the pattern for the title, as you lack the %permission permission.', array('%permission' => t('Use PHP for title patterns')));
-  }
-  // Display the list of available placeholders if token module is installed.
-  if (module_exists('token')) {
-    $form['auto_entitylabel']['token_help'] = array(
-      '#theme' => 'token_tree',
-      '#token_types' => array($info['token type']),
-    );
-  }
-
-  $form['auto_entitylabel']['auto_entitylabel_php_' . $key] = array(
-    '#access' => user_access('use PHP for label patterns'),
-    '#type' => 'checkbox',
-    '#title' => t('Evaluate PHP in pattern.'),
-    '#description' => t('Put PHP code above that returns your string, but make sure you surround code in <code>&lt;?php</code> and <code>?&gt;</code>. Note that <code>$entity</code> and <code>$language</code> are available and can be used by your code.'),
-    '#default_value' => variable_get('auto_entitylabel_php_' . $key, ''),
-  );
-  return system_settings_form($form);
-}
-
-/**
- * Constructs the list of options for the given bundle.
- */
-function _auto_entitylabel_options($entity_type, $bundle_name) {
-  $options = array(
-    AUTO_ENTITYLABEL_DISABLED => t('Disabled'),
-  );
-  if (auto_entitylabel_entity_label_visible($entity_type, $bundle_name)) {
-    $options += array(
-      AUTO_ENTITYLABEL_ENABLED => t('Automatically generate the label and hide the label field'),
-      AUTO_ENTITYLABEL_OPTIONAL => t('Automatically generate the label if the label field is left empty'),
-    );
-  }
-  else {
-    $options += array(
-      AUTO_ENTITYLABEL_ENABLED => t('Automatically generate the label'),
-    );
-  }
-  return $options;
-}
-
-/**
- * Check if given entity bundle has a visible label on the entity form.
- *
- * @param $entity_type
- *   The entity type.
- * @param $bundle_name
- *   The name of the bundle.
- *
- * @return
- *   TRUE if the label is rendered in the entity form, FALSE otherwise.
- *
- * @todo
- *   Find a generic way of determining the result of this function. This
- *   will probably require access to more information about entity forms
- *   (entity api module?).
- */
-function auto_entitylabel_entity_label_visible($entity_type, $bundle_name) {
-  $hidden = array(
-    'profile2' => TRUE,
-  );
-  
-  return empty($hidden[$entity_type]);
-}
diff --git a/auto_entitylabel.info b/auto_entitylabel.info
deleted file mode 100644
index 46bc855..0000000
--- a/auto_entitylabel.info
+++ /dev/null
@@ -1,3 +0,0 @@
-name = Automatic Entity Labels
-description = Allows hiding of entity label fields and automatic label creation.
-core = 7.x
diff --git a/auto_entitylabel.install b/auto_entitylabel.install
deleted file mode 100644
index 7f4db78..0000000
--- a/auto_entitylabel.install
+++ /dev/null
@@ -1,102 +0,0 @@
-<?php
-
-/**
- * @file
- * Installation file for the automatic entity labels module
- */
-
-/**
- * Implements hook_install().
- */
-function auto_entitylabel_install() {
-  // Make sure hooks are invoked after cck main hooks.
-  db_query("UPDATE {system} SET weight = 5 WHERE name = 'auto_entitylabel'");
-
-  // Migrate settings (permission+variable) from the auto_nodetitle module.
-  _auto_entitylabel_ant_migrate();
-
-  // Notify the user they may want to install token.
-  if (!module_exists('token')) {
-    $t = get_t();
-    drupal_set_message($t('If you install the <a href="!url">Token module</a>, Automatic Entity Label will be able to use token patterns.', array('!url' => 'http://drupal.org/project/token')));
-  }
-}
-
-/**
- * Implements hook_uninstall().
- */
-function auto_entitylabel_uninstall() {
-  static $variables = array(
-    'auto_entitylabel',
-    'auto_entitylabel_pattern',
-    'auto_entitylabel_php',
-  );
-
-  foreach (entity_get_info() as $entity_type => $entity_info) {
-    foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
-      foreach ($variables as $variable) {
-        variable_del($variable . '_' . $entity_type . '_' . $bundle_name);
-      }
-    }
-  }
-}
-
-/**
- * Migrate settings from the automatic nodetitle module.
- */
-function _auto_entitylabel_ant_migrate() {
-  // Grant the entitylabel permission to all roles which had the nodetitle one.
-  $roles = user_roles(TRUE, 'use PHP for title patterns');
-  foreach ($roles as $rid => $role) {
-    user_role_grant_permissions($rid, array('use PHP for label patterns'));
-  }
-
-  // Stop migration if no ant_* variables exist.
-  $ant_variables_exist = db_select('variable', 'v')->fields('v', array('name'))->condition('name', 'ant_%', 'LIKE')->execute()->rowCount();
-  if (!$ant_variables_exist) {
-    return;
-  }
-
-  $types = node_type_get_types();
-  $php_types = array();
-  foreach ($types as $key => $value) {
-    // Import auto_nodetitle variables (ant_*)
-    if (variable_get('ant_' . $key)) {
-      variable_set('auto_entitylabel_node_' . $key, variable_get('ant_' . $key));
-    }
-    if (variable_get('ant_pattern_' . $key)) {
-      variable_set('auto_entitylabel_pattern_node_' . $key, variable_get('ant_pattern_' . $key));
-    }
-    if (variable_get('ant_php_' . $key)) {
-      variable_set('auto_entitylabel_php_node_' . $key, variable_get('ant_php_' . $key));
-    }
-    variable_del('ant_' . $key);
-    variable_del('ant_php_' . $key);
-    variable_del('ant_pattern_' . $key);
-
-    // Import variables from vasi1186's intial entitylabel patch (see #1124484)
-    if (variable_get('ant_node_' . $key)) {
-      variable_set('auto_entitylabel_node_' . $key, variable_get('ant_node_' . $key));
-    }
-    if (variable_get('ant_pattern_node_' . $key)) {
-      variable_set('auto_entitylabel_pattern_node_' . $key, variable_get('ant_pattern_node_' . $key));
-    }
-    if (variable_get('ant_php_node_' . $key)) {
-      variable_set('auto_entitylabel_php_node_' . $key, variable_get('ant_php_node_' . $key));
-    }
-    variable_del('ant_node_' . $key);
-    variable_del('ant_php_node_' . $key);
-    variable_del('ant_pattern_node_' . $key);
-
-    // Create list of types using php patterns for warning.
-    if (variable_get('auto_entitylabel_php_node_' . $key)) {
-      $php_types[] = $value->name;
-    }
-  }
-
-  drupal_set_message(t('All settings from the <em>Automatic Nodetitles</em> module have been migrated to the entity labels module. You can disable the <em>Automatic Nodetitles</em> module now if you have it installed.'));
-  if (!empty($php_types)) {
-    $php_types = '<em>' . implode('</em>, <em>', $php_types) . '</em>';
-    drupal_set_message(t('Please check all title patterns which use PHP evaluation! Any patterns using the <code>$node</code> variable need to be updated to use the <code>$entity</code> variable instead. The following node types have php evaluation enabled at the moment: !types', array('!types' => filter_xss($php_types, array('em')))), 'warning');
-  }
-}
diff --git a/auto_entitylabel.js b/auto_entitylabel.js
deleted file mode 100644
index 52fd6d9..0000000
--- a/auto_entitylabel.js
+++ /dev/null
@@ -1,23 +0,0 @@
-(function ($) {
-
-Drupal.behaviors.auto_entitylabelFieldsetSummaries = {
-  attach: function (context) {
-    $('fieldset#edit-auto-entitylabel', context).drupalSetSummary(function (context) {
-
-      // Retrieve the value of the selected radio button
-      var ant = $("input[@name=#edit-auto-entitylabel-ant]:checked").val();
-
-      if (ant==0) {
-        return Drupal.t('Disabled')
-      }
-      else if (ant==1) {
-        return Drupal.t('Automatic (hide title field)')
-      }
-      else if (ant==2) {
-        return Drupal.t('Automatic (if title empty)')
-      }
-    });
-  }
-};
-
-})(jQuery);
diff --git a/auto_entitylabel.module b/auto_entitylabel.module
deleted file mode 100644
index 52b54e4..0000000
--- a/auto_entitylabel.module
+++ /dev/null
@@ -1,398 +0,0 @@
-<?php
-
-/**
- * @file
- * Allows hiding of entity label fields and automatic label creation.
- */
-
-define('AUTO_ENTITYLABEL_DISABLED', 0);
-define('AUTO_ENTITYLABEL_ENABLED', 1);
-define('AUTO_ENTITYLABEL_OPTIONAL', 2);
-
-/**
- * Implements hook_permission().
- */
-function auto_entitylabel_permission() {
-  return array(
-    'use PHP for label patterns' => array(
-      'title' => t('Use PHP for label patterns'),
-      'description' => t('Use PHP evaluation for automatic entity label patterns.'),
-      'restrict access' => TRUE,
-    ),
-  );
-}
-
-/**
- * Implements hook_menu().
- */
-function auto_entitylabel_menu() {
-  $items = array();
-  // This logic is taken from the field_ui module.
-  // Create tabs for all possible bundles.
-  foreach (entity_get_info() as $entity_type => $entity_info) {
-    if (isset($entity_info['entity keys']['label'])) {
-      foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
-        if (isset($bundle_info['admin'])) {
-          // Extract path information from the bundle.
-          $path = $bundle_info['admin']['path'];
-          // Different bundles can appear on the same path (e.g. %node_type and
-          // %comment_node_type). To allow field_ui_menu_load() to extract the
-          // actual bundle object from the translated menu router path
-          // arguments, we need to identify the argument position of the bundle
-          // name string ('bundle argument') and pass that position to the menu
-          // loader. The position needs to be casted into a string; otherwise it
-          // would be replaced with the bundle name string.
-          if (isset($bundle_info['admin']['bundle argument'])) {
-            $bundle_arg = $bundle_info['admin']['bundle argument'];
-          }
-          else {
-            $bundle_arg = $bundle_name;
-          }
-          // Extract access information, providing defaults.
-          $access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array('access callback', 'access arguments')));
-          $access += array(
-            'access callback' => 'user_access',
-            'access arguments' => array('administer site configuration'),
-          );
-
-          $items["$path/auto_label"] = array(
-            'title' => '@type Auto label',
-            'title arguments' => array('@type' => $entity_info['label']),
-            'page callback' => 'drupal_get_form',
-            'page arguments' => array('auto_entitylabel_settings_form', $entity_type, $bundle_arg),
-            'type' => MENU_LOCAL_TASK,
-            'weight' => 10,
-            'file' => 'auto_entitylabel.admin.inc',
-          ) + $access;
-        }
-      }
-    }
-  }
-  return $items;
-}
-
-/**
- * Implements hook_form_alter().
- */
-function auto_entitylabel_form_alter(&$form, &$form_state, $form_id) {
-  if (isset($form['#entity_type']) && isset($form['#bundle'])) {
-    $info = entity_get_info($form['#entity_type']);
-    // Exit if there is no label field, e.g. users only have a "label callback"
-    if (!isset($info['entity keys']['label'])) return;
-    $key = $form['#entity_type'] . '_' . $form['#bundle'];
-    $title = $info['entity keys']['label'];
-    // Integration with the title module.
-    $replacement = FALSE;
-    if (module_exists('title') && (title_field_replacement_enabled($form['#entity_type'], $form['#bundle'], $title))) {
-      $title = $info['field replacement'][$title]['instance']['field_name'];
-      $replacement = TRUE;
-    }
-    if (auto_entitylabel_get_setting($key) == AUTO_ENTITYLABEL_ENABLED) {
-      // We will autogenerate the title later, just hide the title field in the
-      // meanwhile.
-      if ($replacement && isset($form[$title])) {
-        $form[$title][$form[$title]['#language']][0]['value']['#value'] = '%AutoEntityLabel%';
-        $form[$title][$form[$title]['#language']][0]['value']['#type'] = 'value';
-        $form[$title][$form[$title]['#language']][0]['value']['#required'] = FALSE;
-      }
-      else {
-        $form[$title]['#value'] = '%AutoEntityLabel%';
-        $form[$title]['#type'] = 'value';
-        $form[$title]['#required'] = FALSE;
-      }
-    }
-    elseif (auto_entitylabel_get_setting($key) == AUTO_ENTITYLABEL_OPTIONAL) {
-      if ($replacement) {
-        $form[$title][$form[$title]['#language']][0]['value']['#required'] = FALSE;
-      }
-      else {
-        $form[$title]['#required'] = FALSE;
-      }
-    }
-  }
-}
-
-/**
- * Implements hook_entity_presave().
- */
-function auto_entitylabel_entity_presave($entity, $type) {
-  if (auto_entitylabel_is_needed($entity, $type)) {
-    $settings = _auto_entitylabel_get_settings($entity, $type);
-    $setting = auto_entitylabel_get_setting($settings['key']);
-    if ($setting == AUTO_ENTITYLABEL_ENABLED || ($setting == AUTO_ENTITYLABEL_OPTIONAL && empty($entity->{$settings['title']}))) {
-      auto_entitylabel_set_title($entity, $type);
-    }
-  }
-}
-
-/**
- * Implements hook_field_attach_presave().
- *
- * Required for compatibility with entity_translation module, which does not
- * invoke hook_entity_presave() when saving new translations.
- */
-function auto_entitylabel_field_attach_presave($entity_type, $entity) {
-  auto_entitylabel_entity_presave($entity, $entity_type);
-}
-
-/**
- * Returns whether the auto entitylabel has to be set.
- */
-function auto_entitylabel_is_needed($entity, $entity_type) {
-  $settings = _auto_entitylabel_get_settings($entity, $entity_type);
-  return empty($entity->auto_entitylabel_applied) && ($setting = auto_entitylabel_get_setting($settings['key'])) && !($setting == AUTO_ENTITYLABEL_OPTIONAL && !empty($entity->{$settings['title']}));
-}
-
-/**
- * Sets the automatically generated entitylabel for the entity.
- */
-function auto_entitylabel_set_title(&$entity, $type) {
-  $settings = _auto_entitylabel_get_settings($entity, $type);
-
-  // Generate title in different languages?
-  $multilingual = FALSE;
-
-  // Support for title module
-  $entity_info = entity_get_info($type);
-  list(, , $bundle) = entity_extract_ids($type, $entity);
-  $title_field_name = FALSE;
-  $title_languages = array();
-  if (module_exists('title') && (title_field_replacement_enabled($type, $bundle, $settings['title']))) {
-    $title_field_name = $entity_info['field replacement'][$settings['title']]['instance']['field_name'];
-    $title_languages = field_available_languages($type, $title_field_name);
-    $multilingual = count($title_languages) > 1;
-  }
-
-  // Remove LANGUAGE_NONE from array of languages
-  if (($key = array_search(LANGUAGE_NONE, $title_languages, TRUE)) && auto_entitylabel_entity_language($type, $entity) !== LANGUAGE_NONE) {
-    unset($title_languages[$key]);
-  }
-
-  // Generate titles
-  $titles = array();
-  $pattern = variable_get('auto_entitylabel_pattern_' . $settings['key'], '');
-  if (trim($pattern)) {
-    $entity->changed = REQUEST_TIME;
-    if ($multilingual) {
-      foreach ($title_languages as $language) {
-        $titles[$language] = _auto_entitylabel_patternprocessor($pattern, $entity, $type, $language);
-      }
-    }
-    else {
-      $titles[LANGUAGE_NONE] = _auto_entitylabel_patternprocessor($pattern, $entity, $type);
-    }
-  }
-  elseif ($type == 'node' && $entity->nid) {
-    $titles[LANGUAGE_NONE] = t('@bundle @node-id', array('@bundle' => $bundle, '@node-id' => $entity->nid));
-  }
-  else {
-    $titles[LANGUAGE_NONE] = t('@bundle', array('@bundle' => $bundle));
-  }
-
-  // Ensure the generated title isn't too long.
-  $max_length = auto_entitylabel_max_length($type, $settings['title']);
-  foreach ($titles as $k => $v) {
-    $titles[$k] = drupal_substr($v, 0, $max_length);
-  }
-
-  // Save titles on entity (field)
-  if (module_exists('title') && (title_field_replacement_enabled($type, $bundle, $settings['title']))) {
-    foreach ($titles as $lang => $title) {
-      $entity->{$title_field_name}[$lang][0]['format'] = NULL;
-      $entity->{$title_field_name}[$lang][0]['safe_value'] = check_plain($title);
-      $entity->{$title_field_name}[$lang][0]['value'] = $title;
-    }
-  }
-
-  // Save title on entity (non-field).  This needs be done even if field_title
-  // above is updated, because the title module automatically syncs changes
-  // from the "non field title" to the "title field". Without this line we end
-  // up getting "%AutoEntityLabel%" as the title.
-  $entity_language = auto_entitylabel_entity_language($type, $entity);
-  $entity->{$settings['title']} = isset($titles[$entity_language]) ? $titles[$entity_language] : $titles[LANGUAGE_NONE];
-
-  // With that flag we ensure we don't apply the title two times to the same
-  // node. See auto_entitylabel_is_needed().
-  $entity->auto_entitylabel_applied = TRUE;
-}
-
-/**
- * Implements hook_node_operations().
- */
-function auto_entitylabel_node_operations() {
-  $operations = array(
-    'entitylabel_update' => array(
-      'label' => t('Update automatic nodetitles'),
-      'callback' => 'auto_entitylabel_operations_update',
-    ),
-  );
-  return $operations;
-}
-
-/**
- * Callback function for updating node titles.
- */
-function auto_entitylabel_operations_update($nodes) {
-  foreach ($nodes as $nid) {
-    $node = node_load($nid);
-    if ($node && auto_entitylabel_is_needed($node, 'node')) {
-      $previous_title = $node->title;
-      auto_entitylabel_set_title($node, 'node');
-      // Only save if the title has actually changed.
-      if ($node->title != $previous_title) {
-        node_save($node);
-      }
-    }
-  }
-}
-
-/**
-  * Helper function to generate the title according to the settings.
-  *
-  * @return
-  *   A title string
-  */
-function _auto_entitylabel_patternprocessor($pattern, $entity, $entity_type, $language = LANGUAGE_NONE) { 
-  // Replace tokens.
-  $info = entity_get_info($entity_type);
-  $languages = language_list();
-  $language_obj = $language == LANGUAGE_NONE ? NULL : $languages[$language];
-  $token_data = isset($info['token type']) ? array($info['token type'] => $entity) : array();
-  $output = token_replace($pattern, $token_data, array('sanitize' => FALSE, 'clear' => TRUE, 'language' => $language_obj));
-
-  // Evalute PHP.
-  $settings = _auto_entitylabel_get_settings($entity, $entity_type);
-  if (variable_get('auto_entitylabel_php_' . $settings['key'], 0)) {
-    $output = auto_entitylabel_eval($output, $entity, $language);
-  }
-  // Strip tags.
-  $output = preg_replace('/[\t\n\r\0\x0B]/', '', strip_tags($output));
-  return $output;
-}
-
-/**
- * Gets the auto node title setting associated with the given content type.
- */
-function auto_entitylabel_get_setting($type) {
-  return variable_get('auto_entitylabel_' . $type, AUTO_ENTITYLABEL_DISABLED);
-}
-
-/**
- * Evaluates php code and passes $node to it.
- */
-function auto_entitylabel_eval($code, $entity, $language = LANGUAGE_NONE) {
-  ob_start();
-  print eval('?>' . $code);
-  $output = ob_get_contents();
-  ob_end_clean();
-  return $output;
-}
-
-/**
- * Implements hook_field_attach_delete_bundle().
- */
-function auto_entitylabel_field_attach_delete_bundle($entity_type, $bundle, $instances) {
-  static $variables = array(
-    'auto_entitylabel',
-    'auto_entitylabel_pattern',
-    'auto_entitylabel_php',
-  );
-  foreach ($variables as $variable) {
-    variable_del($variable . '_' . $entity_type . '_' . $bundle);
-  }
-}
-
-/** 
- * Implements hook_field_attach_rename_bundle().
- */
-function auto_entitylabel_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
-  static $variables = array(
-    'auto_entitylabel',
-    'auto_entitylabel_pattern',
-    'auto_entitylabel_php',
-  );
-  if ($bundle_old !== $bundle_new) {
-    foreach ($variables as $variable) {
-      $key_old = $variable . '_' . $entity_type . '_' . $bundle_old;
-      $key_new = $variable . '_' . $entity_type . '_' . $bundle_new;
-      variable_set($key_new, variable_get($key_old, ''));
-      variable_del($key_old);
-    }
-  }
-}
-
-function _auto_entitylabel_get_settings($entity, $entity_type) {
-  $entity_info = entity_get_info($entity_type);
-  if ($entity_info['entity keys']['bundle']) {
-    $result['key'] = $entity_type . '_' . $entity->{$entity_info['entity keys']['bundle']};
-    $result['title'] = isset($entity_info['entity keys']['label']) ? $entity_info['entity keys']['label']: 'none';
-    return $result;
-  }
-  return FALSE;
-}
-
-/**
- * Implements hook_features_pipe_node_alter().
- *
- * Adds auto_entitylabel_* variables when exporting node types to features.
- *
- * @todo
- *   Generalize for other entity types.
- */
-function auto_entitylabel_features_pipe_node_alter(&$pipe, $data, $export) {
-  if (!empty($data)) {
-    $variables = array(
-      'auto_entitylabel_node',
-      'auto_entitylabel_pattern_node',
-      'auto_entitylabel_php_node',
-    );
-    foreach ($data as $node_type) {
-      foreach ($variables as $variable_name) {
-        $pipe['variable'][] = "{$variable_name}_{$node_type}";
-      }
-    }
-  }
-}
-
-/**
- * Tries to extract the maximum length for the given property from the
- * respective database schema field.
- *
- * Assumes that the the schema field is named identical to the property.
- */
-function auto_entitylabel_max_length($entity_type, $property_name) {
-  // Load entity and schema info.
-  $entity_info = entity_get_info($entity_type);
-  $schema = drupal_get_schema($entity_info['base table']);
-
-  // Return 'length' from schema field as maximum length, fall back to 255.
-  return isset($schema['fields'][$property_name]['length']) ? $schema['fields'][$property_name]['length'] : 255;
-}
-
-/**
- * Returns the language code of the given entity.
- *
- * Backward compatibility layer to ensure that installations running an older
- * version of core where entity_language() is not available do not break.
- *
- * @param string $entity_type
- *   An entity type.
- * @param object $entity
- *   An entity object.
- * @param bool $check_language_property
- *   A boolean if TRUE, will attempt to fetch the language code from
- *   $entity->language if the entity_language() function failed or does not
- *   exist. Default is TRUE.
- */
-function auto_entitylabel_entity_language($entity_type, $entity, $check_language_property = TRUE) {
-  $langcode = NULL;
-
-  if (function_exists('entity_language')) {
-    $langcode = entity_language($entity_type, $entity);
-  }
-  elseif ($check_language_property && !empty($entity->language)) {
-    $langcode = $entity->language;
-  }
-
-  return !empty($langcode) ? $langcode : LANGUAGE_NONE;
-}
