class ExportUserConfirm in Open Social 8
Same name and namespace in other branches
- 8.2 modules/social_features/social_user_export/src/Form/ExportUserConfirm.php \Drupal\social_user_export\Form\ExportUserConfirm
- 8.3 modules/social_features/social_user_export/src/Form/ExportUserConfirm.php \Drupal\social_user_export\Form\ExportUserConfirm
- 8.4 modules/social_features/social_user_export/src/Form/ExportUserConfirm.php \Drupal\social_user_export\Form\ExportUserConfirm
Class ExportUserConfirm.
@package Drupal\social_user_export\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\social_user_export\Form\ExportUserConfirm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of ExportUserConfirm
1 string reference to 'ExportUserConfirm'
- social_user_export.routing.yml in modules/
social_features/ social_user_export/ social_user_export.routing.yml - modules/social_features/social_user_export/social_user_export.routing.yml
File
- modules/
social_features/ social_user_export/ src/ Form/ ExportUserConfirm.php, line 19
Namespace
Drupal\social_user_export\FormView source
class ExportUserConfirm extends ConfirmFormBase {
/**
* The temp store factory.
*
* @var \Drupal\user\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a new ExportUserConfirm.
*
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
* The temp store factory.
* @param \Drupal\user\UserStorageInterface $user_storage
* The user storage.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(PrivateTempStoreFactory $temp_store_factory, UserStorageInterface $user_storage, EntityTypeManagerInterface $entity_manager) {
$this->tempStoreFactory = $temp_store_factory;
$this->userStorage = $user_storage;
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('user.private_tempstore'), $container
->get('entity.manager')
->getStorage('user'), $container
->get('entity.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'user_export_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->t('Export users');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.user.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this
->t('Export users');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Retrieve the data to be exported from the temp store.
$data = $this->tempStoreFactory
->get('user_operations_export')
->get($this
->currentUser()
->id());
if (!$data) {
return $this
->redirect('entity.user.collection');
}
$export_params = [
'apply_all' => !empty($data['apply_all']),
'accounts' => [],
'query' => [],
];
// If not selected all items, show list of selected items,
// else show quantity of all items.
if (empty($data['apply_all'])) {
$form['accounts'] = [
'#prefix' => '<ul>',
'#suffix' => '</ul>',
'#tree' => TRUE,
];
foreach ($data['entities'] as $account) {
$export_params['accounts'][] = $account
->id();
$form['accounts'][] = [
'#type' => 'markup',
'#markup' => '<li>' . $account
->getDisplayName() . '</li>',
];
}
}
else {
if (empty($data['query'])) {
$data['query'] = [];
}
$export_params['query'] = $data['query'];
$view = _social_user_export_get_view($data['query']);
$form['message'] = [
'#type' => 'item',
'#markup' => t('@count users will be exported', [
'@count' => $view->total_rows,
]),
];
}
$form_state
->set('export_params', $export_params);
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$export_params = $form_state
->get('export_params');
if ($form_state
->getValue('confirm')) {
// Define the batch.
$batch = [
'title' => t('Exporting users'),
'operations' => [],
'finished' => [
'\\Drupal\\social_user_export\\ExportUser',
'finishedCallback',
],
];
// If selected all users, add single massive operation,
// else add one operation for each user.
if ($export_params['apply_all']) {
$batch['operations'][] = [
[
'\\Drupal\\social_user_export\\ExportUser',
'exportUsersAllOperation',
],
[
$export_params['query'],
],
];
}
else {
foreach ($export_params['accounts'] as $uid) {
$batch['operations'][] = [
[
'\\Drupal\\social_user_export\\ExportUser',
'exportUserOperation',
],
[
User::load($uid),
],
];
}
$batch['operations'] = array_reverse($batch['operations']);
}
batch_set($batch);
}
$form_state
->setRedirect('entity.user.collection');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this
->t('Users will be exported to CSV file');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
1 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
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 | |
ExportUserConfirm:: |
protected | property | The entity manager. | |
ExportUserConfirm:: |
protected | property | The temp store factory. | |
ExportUserConfirm:: |
protected | property | The user storage. | |
ExportUserConfirm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
ExportUserConfirm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ExportUserConfirm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
ExportUserConfirm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
ExportUserConfirm:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormBase:: |
|
ExportUserConfirm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ExportUserConfirm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
ExportUserConfirm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ExportUserConfirm:: |
public | function | Constructs a new ExportUserConfirm. | |
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. |