public function DeleteMultiple::buildForm in Log entity 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfirmFormBase::buildForm
File
- src/
Form/ DeleteMultiple.php, line 133 - Contains \Drupal\log\Form\DeleteMultiple.
Class
- DeleteMultiple
- Provides a log deletion confirmation form.
Namespace
Drupal\log\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$this->logInfo = $this->tempStoreFactory
->get('log_multiple_delete_confirm')
->get(\Drupal::currentUser()
->id());
if (empty($this->logInfo)) {
return new RedirectResponse($this
->getCancelUrl()
->setAbsolute()
->toString());
}
/** @var \Drupal\log\LogInterface[] $logs */
$logs = $this->storage
->loadMultiple(array_keys($this->logInfo));
$items = [];
foreach ($this->logInfo as $id => $langcodes) {
foreach ($langcodes as $langcode) {
$log = $logs[$id]
->getTranslation($langcode);
$key = $id . ':' . $langcode;
$default_key = $id . ':' . $log
->getUntranslated()
->language()
->getId();
// If we have a translated entity we build a nested list of translations
// that will be deleted.
$languages = $log
->getTranslationLanguages();
if (count($languages) > 1 && $log
->isDefaultTranslation()) {
$names = [];
foreach ($languages as $translation_langcode => $language) {
$names[] = $language
->getName();
unset($items[$id . ':' . $translation_langcode]);
}
$items[$default_key] = [
'label' => [
'#markup' => $this
->t('@label (Original translation) - <em>The following content translations will be deleted:</em>', [
'@label' => $log
->label(),
]),
],
'deleted_translations' => [
'#theme' => 'item_list',
'#items' => $names,
],
];
}
elseif (!isset($items[$default_key])) {
$items[$key] = $log
->label();
}
}
}
$form['logs'] = array(
'#theme' => 'item_list',
'#items' => $items,
);
$form = parent::buildForm($form, $form_state);
return $form;
}