EntityTranslationActionsDelete.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Et_action plugin class.
  5. */
  6. class EntityTranslationActionsDelete extends EntityTranslationActionsBasic {
  7. /**
  8. * Function checks if plugin available for selected entity type.
  9. */
  10. public function available() {
  11. return entity_translation_enabled($this->entityType);
  12. }
  13. /**
  14. * Function function executes plugin actions.
  15. */
  16. public function action($entity, $context, $handler = NULL) {
  17. $handler = $handler ? $handler : entity_translation_get_handler($this->entityType, $entity);
  18. $translations = $handler->getTranslations();
  19. // Set new original language if replaced language was original.
  20. $lang_entity = $this->entityLanguage($entity, $handler, FALSE);
  21. if ($lang_entity && in_array($lang_entity, $this->options['language'])) {
  22. $language_key = $handler->getLanguageKey();
  23. $translations->original = LANGUAGE_NONE;
  24. $entity->{$language_key} = LANGUAGE_NONE;
  25. foreach ($translations->data as &$translation) {
  26. if ($translation['language'] == LANGUAGE_NONE) {
  27. $translation['source'] = FALSE;
  28. $handler->setTranslation($translation);
  29. }
  30. elseif ($translation['source'] == $lang_entity) {
  31. $translation['source'] = LANGUAGE_NONE;
  32. $handler->setTranslation($translation);
  33. }
  34. unset($translation);
  35. }
  36. }
  37. foreach ($this->options['language'] as $language) {
  38. $handler->removeTranslation($language);
  39. }
  40. return ENTITY_ACTIONS_KIT_RESULT_DELETED;
  41. }
  42. /**
  43. * Function builds form elements for action.
  44. */
  45. public function formBuild(&$form, &$form_state) {
  46. $form['language'] = array(
  47. '#type' => 'checkboxes',
  48. '#options' => $this->languagesList(),
  49. '#title' => t('Select languages:'),
  50. '#required' => TRUE,
  51. );
  52. }
  53. /**
  54. * Function process form data.
  55. *
  56. * Filter selected language options.
  57. */
  58. public function formSubmit($form, &$form_state, $options) {
  59. parent::formSubmit($form, $form_state, $options);
  60. $this->options['language'] = array_filter($this->options['language']);
  61. }
  62. }