EntityLazyLoadContext.php in Page Manager 8
File
src/Context/EntityLazyLoadContext.php
View source
<?php
namespace Drupal\page_manager\Context;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinitionInterface;
class EntityLazyLoadContext extends Context {
protected $uuid;
protected $entityRepository;
public function __construct(ContextDefinitionInterface $context_definition, EntityRepositoryInterface $entity_repository, $uuid) {
parent::__construct($context_definition);
$this->entityRepository = $entity_repository;
$this->uuid = $uuid;
}
public function getContextValue() {
if (!$this->contextData) {
$entity_type_id = substr($this->contextDefinition
->getDataType(), 7);
$this
->setContextValue($this->entityRepository
->loadEntityByUuid($entity_type_id, $this->uuid));
}
return parent::getContextValue();
}
public function hasContextValue() {
if (!$this->contextData) {
$this
->getContextValue();
}
return parent::hasContextValue();
}
}