buildEntityFormElement example

FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
        ],
      ],
    ];
    return $element;
  }

  /** * {@inheritdoc} */
  protected function buildEntityFormElement(MediaInterface $media, array $form, FormStateInterface $form_state$delta) {
    $element = parent::buildEntityFormElement($media$form$form_state$delta);
    $source_field = $this->getSourceFieldName($media->bundle->entity);
    if (isset($element['fields'][$source_field])) {
      $element['fields'][$source_field]['widget'][0]['#process'][] = [static::class, 'hideExtraSourceFieldComponents'];
    }
    return $element;
  }

  /** * Processes an image or file source field element. * * @param array $element * The entity form source field element. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * @param $form * The complete form. * * @return array * The processed form element. */

          'aria-label' => $this->t('Added media items'),
          // Add the tabindex '-1' to allow the focus to be shifted to the added           // media wrapper when items are added. We set focus to the container           // because a media item does not necessarily have required fields and           // we do not want to set focus to the remove button automatically.           // @see ::updateFormCallback()           'tabindex' => '-1',
        ],
      ];
      foreach ($added_media as $delta => $media) {
        $form['media'][$delta] = $this->buildEntityFormElement($media$form$form_state$delta);
      }

      $form['selection'] = $this->buildCurrentSelectionArea($form$form_state);
      $form['actions'] = $this->buildActions($form$form_state);
    }

    // Allow the current selection to be set in a hidden field so the selection     // can be passed between different states of the form. This field is filled     // via JavaScript so the default value should be empty.     // @see Drupal.behaviors.MediaLibraryItemSelection     $form['current_selection'] = [
      
Home | Imprint | This part of the site doesn't use cookies.