function ConfigTestForm::exists

Same name and namespace in other branches
  1. 9 core/modules/config/tests/config_test/src/ConfigTestForm.php \Drupal\config_test\ConfigTestForm::exists()
  2. 8.9.x core/modules/config/tests/config_test/src/ConfigTestForm.php \Drupal\config_test\ConfigTestForm::exists()
  3. 10 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 165

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();
    
    /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
    $storage = $this->entityTypeManager
        ->getStorage($entity->getEntityTypeId());
    return (bool) $storage->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.