getCurrentMediaItems example


  public function updateWidget(array &$form, FormStateInterface $form_state) {
    if ($form_state::hasAnyErrors()) {
      return $form;
    }

    // The added media items get an ID when they are saved in ::submitForm().     // For that reason the added media items are keyed by delta in the form     // state and we have to do an array map to get each media ID.     $media_ids = array_map(function DMediaInterface $media) {
      return $media->id();
    }$this->getCurrentMediaItems($form_state));

    // Allow the opener service to respond to the selection.     $state = $this->getMediaLibraryState($form_state);
    $selected_count = $this->getSelectedMediaItemCount($media_ids$form_state);

    $available_slots = $this->getMediaLibraryState($form_state)->getAvailableSlots();
    if ($available_slots > 0 && $selected_count > $available_slots) {
      // Return to library where we display a warning about the overage.       return $this->updateLibrary($form$form_state);
    }

    
Home | Imprint | This part of the site doesn't use cookies.