public function CacheflushDeleteMultiple::buildForm in CacheFlush 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
- modules/
cacheflush_ui/ src/ Form/ CacheflushDeleteMultiple.php, line 117
Class
- CacheflushDeleteMultiple
- Provides a cacheflush deletion confirmation form.
Namespace
Drupal\cacheflush_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$this->cacheflushInfo = $this->tempStoreFactory
->get('cacheflush_multiple_delete_confirm')
->get($this->currentUser
->id());
if (empty($this->cacheflushInfo)) {
return new RedirectResponse($this
->getCancelUrl()
->setAbsolute()
->toString());
}
$entities = $this->storage
->loadMultiple(array_keys($this->cacheflushInfo));
$items = [];
foreach ($this->cacheflushInfo as $id => $langcodes) {
foreach ($langcodes as $langcode) {
$entity = $entities[$id]
->getTranslation($langcode);
$key = $id . ':' . $langcode;
$default_key = $id . ':' . $entity
->getUntranslated()
->language()
->getId();
// If we have a translated entity we build a nested list of translations
// that will be deleted.
$languages = $entity
->getTranslationLanguages();
if (count($languages) > 1 && $entity
->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' => $entity
->label(),
]),
],
'deleted_translations' => [
'#theme' => 'item_list',
'#items' => $names,
],
];
}
elseif (!isset($items[$default_key])) {
$items[$key] = $entity
->label();
}
}
}
$form['cacheflush_items'] = [
'#theme' => 'item_list',
'#items' => $items,
];
$form = parent::buildForm($form, $form_state);
return $form;
}