You are here

public function YamlFormRequest::getCurrentSourceEntity in YAML Form 8

Get the current request's source entity.

Parameters

string|array $ignored_types: (optional) Array of ignore entity types.

Return value

\Drupal\Core\Entity\EntityInterface|null The current request's source entity.

Overrides YamlFormRequestInterface::getCurrentSourceEntity

3 calls to YamlFormRequest::getCurrentSourceEntity()
YamlFormRequest::getCurrentYamlForm in src/YamlFormRequest.php
Get form associated with the current request.
YamlFormRequest::getYamlFormEntities in src/YamlFormRequest.php
Get the form and source entity for the current request.
YamlFormRequest::getYamlFormSubmissionEntities in src/YamlFormRequest.php
Get the form submission and source entity for the current request.

File

src/YamlFormRequest.php, line 65

Class

YamlFormRequest
Handles form requests.

Namespace

Drupal\yamlform

Code

public function getCurrentSourceEntity($ignored_types = NULL) {

  // See if source entity is being set via query string parameters.
  if ($source_entity = $this
    ->getCurrentSourceEntityFromQuery()) {
    return $source_entity;
  }
  $entity_types = $this->entityTypeRepository
    ->getEntityTypeLabels();
  if ($ignored_types) {
    if (is_array($ignored_types)) {
      $entity_types = array_diff_key($entity_types, array_flip($ignored_types));
    }
    else {
      unset($entity_types[$ignored_types]);
    }
  }
  foreach ($entity_types as $entity_type => $entity_label) {
    $entity = $this->routeMatch
      ->getParameter($entity_type);
    if ($entity instanceof EntityInterface) {
      return $entity;
    }
  }
  return NULL;
}