You are here

protected function EntityEmbedDialog::loadEntityByAttributes in Entity Embed 8

Loads an entity (in the appropriate translation) given HTML attributes.

Parameters

string[] $attributes: An array of HTML attributes, including at least `data-entity-type` and `data-entity-uuid`, and optionally `data-langcode`.

Return value

\Drupal\Core\Entity\EntityInterface|null The requested entity, or NULL.

2 calls to EntityEmbedDialog::loadEntityByAttributes()
EntityEmbedDialog::buildForm in src/Form/EntityEmbedDialog.php
Form constructor.
EntityEmbedDialog::submitEmbedStep in src/Form/EntityEmbedDialog.php
Form submission handler for the entity embedding step.

File

src/Form/EntityEmbedDialog.php, line 147

Class

EntityEmbedDialog
Provides a form to embed entities by specifying data attributes.

Namespace

Drupal\entity_embed\Form

Code

protected function loadEntityByAttributes(array $attributes) {
  $entity = $this->entityTypeManager
    ->getStorage($attributes['data-entity-type'])
    ->loadByProperties([
    'uuid' => $attributes['data-entity-uuid'],
  ]);
  $entity = current($entity);
  if ($entity && $entity instanceof TranslatableInterface && !empty($attributes['data-langcode'])) {
    if ($entity
      ->hasTranslation($attributes['data-langcode'])) {
      $entity = $entity
        ->getTranslation($attributes['data-langcode']);
    }
  }
  return $entity;
}