search_api_saved_searches_i18n.string_wrapper.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @file
  4. * Contains the SearchApiSavedSearchesSettingsI18nStringObjectWrapper class.
  5. */
  6. /**
  7. * Custom i18n object wrapper.
  8. */
  9. class SearchApiSavedSearchesSettingsI18nStringObjectWrapper extends i18n_string_object_wrapper {
  10. /**
  11. * Overrides i18n_string_object_wrapper::get_field() to read properties from the options array.
  12. */
  13. public function get_field($field, $default = NULL) {
  14. if (strpos($field, '.') !== FALSE) {
  15. $value = drupal_array_get_nested_value($this->object->options, explode('.', $field));
  16. if (isset($value)) {
  17. return $value;
  18. }
  19. }
  20. if (isset($this->object->options[$field])) {
  21. return $this->object->options[$field];
  22. }
  23. // Fallback to the usual behaviour.
  24. return parent::get_field($field, $default);
  25. }
  26. /**
  27. * Get translatable properties
  28. */
  29. protected function build_properties() {
  30. $strings = parent::build_properties();
  31. $properties = array();
  32. // Dynamically add interval options.
  33. foreach ($this->object->options['interval_options'] as $key => $value) {
  34. $properties['interval_options.' . $key] = array(
  35. 'title' => t('Interval option, @key', array('@key' => $key)),
  36. 'string' => $value,
  37. );
  38. }
  39. $strings[$this->get_textgroup()]['search_api_saved_searches_settings'][$this->object->delta] += $properties;
  40. return $strings;
  41. }
  42. }