CommerceBundleEntityDeleteFormBase.php in Commerce Core 8.2
File
src/Form/CommerceBundleEntityDeleteFormBase.php
View source
<?php
namespace Drupal\commerce\Form;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Form\FormStateInterface;
class CommerceBundleEntityDeleteFormBase extends EntityDeleteForm {
public function buildForm(array $form, FormStateInterface $form_state) {
$bundle_entity_type = $this->entityTypeManager
->getDefinition($this->entity
->getEntityTypeId());
$content_entity_type = $this->entityTypeManager
->getDefinition($bundle_entity_type
->getBundleOf());
$usage_count = $this->entityTypeManager
->getStorage($content_entity_type
->id())
->getQuery()
->accessCheck(FALSE)
->condition($content_entity_type
->getKey('bundle'), $this->entity
->id())
->count()
->execute();
if ($usage_count) {
$caption = '<p>' . $this
->formatPlural($usage_count, '%type is used by 1 %entity on your site. You cannot remove this %entity_type until you have removed all of the %type %entities.', '%type is used by @count %entities on your site. You cannot remove this %entity_type until you have removed all of the %type %entities.', [
'%type' => $this->entity
->label(),
'%entity' => $content_entity_type
->getSingularLabel(),
'%entities' => $content_entity_type
->getPluralLabel(),
'%entity_type' => $content_entity_type
->getBundleLabel(),
]) . '</p>';
$form['#title'] = $this
->getQuestion();
$form['description'] = [
'#markup' => $caption,
];
return $form;
}
return parent::buildForm($form, $form_state);
}
}