Skip to content

Commit

Permalink
PCC-63: Update SmartComponentRenderer to handle non-existent components.
Browse files Browse the repository at this point in the history
  • Loading branch information
purushotamrai committed Jun 18, 2024
1 parent f7a630a commit 181db40
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions modules/pcx_smart_components/src/Service/SmartComponentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,36 @@ private function convertPccComponent(\DOMElement $node): ?array {
// @todo: Update decoding based on ContentType enum.
$attrs = !empty($attrs) ? base64_decode($attrs) : NULL;
$attrs = !empty($attrs) ? json_decode($attrs, TRUE) : NULL;
return !empty($attrs) ?
[
'#type' => 'component',
'#component' => $this->getComponentName($type),
'#props' => $attrs,
] : NULL;

return !empty($attrs) ? $this->createRenderableComponent($type, $attrs) : NULL;
}

/**
* Get SDC component name to prepare render array.
* Get SDC component to prepare render array.
*
* @param string $type
* Smart Component Type | Machine name of the SDC Component.
*
* @return string
* Render array component key.
* @return array|null
* SDC Component Renderable array.
*/
protected function getComponentName(string $type): string {
protected function createRenderableComponent(string $type, array $attrs): ?array {
$component = $this->smartComponentManager->getSDCComponent($type);
$provider = 'pcx_smart_components';
if (!empty($component) && $component instanceof Component) {
if (!empty($component->getPluginDefinition()['provider'])) {
$provider = $component->getPluginDefinition()['provider'];
$renderableComponent = NULL;
if (!empty($component)
&& $component instanceof Component
&& $pluginDefinition = $component->getPluginDefinition()) {
if (!empty($pluginDefinition['provider'])) {
$provider = $pluginDefinition['provider'];
$renderableComponent = [
'#type' => 'component',
'#component' => "$provider:$type",
'#props' => $attrs,
];
}
}

return "$provider:$type";
return $renderableComponent;
}

}

0 comments on commit 181db40

Please sign in to comment.