class BrightcoveAPIClientDeleteForm in Brightcove Video Connect 8
Same name and namespace in other branches
- 8.2 src/Form/BrightcoveAPIClientDeleteForm.php \Drupal\brightcove\Form\BrightcoveAPIClientDeleteForm
- 3.x src/Form/BrightcoveAPIClientDeleteForm.php \Drupal\brightcove\Form\BrightcoveAPIClientDeleteForm
Builds the form to delete Brightcove API Client entities.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\Core\Entity\EntityConfirmFormBase implements ConfirmFormInterface
- class \Drupal\brightcove\Form\BrightcoveAPIClientDeleteForm
- class \Drupal\Core\Entity\EntityConfirmFormBase implements ConfirmFormInterface
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of BrightcoveAPIClientDeleteForm
File
- src/
Form/ BrightcoveAPIClientDeleteForm.php, line 18
Namespace
Drupal\brightcove\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BrightcoveAPIClientDeleteForm:: |
protected | property | Database connection. | |
BrightcoveAPIClientDeleteForm:: |
protected | property | The custom field local delete queue object. | |
BrightcoveAPIClientDeleteForm:: |
protected | property | The player local delete queue object. | |
BrightcoveAPIClientDeleteForm:: |
protected | property | The playlist local delete queue object. | |
BrightcoveAPIClientDeleteForm:: |
protected | property | Query factory. | |
BrightcoveAPIClientDeleteForm:: |
protected | property | The subscription delete queue object. | |
BrightcoveAPIClientDeleteForm:: |
protected | property | The playlist page queue object. | |
BrightcoveAPIClientDeleteForm:: |
protected | property | The video local delete queue object. | |
BrightcoveAPIClientDeleteForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
BrightcoveAPIClientDeleteForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
BrightcoveAPIClientDeleteForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides EntityConfirmFormBase:: |
|
BrightcoveAPIClientDeleteForm:: |
public | function |
Returns additional text to display as a description. Overrides EntityConfirmFormBase:: |
|
BrightcoveAPIClientDeleteForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
BrightcoveAPIClientDeleteForm:: |
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:: |
|
BrightcoveAPIClientDeleteForm:: |
public | function | Constructs a new BrightcoveAPIClientDeleteForm. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityConfirmFormBase:: |
protected | function |
Returns an array of supported actions for the current entity form. Overrides EntityForm:: |
1 |
EntityConfirmFormBase:: |
public | function |
Form constructor. Overrides EntityForm:: |
4 |
EntityConfirmFormBase:: |
public | function | The delete() method is not used in EntityConfirmFormBase. This overrides the default implementation that redirects to the delete-form confirmation form. | |
EntityConfirmFormBase:: |
public | function |
Returns a string identifying the base form. Overrides EntityForm:: |
|
EntityConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
|
EntityConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
EntityConfirmFormBase:: |
public | function |
The save() method is not used in EntityConfirmFormBase. This overrides the
default implementation that saves the entity. Overrides EntityForm:: |
|
EntityForm:: |
protected | property | The entity being used by this form. | 7 |
EntityForm:: |
protected | property | The entity type manager. | 3 |
EntityForm:: |
protected | property | The module handler service. | |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
private | property | The entity manager. | |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
2 |
EntityForm:: |
protected | function | Copies top-level form values to entity properties | 7 |
EntityForm:: |
public | function | Gets the actual form array to be built. | 30 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
1 |
EntityForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
10 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Initialize the form state and the entity before the first form build. | 3 |
EntityForm:: |
protected | function | Prepares the entity object before the form is built first. | 3 |
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function | ||
EntityForm:: |
public | function | ||
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |