class MergeConfirmForm in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_entity/src/Form/MergeConfirmForm.php \Drupal\bibcite_entity\Form\MergeConfirmForm
Confirm merge of bibliographic entities.
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\bibcite_entity\Form\MergeConfirmForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of MergeConfirmForm
1 string reference to 'MergeConfirmForm'
- bibcite_entity.routing.yml in modules/
bibcite_entity/ bibcite_entity.routing.yml - modules/bibcite_entity/bibcite_entity.routing.yml
File
- modules/
bibcite_entity/ src/ Form/ MergeConfirmForm.php, line 14
Namespace
Drupal\bibcite_entity\FormView source
class MergeConfirmForm extends ConfirmFormBase {
/**
* This entity will be merged to target.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $source;
/**
* Source entity will be merged to this one.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $target;
/**
* The field name for filtering.
*
* @var string
*/
protected $fieldName;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_route_match'));
}
/**
* {@inheritdoc}
*/
public function __construct(RouteMatchInterface $route_match) {
$parameter_name = $route_match
->getRouteObject()
->getOption('_bibcite_entity_type_id');
$this->source = $route_match
->getParameter($parameter_name);
$this->target = $route_match
->getParameter("{$parameter_name}_target");
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'bibcite_entity_merge_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->t('Are you sure you want to merge @source to @target?', [
'@source' => $this->source
->label(),
'@target' => $this->target
->label(),
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return $this->source
->toUrl('bibcite-merge-form');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $field_name = NULL) {
$this->fieldName = $field_name;
$statistic = $this
->getAuthoredReferencesStatistic();
$form['references'] = [
'#type' => 'fieldset',
'#title' => $this
->t('This operation will cause changes in these references'),
'items' => [
'#markup' => $this
->t('No one reference will be changed.'),
],
];
if (count($statistic['entities']) > 0) {
$items = array_map(function (ReferenceInterface $reference) {
return $reference
->label();
}, $statistic['entities']);
$form['references']['items'] = [
'#theme' => 'item_list',
'#items' => $items,
];
}
if ($statistic['count'] > 0) {
$form['references']['count'] = [
'#markup' => $this
->t('and @count more', [
'@count' => $statistic['count'],
]),
];
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$batch = [
'title' => t('Merging'),
'operations' => [
[
'bibcite_entity_merge_entity',
[
$this->source
->id(),
$this->target
->id(),
$this->source
->getEntityTypeId(),
$this->fieldName,
],
],
[
'bibcite_entity_merge_entity_delete',
[
$this->source
->id(),
$this->source
->getEntityTypeId(),
$this->fieldName,
],
],
],
'finished' => 'bibcite_entity_merge_entity_finished',
'file' => drupal_get_path('module', 'bibcite_entity') . '/bibcite_entity.batch.inc',
];
batch_set($batch);
}
/**
* Find references and get statistic data.
*
* @return array
* Statistic data with first 10 objects and count of another references.
*/
private function getAuthoredReferencesStatistic() {
$storage = \Drupal::entityTypeManager()
->getStorage('bibcite_reference');
$range = 10;
$query = $storage
->getQuery();
$query
->condition($this->fieldName, $this->source
->id());
$query
->range(0, $range);
$entities = $storage
->loadMultiple($query
->execute());
$count = $query
->range()
->count()
->execute();
return [
'entities' => $entities,
'count' => $count > $range ? $count - $range : 0,
];
}
}
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 a caption for the button that confirms the action. Overrides ConfirmFormInterface:: |
20 |
ConfirmFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormInterface:: |
11 |
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 | |
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. | |
MergeConfirmForm:: |
protected | property | The field name for filtering. | |
MergeConfirmForm:: |
protected | property | This entity will be merged to target. | |
MergeConfirmForm:: |
protected | property | Source entity will be merged to this one. | |
MergeConfirmForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
MergeConfirmForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
MergeConfirmForm:: |
private | function | Find references and get statistic data. | |
MergeConfirmForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
MergeConfirmForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
MergeConfirmForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
MergeConfirmForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
MergeConfirmForm:: |
public | function | ||
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. |