entityFormAlter example

use Drupal\Core\Form\FormStateInterface;

/** * Defines the translation handler for comments. */
class CommentTranslationHandler extends ContentTranslationHandler {

  /** * {@inheritdoc} */
  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
    parent::entityFormAlter($form$form_state$entity);

    if (isset($form['content_translation'])) {
      // We do not need to show these values on comment forms: they inherit the       // basic comment property values.       $form['content_translation']['status']['#access'] = FALSE;
      $form['content_translation']['name']['#access'] = FALSE;
      $form['content_translation']['created']['#access'] = FALSE;
    }
  }

  /** * {@inheritdoc} */
use Drupal\Core\Form\FormStateInterface;

/** * Defines the translation handler for terms. */
class TermTranslationHandler extends ContentTranslationHandler {

  /** * {@inheritdoc} */
  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
    parent::entityFormAlter($form$form_state$entity);

    $form['content_translation']['status']['#access'] = !isset($form['content_translation']);

    $form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
  }

  /** * Form submission handler for TermTranslationHandler::entityFormAlter(). * * This handles the save action. * * @see \Drupal\Core\Entity\EntityForm::build() */
use Drupal\Core\Form\FormStateInterface;

/** * Defines the translation handler for nodes. */
class NodeTranslationHandler extends ContentTranslationHandler {

  /** * {@inheritdoc} */
  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
    parent::entityFormAlter($form$form_state$entity);

    if (isset($form['content_translation'])) {
      // We do not need to show these values on node forms: they inherit the       // basic node property values.       $form['content_translation']['status']['#access'] = FALSE;
      $form['content_translation']['name']['#access'] = FALSE;
      $form['content_translation']['created']['#access'] = FALSE;
    }

    $form_object = $form_state->getFormObject();
    $form_langcode = $form_object->getFormLangcode($form_state);
    

  protected function hasCreatedTime() {
    // User creation date has nothing to do with translation creation date.     return FALSE;
  }

  /** * {@inheritdoc} */
  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
    parent::entityFormAlter($form$form_state$entity);
    $form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
  }

  /** * Form submission handler for ProfileTranslationHandler::entityFormAlter(). * * This handles the save action. * * @see \Drupal\Core\Entity\EntityForm::build() */
  public function entityFormSave(array $form, FormStateInterface $form_state) {
    
Home | Imprint | This part of the site doesn't use cookies.