copyFormValuesToEntity example


  public function save(array $form, FormStateInterface $form_state) {
    return $this->entity->save();
  }

  /** * {@inheritdoc} */
  public function buildEntity(array $form, FormStateInterface $form_state) {
    $entity = clone $this->entity;
    $this->copyFormValuesToEntity($entity$form$form_state);

    // Invoke all specified builders for copying form values to entity     // properties.     if (isset($form['#entity_builders'])) {
      foreach ($form['#entity_builders'] as $function) {
        call_user_func_array($form_state->prepareCallback($function)[$entity->getEntityTypeId()$entity, &$form, &$form_state]);
      }
    }

    return $entity;
  }

  

  protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
    // Do not process field values if Layout Builder is or will be enabled.     $set_enabled = (bool) $form_state->getValue(['layout', 'enabled'], FALSE);
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $entity */
    $already_enabled = $entity->isLayoutBuilderEnabled();
    if ($already_enabled || $set_enabled) {
      $form['#fields'] = [];
      $form['#extra'] = [];
    }

    parent::copyFormValuesToEntity($entity$form$form_state);
  }

  /** * Entity builder for layout options on the entity view display form. */
  public function entityFormEntityBuild($entity_type_id, LayoutEntityDisplayInterface $display, &$form, FormStateInterface &$form_state) {
    $set_enabled = (bool) $form_state->getValue(['layout', 'enabled'], FALSE);
    $already_enabled = $display->isLayoutBuilderEnabled();

    if ($set_enabled) {
      $overridable = (bool) $form_state->getValue(['layout', 'allow_custom'], FALSE);
      
Home | Imprint | This part of the site doesn't use cookies.