protected function PreviewLinkForm::getRelatedEntity in Preview Link 8
Attempts to load the entity this preview link will be related to.
Return value
\Drupal\Core\Entity\ContentEntityInterface The content entity interface.
Throws
\InvalidArgumentException Only thrown if we cannot detect the related entity.
1 call to PreviewLinkForm::getRelatedEntity()
- PreviewLinkForm::getEntityFromRouteMatch in src/
Form/ PreviewLinkForm.php - Determines which entity will be used by this form from a RouteMatch object.
File
- src/
Form/ PreviewLinkForm.php, line 138
Class
- PreviewLinkForm
- Preview link form.
Namespace
Drupal\preview_link\FormCode
protected function getRelatedEntity() {
$entity = NULL;
$entity_type_ids = array_keys($this->entityTypeManager
->getDefinitions());
foreach ($entity_type_ids as $entity_type_id) {
if ($entity = \Drupal::request()->attributes
->get($entity_type_id)) {
break;
}
}
if (!$entity) {
throw new \InvalidArgumentException('Something went very wrong');
}
return $entity;
}