public function ConfigTestForm::exists in Drupal 9
Same name and namespace in other branches
- 8 core/modules/config/tests/config_test/src/ConfigTestForm.php \Drupal\config_test\ConfigTestForm::exists()
- 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 164
Class
- ConfigTestForm
- Form controller for the test config edit forms.
Namespace
Drupal\config_testCode
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();
}