1 | <?php |
||
25 | class ElementIndexMapper extends BaseComponent implements MapperInterface |
||
26 | { |
||
27 | /** |
||
28 | * Load sources behaviors. |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | 2 | public function behaviors(): array |
|
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 1 | public function export(array $elementTypes): array |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 1 | public function import(array $settingDefinitions, array $elementTypes): array |
|
60 | { |
||
61 | 1 | $this->resetCraftEditableSectionsCache(); |
|
62 | |||
63 | 1 | foreach ($settingDefinitions as $elementTypeName => $settings) { |
|
64 | 1 | $elementType = 'craft\\elements\\'.$elementTypeName; |
|
65 | 1 | $mappedSettings = $this->getMappedSettings($settings, 'handle', 'id'); |
|
66 | 1 | if (!Craft::$app->elementIndexes->saveSettings($elementType, $mappedSettings)) { |
|
67 | 1 | Schematic::error(' - Settings for '.$elementTypeName.' could not be saved'); |
|
68 | } |
||
69 | } |
||
70 | |||
71 | 1 | return []; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Get mapped element index settings, converting source ids to handles or back again. |
||
76 | * |
||
77 | * @param array $settings |
||
78 | * @param string $fromIndex |
||
79 | * @param string $toIndex |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | 2 | private function getMappedSettings(array $settings, $fromIndex, $toIndex) |
|
107 | |||
108 | /** |
||
109 | * Reset craft editable sections cache using reflection. |
||
110 | */ |
||
111 | 1 | private function resetCraftEditableSectionsCache() |
|
121 | } |
||
122 |