function ConfigTestForm::exists
Same name in other branches
- 9 core/modules/config/tests/config_test/src/ConfigTestForm.php \Drupal\config_test\ConfigTestForm::exists()
- 8.9.x 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 167
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();
/** @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.