protected function YamlFormRequest::getCurrentSourceEntityFromQuery in YAML Form 8
Get form submission source entity from query string.
Return value
\Drupal\Core\Entity\EntityInterface|null A source entity.
1 call to YamlFormRequest::getCurrentSourceEntityFromQuery()
- YamlFormRequest::getCurrentSourceEntity in src/YamlFormRequest.php 
- Get the current request's source entity.
File
- src/YamlFormRequest.php, line 211 
Class
- YamlFormRequest
- Handles form requests.
Namespace
Drupal\yamlformCode
protected function getCurrentSourceEntityFromQuery() {
  // Get and check for form.
  $yamlform = $this->routeMatch
    ->getParameter('yamlform');
  if (!$yamlform) {
    return NULL;
  }
  // Get and check source entity type.
  $source_entity_type = $this->request->query
    ->get('source_entity_type');
  if (!$source_entity_type || !$this->entityTypeManager
    ->hasDefinition($source_entity_type)) {
    return NULL;
  }
  // Get and check source entity id.
  $source_entity_id = $this->request->query
    ->get('source_entity_id');
  if (!$source_entity_id) {
    return NULL;
  }
  // Get and check source entity.
  $source_entity = $this->entityTypeManager
    ->getStorage($source_entity_type)
    ->load($source_entity_id);
  if (!$source_entity) {
    return NULL;
  }
  // Check source entity access.
  if (!$source_entity
    ->access('view')) {
    return NULL;
  }
  // Check that the form is referenced by the source entity.
  if (!$yamlform
    ->getSetting('form_prepopulate_source_entity')) {
    // Get source entity's yamlform field.
    $yamlform_field_name = $this
      ->getSourceEntityYamlFormFieldName($source_entity);
    if (!$yamlform_field_name) {
      return NULL;
    }
    // Check that source entity's reference form is the current YAML
    // form.
    if ($source_entity->{$yamlform_field_name}->target_id != $yamlform
      ->id()) {
      return NULL;
    }
  }
  return $source_entity;
}