You are here

function _auto_entitylabel_patternprocessor in Automatic Entity Label 7

Helper function to generate the title according to the settings.

Return value

output A title string

1 call to _auto_entitylabel_patternprocessor()
auto_entitylabel_set_title in ./auto_entitylabel.module
Sets the automatically generated entitylabel for the entity.

File

./auto_entitylabel.module, line 416
Allows hiding of entity label fields and automatic label creation.

Code

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(
    'callback' => '_auto_entitylabel_nohtmlentities',
    '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.
  if ($entity_type && $entity) {
    list(, , $bundle_name) = entity_extract_ids($entity_type, $entity);
    $strip_tags = variable_get('auto_entitylabel_strip_' . $entity_type . '_' . $bundle_name, 1);
    if ($strip_tags) {
      $output = preg_replace('/[\\t\\n\\r\\0\\x0B]/', '', strip_tags($output));
    }
  }
  return $output;
}