public function EntityTranslationController::entityFormSharedElements

Process callback: determines which elements get clue in the form.

See also

\Drupal\translation_entity\EntityTranslationController::entityFormAlter()

File

drupal/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php, line 324
Definition of Drupal\translation_entity\EntityTranslationController.

Class

EntityTranslationController
Base class for entity translation controllers.

Namespace

Drupal\translation_entity

Code

public function entityFormSharedElements($element, $form_state, $form) {
  static $ignored_types;

  // @todo Find a more reliable way to determine if a form element concerns a
  //   multilingual value.
  if (!isset($ignored_types)) {
    $ignored_types = array_flip(array(
      'actions',
      'value',
      'hidden',
      'vertical_tabs',
      'token',
    ));
  }
  foreach (element_children($element) as $key) {
    if (!isset($element[$key]['#type'])) {
      $this
        ->entityFormSharedElements($element[$key], $form_state, $form);
    }
    else {

      // Ignore non-widget form elements.
      if (isset($ignored_types[$element[$key]['#type']])) {
        continue;
      }

      // Elements are considered to be non multilingual by default.
      if (empty($element[$key]['#multilingual'])) {

        // If we are displaying a multilingual entity form we need to provide
        // translatability clues, otherwise the shared form elements should be
        // hidden.
        if (empty($form_state['translation_entity']['translation_form'])) {
          $this
            ->addTranslatabilityClue($element[$key]);
        }
        else {
          $element[$key]['#access'] = FALSE;
        }
      }
    }
  }
  return $element;
}