function ConfigTestForm::exists

Same name in other branches
  1. 9 core/modules/config/tests/config_test/src/ConfigTestForm.php \Drupal\config_test\ConfigTestForm::exists()
  2. 10 core/modules/config/tests/config_test/src/ConfigTestForm.php \Drupal\config_test\ConfigTestForm::exists()
  3. 11.x core/modules/config/tests/config_test/src/ConfigTestForm.php \Drupal\config_test\ConfigTestForm::exists()

Determines if the entity already exists.

Parameters

string|int $entity_id: The entity ID.

array $element: The form element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

bool TRUE if the entity exists, FALSE otherwise.

File

core/modules/config/tests/config_test/src/ConfigTestForm.php, line 164

Class

ConfigTestForm
Form controller for the test config edit forms.

Namespace

Drupal\config_test

Code

public function exists($entity_id, array $element, FormStateInterface $form_state) {
    
    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $entity = $form_state->getFormObject()
        ->getEntity();
    return (bool) $this->entityTypeManager
        ->getStorage($entity->getEntityTypeId())
        ->getQuery()
        ->condition($entity->getEntityType()
        ->getKey('id'), $entity_id)
        ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.