You are here

public function RelationTypeDeleteConfirm::buildForm in Relation 8

Same name and namespace in other branches
  1. 8.2 src/Form/RelationTypeDeleteConfirm.php \Drupal\relation\Form\RelationTypeDeleteConfirm::buildForm()

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 EntityConfirmFormBase::buildForm

File

src/Form/RelationTypeDeleteConfirm.php, line 71
Contains \Drupal\relation\Form\RelationTypeDeleteConfirm.

Class

RelationTypeDeleteConfirm
Provides a form for relation type deletion.

Namespace

Drupal\relation\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $num_relations = $this->database
    ->query("SELECT COUNT(*) FROM {relation} WHERE relation_type = :type", array(
    ':type' => $this->entity
      ->id(),
  ))
    ->fetchField();
  if ($num_relations) {
    $caption = '<p>' . \Drupal::translation()
      ->formatPlural($num_relations, '%relation_type is used by 1 relation. You can not remove this relation type until you have removed all %relation_type relations.', '%relation_type is used by @count relations. You can not remove %relation_type until you have removed all %relation_type relations.', array(
      '%relation_type' => $this->entity
        ->label(),
    )) . '</p>';
    $form['#title'] = $this
      ->getQuestion();
    $form['description'] = array(
      '#markup' => $caption,
    );
    return $form;
  }
  return parent::buildForm($form, $form_state);
}