tableau-mkt-archived / entity_xliff

Drupal module that provides an API for entity serialization in the XLIFF format.
https://drupal.org/project/entity_xliff
2 stars 0 forks source link

Add the ability to alter translatable fields #53

Closed iamEAP closed 9 years ago

iamEAP commented 9 years ago

Introduces a new alter hook: hook_entity_xliff_translatable_fields_alter(), with the following signature:

/**
 * Alter translatable fields for a given entity. Useful for removing or adding
 * entity fields and properties to the generated XLIFF.
 *
 * @param array $fields
 *   An array of field or property names that represent translatable data.
 *   Note: the array keys are meaningless and can change at any time,
 *   You may need to use array_search() to find a specific value.
 *
 * @param \EntityDrupalwrapper $wrapper
 *   An entity metadata wrapper for the entity in question, useful for
 *   context.  For examplee, you may wish to conditionally alter
 *   translatable fields by entity type via $wrapper->type() or entity bundle
 *   via $wrapper->getBundle().
 */
function hook_entity_xliff_translatable_fields_alter(&$fields, $wrapper) {
  if ($wrapper->type() === 'my_entity_type') {
    $key = array_search('my_untranslatable_field', $fields);
    if ($key !== FALSE) {
      unset($fields[$key]);
    }
  }
}

Also implements this hook on behalf of the Automatic Nodetitles module and the Automatic Entity Labels modules.