CerPresetController.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * The controller class for CerPreset entities.
  4. */
  5. class CerPresetController extends EntityAPIControllerExportable {
  6. /**
  7. * Overridden.
  8. */
  9. public function export($entity, $prefix = '') {
  10. $variables = get_object_vars($entity);
  11. // I really wish Entity API tried to notify the entity that it's being
  12. // exported so that it could clean itself up first, but it doesn't. So we
  13. // gotta do this bizness.
  14. unset($variables['pid'], $variables['wrapper'], $variables['status'], $variables['module'], $variables['label_variables'], $variables['uid']);
  15. // Features 2.x checks for overriddenness using sorted keys, which means
  16. // that if the variables aren't key-sorted the presets will always be
  17. // considered overridden, even if they actually aren't.
  18. ksort($variables);
  19. return entity_var_json_export($variables, $prefix);
  20. }
  21. /**
  22. * Overridden.
  23. */
  24. protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
  25. parent::attachLoad($queried_entities, $revision_id);
  26. foreach ($queried_entities as $preset) {
  27. // Attach variables used to build the human-readable preset label. These
  28. // need to be attached after the Field API has done its magic (i.e.,
  29. // during parent::attachLoad()), since the label depends on field values.
  30. // @see CerPreset::label().
  31. $fields = field_attach_view('cer', $preset, 'default');
  32. $preset->label_variables = array(
  33. '@left' =>
  34. render($fields['cer_left'][0]),
  35. '@right' =>
  36. render($fields['cer_right'][0]),
  37. '!operator' =>
  38. $preset->wrapper->cer_bidirectional->value() ? '<>' : '>',
  39. );
  40. }
  41. }
  42. }