function RobotFormBase::exists
Same name in other branches
- 3.x modules/config_entity_example/src/Form/RobotFormBase.php \Drupal\config_entity_example\Form\RobotFormBase::exists()
- 4.0.x modules/config_entity_example/src/Form/RobotFormBase.php \Drupal\config_entity_example\Form\RobotFormBase::exists()
Checks for an existing robot.
Parameters
string|int $entity_id: The entity ID.
array $element: The form element.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
bool TRUE if this format already exists, FALSE otherwise.
File
-
config_entity_example/
src/ Form/ RobotFormBase.php, line 131
Class
- RobotFormBase
- Class RobotFormBase.
Namespace
Drupal\config_entity_example\FormCode
public function exists($entity_id, array $element, FormStateInterface $form_state) {
// Use the query factory to build a new robot entity query.
$query = $this->entityStorage
->getQuery();
// Query the entity ID to see if its in use.
$result = $query->condition('id', $element['#field_prefix'] . $entity_id)
->execute();
// We don't need to return the ID, only if it exists or not.
return (bool) $result;
}