Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
search.php
1<?php
3
4use \Bitrix\Landing\Landing;
5use \Bitrix\Landing\Block;
6
7class Search
8{
15 public static function getSearchResultPage($siteId, $tplCode)
16 {
17 $siteId = (int) $siteId;
18 $tplCode = (string) $tplCode;
19
20 $res = Landing::getList([
21 'select' => [
22 'ID'
23 ],
24 'filter' => [
25 'SITE_ID' => $siteId,
26 '=TPL_CODE' => $tplCode
27 ]
28 ]);
29 if ($row = $res->fetch())
30 {
31 $landingId = $row['ID'];
32 }
33 else
34 {
35 $res = \Bitrix\Landing\PublicAction\Landing::addByTemplate(
36 $siteId,
37 $tplCode
38 );
39 $landingId = $res->getResult();
40 }
41
42 return $landingId;
43 }
44
51 protected static function prepareForm(array $manifest, array $params = [])
52 {
53 if (\Bitrix\Landing\Transfer\AppConfiguration::inProcess())
54 {
55 return $manifest;
56 }
57
58 // necessary params
59 if (!isset($params['resultPage']))
60 {
61 return $manifest;
62 }
63
64 // force set action attribute for form after block add
65 $manifest['callbacks'] = array(
66 'afterAdd' => function (Block &$block) use($params)
67 {
68 $manifest = $block->getManifest();
69 $landingId = Search::getSearchResultPage(
70 $block->getSiteId(),
71 $params['resultPage']
72 );
73
74 if (!$landingId)
75 {
76 return;
77 }
78
79 // try to find url attrs and set default value
80 $attributeSelector = '';
81 foreach ($manifest['attrs'] as $selector => $item)
82 {
83 if (
84 $item['type'] == 'url' &&
85 $item['attribute'] == 'action'
86 )
87 {
88 $attributeSelector = $selector;
89 break;
90 }
91 }
92
93 $block->setAttributes([
94 $attributeSelector => [
95 'action' => '#landing' . $landingId
96 ]
97 ]);
98 $block->save();
99 },
100 );
101
102 return $manifest;
103 }
104
112 public static function prepareManifest(array $manifest, Block $block = null, array $params = [])
113 {
114 if (!isset($params['type']))
115 {
116 return $manifest;
117 }
118
119 if ($params['type'] == 'form')
120 {
121 return self::prepareForm($manifest, $params);
122 }
123
124 return $manifest;
125 }
126}
save(array $additionalFields=[])
Definition block.php:3136
getManifest($extended=false, $missCache=false, array $params=array())
Definition block.php:2117
static getList(array $params=array())
Definition site.php:1348
static prepareForm(array $manifest, array $params=[])
Definition search.php:51
static prepareManifest(array $manifest, Block $block=null, array $params=[])
Definition search.php:112
static getSearchResultPage($siteId, $tplCode)
Definition search.php:15