18 $xpath = new \DOMXPath(
$source);
20 foreach ($xpath->query(
'/widgets/widget') as $widget) {
21 $widgetAttributes = $widget->attributes;
22 $widgetArray = [
'@' => []];
23 $widgetArray[
'@'][
'type'] = $widgetAttributes->getNamedItem(
'class')->nodeValue;
25 $isEmailCompatible = $widgetAttributes->getNamedItem(
'is_email_compatible');
26 if ($isEmailCompatible !==
null) {
27 $widgetArray[
'is_email_compatible'] = $isEmailCompatible->nodeValue ==
'true' ?
'1' :
'0';
29 $placeholderImage = $widgetAttributes->getNamedItem(
'placeholder_image');
30 if ($placeholderImage !==
null) {
31 $widgetArray[
'placeholder_image'] = $placeholderImage->nodeValue;
34 $widgetId = $widgetAttributes->getNamedItem(
'id');
36 foreach ($widget->childNodes as $widgetSubNode) {
37 switch ($widgetSubNode->nodeName) {
39 $widgetArray[
'name'] = $widgetSubNode->nodeValue;
42 $widgetArray[
'description'] = $widgetSubNode->nodeValue;
46 foreach ($widgetSubNode->childNodes as $parameter) {
47 if ($parameter->nodeName ===
'#text' || $parameter->nodeName ===
'#comment') {
50 $subNodeAttributes = $parameter->attributes;
51 $parameterName = $subNodeAttributes->getNamedItem(
'name')->nodeValue;
52 $widgetArray[
'parameters'][$parameterName] = $this->_convertParameter($parameter);
56 if (!isset($widgetArray[
'supported_containers'])) {
57 $widgetArray[
'supported_containers'] = [];
59 foreach ($widgetSubNode->childNodes as $container) {
60 if ($container->nodeName ===
'#text' || $container->nodeName ===
'#comment') {
63 $widgetArray[
'supported_containers'] = array_merge(
64 $widgetArray[
'supported_containers'],
74 throw new \LogicException(
76 "Unsupported child xml node '%s' found in the 'widget' node",
77 $widgetSubNode->nodeName
82 $widgets[$widgetId->nodeValue] = $widgetArray;
96 $supportedContainers = [];
97 $containerAttributes =
$source->attributes;
99 foreach (
$source->childNodes as $containerTemplate) {
100 if (!$containerTemplate instanceof \DOMElement) {
103 if ($containerTemplate->nodeName !==
'template') {
104 throw new \LogicException(
"Only 'template' node can be child of 'container' node");
106 $templateAttributes = $containerTemplate->attributes;
107 $template[$templateAttributes->getNamedItem(
109 )->nodeValue] = $templateAttributes->getNamedItem(
113 $supportedContainers[] = [
114 'container_name' => $containerAttributes->getNamedItem(
'name')->nodeValue,
117 return $supportedContainers;
129 protected function _convertParameter(
$source)
132 $sourceAttributes =
$source->attributes;
133 $xsiType = $sourceAttributes->getNamedItem(
'type')->nodeValue;
134 if ($xsiType ==
'block') {
135 $parameter[
'type'] =
'label';
136 $parameter[
'@'] = [];
137 $parameter[
'@'][
'type'] =
'complex';
138 foreach (
$source->childNodes as $blockSubNode) {
139 if ($blockSubNode->nodeName ==
'block') {
140 $parameter[
'helper_block'] = $this->
_convertBlock($blockSubNode);
144 }
elseif ($xsiType ==
'select' || $xsiType ==
'multiselect') {
145 $sourceModel = $sourceAttributes->getNamedItem(
'source_model');
146 if ($sourceModel !==
null) {
147 $parameter[
'source_model'] = $sourceModel->nodeValue;
149 $parameter[
'type'] = $xsiType;
152 foreach (
$source->childNodes as $paramSubNode) {
153 if ($paramSubNode->nodeName ==
'options') {
155 foreach ($paramSubNode->childNodes as
$option) {
156 if (
$option->nodeName ===
'#text') {
159 $optionAttributes =
$option->attributes;
160 $optionName = $optionAttributes->getNamedItem(
'name')->nodeValue;
161 $selected = $optionAttributes->getNamedItem(
'selected');
162 if ($selected !==
null) {
163 $parameter[
'value'] = $optionAttributes->getNamedItem(
'value')->nodeValue;
165 if (!isset($parameter[
'values'])) {
166 $parameter[
'values'] = [];
168 $parameter[
'values'][$optionName] = $this->
_convertOption($option);
172 }
elseif ($xsiType ==
'text') {
173 $parameter[
'type'] = $xsiType;
174 foreach (
$source->childNodes as $textSubNode) {
175 if ($textSubNode->nodeName ==
'value') {
176 $parameter[
'value'] = $textSubNode->nodeValue;
179 }
elseif ($xsiType ==
'conditions') {
180 $parameter[
'type'] = $sourceAttributes->getNamedItem(
'class')->nodeValue;
182 $parameter[
'type'] = $xsiType;
184 $visible = $sourceAttributes->getNamedItem(
'visible');
186 $parameter[
'visible'] = $visible->nodeValue ==
'true' ?
'1' :
'0';
188 $parameter[
'visible'] =
true;
190 $required = $sourceAttributes->getNamedItem(
'required');
192 $parameter[
'required'] =
$required->nodeValue ==
'false' ?
'0' :
'1';
194 $sortOrder = $sourceAttributes->getNamedItem(
'sort_order');
196 $parameter[
'sort_order'] = $sortOrder->nodeValue;
198 foreach (
$source->childNodes as $paramSubNode) {
199 switch ($paramSubNode->nodeName) {
201 $parameter[
'label'] = $paramSubNode->nodeValue;
204 $parameter[
'description'] = $paramSubNode->nodeValue;
224 foreach (
$source->childNodes as $childNode) {
225 if ($childNode->nodeName ===
'#text') {
228 if ($childNode->nodeName !==
'parameter') {
229 throw new \LogicException(
230 sprintf(
"Only 'parameter' node can be child of 'depends' node, %s found", $childNode->nodeName)
233 $parameterAttributes = $childNode->attributes;
234 $dependencyName = $parameterAttributes->getNamedItem(
'name')->nodeValue;
235 $dependencyValue = $parameterAttributes->getNamedItem(
'value')->nodeValue;
237 if (!isset($depends[$dependencyName])) {
238 $depends[$dependencyName] = [
239 'value' => $dependencyValue,
243 }
else if (!isset($depends[$dependencyName][
'values'])) {
244 $depends[$dependencyName][
'values'] = [$depends[$dependencyName][
'value']];
245 unset($depends[$dependencyName][
'value']);
248 $depends[$dependencyName][
'values'][] = $dependencyValue;
264 $helperBlock[
'type'] =
$source->attributes->getNamedItem(
'class')->nodeValue;
265 foreach (
$source->childNodes as $blockSubNode) {
266 if ($blockSubNode->nodeName ==
'#text') {
269 if ($blockSubNode->nodeName !==
'data') {
270 throw new \LogicException(
271 sprintf(
"Only 'data' node can be child of 'block' node, %s found", $blockSubNode->nodeName)
274 $helperBlock[
'data'] = $this->
_convertData($blockSubNode);
288 if (!
$source->hasChildNodes()) {
291 foreach (
$source->childNodes as $dataChild) {
292 if ($dataChild instanceof \DOMElement) {
293 $data[$dataChild->attributes->getNamedItem(
'name')->nodeValue] = $this->
_convertData($dataChild);
295 if (strlen(trim($dataChild->nodeValue))) {
296 $data = $dataChild->nodeValue;
313 $optionAttributes =
$source->attributes;
314 $option[
'value'] = $optionAttributes->getNamedItem(
'value')->nodeValue;
315 foreach (
$source->childNodes as $childNode) {
316 if ($childNode->nodeName ==
'#text') {
319 if ($childNode->nodeName !==
'label') {
320 throw new \LogicException(
"Only 'label' node can be child of 'option' node");
322 $option[
'label'] = $childNode->nodeValue;
elseif(isset( $params[ 'redirect_parent']))