You are here

class i18n_field_instance in Internationalization 7

Field instance object

Hierarchy

Expanded class hierarchy of i18n_field_instance

1 string reference to 'i18n_field_instance'
i18n_field_i18n_object_info in i18n_field/i18n_field.i18n.inc
Implements hook_i18n_object_info().

File

i18n_field/i18n_field.inc, line 119
Field and field instance object handlers

View source
class i18n_field_instance extends i18n_field_base {

  /**
   * Get edit path for object
   */
  public function get_edit_path() {
    return $this
      ->get_base_path();
  }

  /**
   * Get translate path for object
   */
  public function get_translate_path($langcode = NULL) {
    return $this
      ->get_base_path() . '/translate' . ($langcode ? '/' . $langcode : '');
  }

  /**
   * Get string context
   */
  public function get_string_context() {
    return array(
      $this->object['field_name'],
      $this->object['bundle'],
    );
  }

  /**
   * Get translatable properties
   */
  protected function build_properties() {
    $properties = parent::build_properties();
    $object = $this->object;
    $field = field_info_field($object['field_name']);

    // Only for text field types
    if (!empty($object['default_value']) && i18n_field_type_info($field['type'], 'translate_default')) {
      $format = isset($object['default_value'][0]['format']) ? $object['default_value'][0]['format'] : NULL;
      $properties[$this
        ->get_textgroup()][$object['field_name']][$object['bundle']]['default_value']['string'] = $object['default_value'][0]['value'];
      $properties[$this
        ->get_textgroup()][$object['field_name']][$object['bundle']]['default_value']['format'] = $format;
    }
    return $properties;
  }

  /**
   * Set field translation for object.
   *
   * Mot often, this is a direct field set, but sometimes fields may have different formats.
   *
   * @param $object
   *   A clone of the object or array. Field instance.
   */
  protected function translate_field(&$object, $i18nstring, $langcode, $options) {
    if ($i18nstring->property == 'default_value') {

      // Render string without applying format
      $object['default_value'][0]['value'] = $i18nstring
        ->format_translation($langcode, array(
        'sanitize' => FALSE,
      ) + $options);
    }
    else {
      parent::translate_field($object, $i18nstring, $langcode, $options);
    }
  }

  /**
   * Context to be pre-loaded before translation.
   */
  protected function get_translate_context($langcode, $options) {
    return array(
      $this->object['field_name'],
      array(
        '#field',
        '#allowed_values',
        $this->object['bundle'],
      ),
      '*',
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
i18n_field_base::get_base_path protected function Get base path for object
i18n_field_instance::build_properties protected function Get translatable properties Overrides i18n_string_object_wrapper::build_properties
i18n_field_instance::get_edit_path public function Get edit path for object Overrides i18n_object_wrapper::get_edit_path
i18n_field_instance::get_string_context public function Get string context Overrides i18n_string_object_wrapper::get_string_context
i18n_field_instance::get_translate_context protected function Context to be pre-loaded before translation. Overrides i18n_string_object_wrapper::get_translate_context
i18n_field_instance::get_translate_path public function Get translate path for object Overrides i18n_string_object_wrapper::get_translate_path
i18n_field_instance::translate_field protected function Set field translation for object. Overrides i18n_string_object_wrapper::translate_field
i18n_object_wrapper::$key protected property
i18n_object_wrapper::$object protected property
i18n_object_wrapper::$translations protected property
i18n_object_wrapper::$type protected property
i18n_object_wrapper::get_field function Get field value from object/array
i18n_object_wrapper::get_index function Get string numeric key for indexing.
i18n_object_wrapper::get_info public function Get object info
i18n_object_wrapper::get_key function Get key value from object/array
i18n_object_wrapper::get_langcode public function Get language code
i18n_object_wrapper::get_object public function Get real object or array.
i18n_object_wrapper::get_path public function Get link for item 2
i18n_object_wrapper::get_placeholders protected function Get menu placehoders for object
i18n_object_wrapper::get_string_info public function Get object string translation info
i18n_object_wrapper::get_title public function Get title from item 2
i18n_object_wrapper::get_translate_access function Menu access callback for mixed translation tab
i18n_object_wrapper::get_translation_info public function Get object translation set info
i18n_object_wrapper::get_tsid function Get translation set id if any
i18n_object_wrapper::get_type public function Get object type
i18n_object_wrapper::load_object function Load real object or array. 1
i18n_object_wrapper::localize function Localize object if localizable.
i18n_object_wrapper::path_replace protected function Replace path with placeholders
i18n_object_wrapper::set_field function Set field value to object/array
i18n_object_wrapper::set_tsid function Set translation set id
i18n_object_wrapper::translate_access protected function Translate access (translation sets) 2
i18n_object_wrapper::__construct public function Class constructor 2
i18n_string_object_wrapper::$properties protected property
i18n_string_object_wrapper::$textgroup protected property
i18n_string_object_wrapper::get_properties public function Get object translatable properties
i18n_string_object_wrapper::get_strings public function Get object strings for translation
i18n_string_object_wrapper::get_textgroup public function Get textgroup name
i18n_string_object_wrapper::get_translate_mode public function Translation mode for object Overrides i18n_object_wrapper::get_translate_mode 3
i18n_string_object_wrapper::load_strings public function Load all existing strings for this object.
i18n_string_object_wrapper::localize_access protected function Translate access (localize strings) Overrides i18n_object_wrapper::localize_access
i18n_string_object_wrapper::strings_remove public function Remove all strings for this object.
i18n_string_object_wrapper::strings_update public function Update all strings for this object.
i18n_string_object_wrapper::textgroup protected function Get textgroup object
i18n_string_object_wrapper::translate public function Translate object. Overrides i18n_object_wrapper::translate
i18n_string_object_wrapper::translate_object protected function Translate all properties for object.