translation.handler.field_collection_item.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @file
  4. * Field Collection Item translation handler for the Entity Translation module.
  5. */
  6. /**
  7. * Field Collection Item translation handler.
  8. *
  9. * Overrides default behaviours for Field Collection Item properties.
  10. */
  11. class EntityTranslationFieldCollectionItemHandler extends EntityTranslationDefaultHandler {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function __construct($entity_type, $entity_info, $entity) {
  16. parent::__construct('field_collection_item', $entity_info, $entity);
  17. // Initialize the path scheme for the current bundle, unless we are dealing
  18. // with the "default" bundle.
  19. if ($this->bundle != $entity_info['translation']['entity_translation']['default_scheme']) {
  20. $this->setPathScheme($this->bundle);
  21. }
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function getAccess($op) {
  27. return entity_access($op, 'field_collection_item', $this->entity);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function getLanguage() {
  33. // Do not use $this->entity->langcode() as this will finally call
  34. // field_collection_entity_language() which again calls us!
  35. // If the current field is untranslatable, try inherit the host entity
  36. // language.
  37. if (($host_entity_type = $this->entity->hostEntityType()) && entity_translation_enabled($host_entity_type) && ($host_entity = $this->entity->hostEntity())) {
  38. $handler = $this->factory->getHandler($host_entity_type, $host_entity);
  39. $langcode = $handler->getFormLanguage();
  40. }
  41. // If the host entity is not translatable, use the default language
  42. // fallback.
  43. else {
  44. $langcode = parent::getLanguage();
  45. }
  46. return $langcode;
  47. }
  48. }