Skip to content
Snippets Groups Projects
Commit 978514cd authored by Abhisek Mazumdar's avatar Abhisek Mazumdar Committed by Ted Bowman
Browse files

Issue #3462160 by abhisekmazumdar, wim leers, tedbow: Create a new Exception...

Issue #3462160 by abhisekmazumdar, wim leers, tedbow: Create a new Exception type for a dynamic prop missing a host entity
parent ba13164c
No related branches found
No related tags found
1 merge request!313#3462160: Create a new Exception type for a dynamic prop missing a host entity
Pipeline #300967 failed
<?php
declare(strict_types=1);
namespace Drupal\experience_builder;
class MissingHostEntityException extends \Exception {
public function __construct(string $message = "Missing host entity.", int $code = 0, ?\Throwable $previous = NULL) {
parent::__construct($message, $code, $previous);
}
}
......@@ -10,6 +10,7 @@ use Drupal\Core\Render\Component\Exception\InvalidComponentException;
use Drupal\Core\Theme\Component\ComponentValidator;
use Drupal\Core\Theme\ComponentPluginManager;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\experience_builder\MissingHostEntityException;
use Drupal\experience_builder\Entity\Component;
use Drupal\experience_builder\Plugin\DataType\ComponentTreeStructure;
use Drupal\experience_builder\Plugin\Field\FieldType\ComponentTreeItem;
......@@ -88,11 +89,9 @@ final class ValidComponentTreeConstraintValidator extends ConstraintValidator im
catch (InvalidComponentException) {
$this->context->addViolation('The component instance with UUID %uuid uses component %id and receives some invalid props! Put a breakpoint here and figure out why.', ['%uuid' => $component_instance_uuid, '%id' => Component::convertIdToMachineName($component_id)]);
}
catch (\OutOfRangeException $e) {
catch (MissingHostEntityException $e) {
// DynamicPropSources cannot be validated in isolation, only in the
// context of a host content entity.
// @todo Create specific exceptions for this in
// https://drupal.org/i/3462160.
if ($component_tree_type === 'config') {
// Silence this exception until this config is used in a content
// entity.
......
......@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Drupal\experience_builder\PropSource;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\experience_builder\MissingHostEntityException;
use Drupal\experience_builder\PropExpressions\StructuredData\Evaluator;
use Drupal\experience_builder\PropExpressions\StructuredData\StructuredDataPropExpression;
use Drupal\experience_builder\PropExpressions\StructuredData\StructuredDataPropExpressionInterface;
......@@ -59,7 +60,7 @@ final class DynamicPropSource extends PropSourceBase {
*/
public function evaluate(?FieldableEntityInterface $host_entity): mixed {
if ($host_entity === NULL) {
throw new \OutOfRangeException('Missing host entity.');
throw new MissingHostEntityException();
}
return Evaluator::evaluate($host_entity, $this->expression);
}
......
......@@ -89,6 +89,12 @@ trait ComponentTreeTestTrait {
'expression' => 'ℹ︎␜entity:node:article␝title␞␟value',
],
],
'dynamic-static-card4' => [
'heading' => [
'sourceType' => 'dynamic',
'expression' => 'ℹ︎␜entity:node:article␝title␞␟value',
],
],
]),
],
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment