updateLibrary example

    $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);
    }

    return $this->openerResolver->get($state)
      ->getSelectionResponse($state$media_ids)
      ->addCommand(new CloseDialogCommand());
  }

  /** * Get the number of selected media. * * @param array $media_ids * Array with the media IDs. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * * @return int * The number of media currently selected. */
Home | Imprint | This part of the site doesn't use cookies.