You are here

class BrightcoveAPIClientDeleteForm in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 src/Form/BrightcoveAPIClientDeleteForm.php \Drupal\brightcove\Form\BrightcoveAPIClientDeleteForm
  2. 3.x src/Form/BrightcoveAPIClientDeleteForm.php \Drupal\brightcove\Form\BrightcoveAPIClientDeleteForm

Builds the form to delete Brightcove API Client entities.

Hierarchy

Expanded class hierarchy of BrightcoveAPIClientDeleteForm

File

src/Form/BrightcoveAPIClientDeleteForm.php, line 18

Namespace

Drupal\brightcove\Form
View source
class BrightcoveAPIClientDeleteForm extends EntityConfirmFormBase {

  /**
   * Query factory.
   *
   * @var \Drupal\Core\Entity\Query\QueryFactory
   */
  protected $queryFactory;

  /**
   * Database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * The playlist local delete queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $playlistLocalDeleteQueue;

  /**
   * The video local delete queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $videoLocalDeleteQueue;

  /**
   * The player local delete queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $playerDeleteQueue;

  /**
   * The custom field local delete queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $customFieldDeleteQueue;

  /**
   * The playlist page queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $textTrackDeleteQueue;

  /**
   * The subscription delete queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $subscriptionDeleteQueue;

  /**
   * Constructs a new BrightcoveAPIClientDeleteForm.
   *
   * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
   *   Query factory.
   * @param \Drupal\Core\Database\Connection $connection
   *   Database connection.
   * @param \Drupal\Core\Queue\QueueInterface $playlist_local_delete_queue
   *   Playlist local delete queue worker.
   * @param \Drupal\Core\Queue\QueueInterface $video_local_delete_queue
   *   Video local delete queue worker.
   * @param \Drupal\Core\Queue\QueueInterface $player_delete_queue
   *   Player local delete queue worker.
   * @param \Drupal\Core\Queue\QueueInterface $custom_field_delete_queue
   *   Custom field local delete queue worker.
   * @param \Drupal\Core\Queue\QueueInterface $text_track_delete_queue
   *   Text track delete queue object.
   * @param \Drupal\Core\Queue\QueueInterface $subscription_delete_queue
   *   Subscription delete queue object.
   */
  public function __construct(QueryFactory $query_factory, Connection $connection, QueueInterface $playlist_local_delete_queue, QueueInterface $video_local_delete_queue, QueueInterface $player_delete_queue, QueueInterface $custom_field_delete_queue, QueueInterface $text_track_delete_queue, QueueInterface $subscription_delete_queue) {
    $this->queryFactory = $query_factory;
    $this->connection = $connection;
    $this->playlistLocalDeleteQueue = $playlist_local_delete_queue;
    $this->videoLocalDeleteQueue = $video_local_delete_queue;
    $this->playerDeleteQueue = $player_delete_queue;
    $this->customFieldDeleteQueue = $custom_field_delete_queue;
    $this->textTrackDeleteQueue = $text_track_delete_queue;
    $this->subscriptionDeleteQueue = $subscription_delete_queue;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity.query'), $container
      ->get('database'), $container
      ->get('queue')
      ->get('brightcove_playlist_local_delete_queue_worker'), $container
      ->get('queue')
      ->get('brightcove_video_local_delete_queue_worker'), $container
      ->get('queue')
      ->get('brightcove_player_delete_queue_worker'), $container
      ->get('queue')
      ->get('brightcove_custom_field_delete_queue_worker'), $container
      ->get('queue')
      ->get('brightcove_text_track_delete_queue_worker'), $container
      ->get('queue')
      ->get('brightcove_subscription_delete_queue_worker'));
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Are you sure you want to delete %name?', [
      '%name' => $this->entity
        ->label(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return parent::getDescription() . '<br>' . $this
      ->t('Warning: By deleting API Client all of its local contents will be deleted too, including videos, playlists, players, custom fields and subscriptions.');
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('entity.brightcove_api_client.collection');
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this
      ->t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    /** @var \Drupal\brightcove\Entity\BrightcoveAPIClient $entity */
    $entity = $this->entity;

    // Empty queues.
    foreach (BrightcoveUtil::getStatusQueues() as $queue) {
      BrightcoveUtil::clearQueue($queue);
    }

    // Collect all playlists belonging for the api client.
    $playlists = $this->queryFactory
      ->get('brightcove_playlist')
      ->condition('api_client', $entity
      ->id())
      ->execute();
    foreach ($playlists as $playlist) {
      $this->playlistLocalDeleteQueue
        ->createItem($playlist);
    }

    // Collect all text tracks belonging for the api client.
    $query = $this->connection
      ->select('brightcove_text_track', 'btt')
      ->fields('btt', [
      'text_track_id',
    ]);
    $query
      ->innerJoin('brightcove_video__text_tracks', 'bvtt', '%alias.text_tracks_target_id = btt.bcttid');
    $query
      ->innerJoin('brightcove_video', 'bv', '%alias.bcvid = bvtt.entity_id');
    $text_tracks = $query
      ->condition('api_client', $entity
      ->id())
      ->execute();
    foreach ($text_tracks as $text_track) {
      $this->textTrackDeleteQueue
        ->createItem($text_track->text_track_id);
    }

    // Collect all videos belonging for the api client.
    $videos = $this->queryFactory
      ->get('brightcove_video')
      ->condition('api_client', $entity
      ->id())
      ->execute();
    foreach ($videos as $video) {
      $this->videoLocalDeleteQueue
        ->createItem($video);
    }

    // Collect all players belonging for the api client.
    $players = $this->queryFactory
      ->get('brightcove_player')
      ->condition('api_client', $entity
      ->id())
      ->execute();
    foreach ($players as $player) {
      $this->playerDeleteQueue
        ->createItem([
        'player_entity_id' => $player,
      ]);
    }

    // Collect all custom fields belonging for the api client.
    $custom_fields = $this->queryFactory
      ->get('brightcove_custom_field')
      ->condition('api_client', $entity
      ->id())
      ->execute();
    foreach ($custom_fields as $custom_field) {
      $this->customFieldDeleteQueue
        ->createItem($custom_field);
    }

    // First delete the default subscription from Brightcove if it's active.
    $default_subscription = BrightcoveSubscription::loadDefault($entity);
    if (!empty($default_subscription)) {
      if ($default_subscription
        ->isActive()) {
        $default_subscription
          ->delete();
      }
      else {
        $default_subscription
          ->delete(TRUE);
      }
    }

    // Then collect all available subscriptions belonging to the given API
    // client, and put them into the delete queue.
    $brightcove_subscriptions = BrightcoveSubscription::loadMultipleByApiClient($entity);
    foreach ($brightcove_subscriptions as $brightcove_subscription) {
      $this->subscriptionDeleteQueue
        ->createItem([
        'subscription_id' => $brightcove_subscription
          ->getBcSid(),
        'local_only' => TRUE,
      ]);
    }

    // Initialize batch.
    batch_set([
      'operations' => [
        [
          [
            BrightcoveUtil::class,
            'runQueue',
          ],
          [
            'brightcove_playlist_local_delete_queue_worker',
          ],
        ],
        [
          [
            BrightcoveUtil::class,
            'runQueue',
          ],
          [
            'brightcove_video_local_delete_queue_worker',
          ],
        ],
        [
          [
            BrightcoveUtil::class,
            'runQueue',
          ],
          [
            'brightcove_player_delete_queue_worker',
          ],
        ],
        [
          [
            BrightcoveUtil::class,
            'runQueue',
          ],
          [
            'brightcove_custom_field_delete_queue_worker',
          ],
        ],
        [
          [
            BrightcoveUtil::class,
            'runQueue',
          ],
          [
            'brightcove_text_track_delete_queue_worker',
          ],
        ],
        [
          [
            BrightcoveUtil::class,
            'runQueue',
          ],
          [
            'brightcove_subscription_delete_queue_worker',
          ],
        ],
      ],
    ]);

    // Delete api client.
    $entity
      ->delete();
    drupal_set_message($this
      ->t('Entity @type: deleted @label.', [
      '@type' => $this->entity
        ->bundle(),
      '@label' => $this->entity
        ->label(),
    ]));
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrightcoveAPIClientDeleteForm::$connection protected property Database connection.
BrightcoveAPIClientDeleteForm::$customFieldDeleteQueue protected property The custom field local delete queue object.
BrightcoveAPIClientDeleteForm::$playerDeleteQueue protected property The player local delete queue object.
BrightcoveAPIClientDeleteForm::$playlistLocalDeleteQueue protected property The playlist local delete queue object.
BrightcoveAPIClientDeleteForm::$queryFactory protected property Query factory.
BrightcoveAPIClientDeleteForm::$subscriptionDeleteQueue protected property The subscription delete queue object.
BrightcoveAPIClientDeleteForm::$textTrackDeleteQueue protected property The playlist page queue object.
BrightcoveAPIClientDeleteForm::$videoLocalDeleteQueue protected property The video local delete queue object.
BrightcoveAPIClientDeleteForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
BrightcoveAPIClientDeleteForm::getCancelUrl public function Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface::getCancelUrl
BrightcoveAPIClientDeleteForm::getConfirmText public function Returns a caption for the button that confirms the action. Overrides EntityConfirmFormBase::getConfirmText
BrightcoveAPIClientDeleteForm::getDescription public function Returns additional text to display as a description. Overrides EntityConfirmFormBase::getDescription
BrightcoveAPIClientDeleteForm::getQuestion public function Returns the question to ask the user. Overrides ConfirmFormInterface::getQuestion
BrightcoveAPIClientDeleteForm::submitForm public function This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state… Overrides EntityForm::submitForm
BrightcoveAPIClientDeleteForm::__construct public function Constructs a new BrightcoveAPIClientDeleteForm.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EntityConfirmFormBase::actions protected function Returns an array of supported actions for the current entity form. Overrides EntityForm::actions 1
EntityConfirmFormBase::buildForm public function Form constructor. Overrides EntityForm::buildForm 4
EntityConfirmFormBase::delete public function The delete() method is not used in EntityConfirmFormBase. This overrides the default implementation that redirects to the delete-form confirmation form.
EntityConfirmFormBase::getBaseFormId public function Returns a string identifying the base form. Overrides EntityForm::getBaseFormId
EntityConfirmFormBase::getCancelText public function Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface::getCancelText
EntityConfirmFormBase::getFormName public function Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface::getFormName
EntityConfirmFormBase::save public function The save() method is not used in EntityConfirmFormBase. This overrides the default implementation that saves the entity. Overrides EntityForm::save
EntityForm::$entity protected property The entity being used by this form. 7
EntityForm::$entityTypeManager protected property The entity type manager. 3
EntityForm::$moduleHandler protected property The module handler service.
EntityForm::$operation protected property The name of the current operation.
EntityForm::$privateEntityManager private property The entity manager.
EntityForm::actionsElement protected function Returns the action form element for the current entity form.
EntityForm::afterBuild public function Form element #after_build callback: Updates the entity with submitted data.
EntityForm::buildEntity public function Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface::buildEntity 2
EntityForm::copyFormValuesToEntity protected function Copies top-level form values to entity properties 7
EntityForm::form public function Gets the actual form array to be built. 30
EntityForm::getEntity public function Gets the form entity. Overrides EntityFormInterface::getEntity
EntityForm::getEntityFromRouteMatch public function Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface::getEntityFromRouteMatch 1
EntityForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId 10
EntityForm::getOperation public function Gets the operation identifying the form. Overrides EntityFormInterface::getOperation
EntityForm::init protected function Initialize the form state and the entity before the first form build. 3
EntityForm::prepareEntity protected function Prepares the entity object before the form is built first. 3
EntityForm::prepareInvokeAll protected function Invokes the specified prepare hook variant.
EntityForm::processForm public function Process callback: assigns weights and hides extra fields.
EntityForm::setEntity public function Sets the form entity. Overrides EntityFormInterface::setEntity
EntityForm::setEntityManager public function Sets the entity manager for this form. Overrides EntityFormInterface::setEntityManager
EntityForm::setEntityTypeManager public function Sets the entity type manager for this form. Overrides EntityFormInterface::setEntityTypeManager
EntityForm::setModuleHandler public function Sets the module handler for this form. Overrides EntityFormInterface::setModuleHandler
EntityForm::setOperation public function Sets the operation for this form. Overrides EntityFormInterface::setOperation
EntityForm::__get public function
EntityForm::__set public function
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.