| @@ 276-370 (lines=95) @@ | ||
| 273 | * @param \eZ\Publish\API\Repository\Values\Content\Location|LocationCollection $location |
|
| 274 | * @return boolean |
|
| 275 | */ |
|
| 276 | protected function setReferences($location, $step) |
|
| 277 | { |
|
| 278 | if (!array_key_exists('references', $step->dsl)) { |
|
| 279 | return false; |
|
| 280 | } |
|
| 281 | ||
| 282 | $references = $this->setReferencesCommon($location, $step->dsl['references']); |
|
| 283 | $location = $this->insureSingleEntity($location, $references); |
|
| 284 | ||
| 285 | foreach ($references as $reference) { |
|
| 286 | switch ($reference['attribute']) { |
|
| 287 | case 'location_id': |
|
| 288 | case 'id': |
|
| 289 | $value = $location->id; |
|
| 290 | break; |
|
| 291 | case 'remote_id': |
|
| 292 | case 'location_remote_id': |
|
| 293 | $value = $location->remoteId; |
|
| 294 | break; |
|
| 295 | case 'always_available': |
|
| 296 | $value = $location->contentInfo->alwaysAvailable; |
|
| 297 | break; |
|
| 298 | case 'content_id': |
|
| 299 | $value = $location->contentId; |
|
| 300 | break; |
|
| 301 | case 'content_type_id': |
|
| 302 | $value = $location->contentInfo->contentTypeId; |
|
| 303 | break; |
|
| 304 | case 'content_type_identifier': |
|
| 305 | $contentTypeService = $this->repository->getContentTypeService(); |
|
| 306 | $value = $contentTypeService->loadContentType($location->contentInfo->contentTypeId)->identifier; |
|
| 307 | break; |
|
| 308 | case 'current_version': |
|
| 309 | case 'current_version_no': |
|
| 310 | $value = $location->contentInfo->currentVersionNo; |
|
| 311 | break; |
|
| 312 | case 'depth': |
|
| 313 | $value = $location->depth; |
|
| 314 | break; |
|
| 315 | case 'is_hidden': |
|
| 316 | $value = $location->hidden; |
|
| 317 | break; |
|
| 318 | case 'main_location_id': |
|
| 319 | $value = $location->contentInfo->mainLocationId; |
|
| 320 | break; |
|
| 321 | case 'main_language_code': |
|
| 322 | $value = $location->contentInfo->mainLanguageCode; |
|
| 323 | break; |
|
| 324 | case 'modification_date': |
|
| 325 | $value = $location->contentInfo->modificationDate->getTimestamp(); |
|
| 326 | break; |
|
| 327 | case 'name': |
|
| 328 | $value = $location->contentInfo->name; |
|
| 329 | break; |
|
| 330 | case 'owner_id': |
|
| 331 | $value = $location->contentInfo->ownerId; |
|
| 332 | break; |
|
| 333 | case 'parent_location_id': |
|
| 334 | $value = $location->parentLocationId; |
|
| 335 | break; |
|
| 336 | case 'path': |
|
| 337 | $value = $location->pathString; |
|
| 338 | break; |
|
| 339 | case 'priority': |
|
| 340 | $value = $location->priority; |
|
| 341 | break; |
|
| 342 | case 'publication_date': |
|
| 343 | $value = $location->contentInfo->publishedDate->getTimestamp(); |
|
| 344 | break; |
|
| 345 | case 'section_id': |
|
| 346 | $value = $location->contentInfo->sectionId; |
|
| 347 | break; |
|
| 348 | case 'section_identifier': |
|
| 349 | $sectionService = $this->repository->getSectionService(); |
|
| 350 | $value = $sectionService->loadSection($location->contentInfo->sectionId)->identifier; |
|
| 351 | break; |
|
| 352 | case 'sort_field': |
|
| 353 | $value = $this->sortConverter->sortField2Hash($location->sortField); |
|
| 354 | break; |
|
| 355 | case 'sort_order': |
|
| 356 | $value = $this->sortConverter->sortOrder2Hash($location->sortOrder); |
|
| 357 | break; |
|
| 358 | default: |
|
| 359 | throw new \InvalidArgumentException('Location Manager does not support setting references for attribute ' . $reference['attribute']); |
|
| 360 | } |
|
| 361 | ||
| 362 | $overwrite = false; |
|
| 363 | if (isset($reference['overwrite'])) { |
|
| 364 | $overwrite = $reference['overwrite']; |
|
| 365 | } |
|
| 366 | $this->referenceResolver->addReference($reference['identifier'], $value, $overwrite); |
|
| 367 | } |
|
| 368 | ||
| 369 | return true; |
|
| 370 | } |
|
| 371 | ||
| 372 | /** |
|
| 373 | * @param int|string|array $locationKey |
|
| @@ 116-211 (lines=96) @@ | ||
| 113 | * @throws \InvalidArgumentException When trying to set a reference to an unsupported attribute |
|
| 114 | * @return boolean |
|
| 115 | */ |
|
| 116 | protected function setReferences($item, $step) |
|
| 117 | { |
|
| 118 | if (!array_key_exists('references', $step->dsl)) { |
|
| 119 | return false; |
|
| 120 | } |
|
| 121 | ||
| 122 | $references = $this->setReferencesCommon($item, $step->dsl['references']); |
|
| 123 | $item = $this->insureSingleEntity($item, $references); |
|
| 124 | ||
| 125 | foreach ($references as $reference) { |
|
| 126 | switch ($reference['attribute']) { |
|
| 127 | // a trashed item extends a location, so in theory everything 'location' here should work |
|
| 128 | case 'location_id': |
|
| 129 | case 'id': |
|
| 130 | $value = $item->id; |
|
| 131 | break; |
|
| 132 | case 'remote_id': |
|
| 133 | case 'location_remote_id': |
|
| 134 | $value = $item->remoteId; |
|
| 135 | break; |
|
| 136 | case 'always_available': |
|
| 137 | $value = $item->contentInfo->alwaysAvailable; |
|
| 138 | break; |
|
| 139 | case 'content_id': |
|
| 140 | $value = $item->contentId; |
|
| 141 | break; |
|
| 142 | case 'content_type_id': |
|
| 143 | $value = $item->contentInfo->contentTypeId; |
|
| 144 | break; |
|
| 145 | case 'content_type_identifier': |
|
| 146 | $contentTypeService = $this->repository->getContentTypeService(); |
|
| 147 | $value = $contentTypeService->loadContentType($item->contentInfo->contentTypeId)->identifier; |
|
| 148 | break; |
|
| 149 | case 'current_version': |
|
| 150 | case 'current_version_no': |
|
| 151 | $value = $item->contentInfo->currentVersionNo; |
|
| 152 | break; |
|
| 153 | case 'depth': |
|
| 154 | $value = $item->depth; |
|
| 155 | break; |
|
| 156 | case 'is_hidden': |
|
| 157 | $value = $item->hidden; |
|
| 158 | break; |
|
| 159 | case 'main_location_id': |
|
| 160 | $value = $item->contentInfo->mainLocationId; |
|
| 161 | break; |
|
| 162 | case 'main_language_code': |
|
| 163 | $value = $item->contentInfo->mainLanguageCode; |
|
| 164 | break; |
|
| 165 | case 'modification_date': |
|
| 166 | $value = $item->contentInfo->modificationDate->getTimestamp(); |
|
| 167 | break; |
|
| 168 | case 'name': |
|
| 169 | $value = $item->contentInfo->name; |
|
| 170 | break; |
|
| 171 | case 'owner_id': |
|
| 172 | $value = $item->contentInfo->ownerId; |
|
| 173 | break; |
|
| 174 | case 'parent_location_id': |
|
| 175 | $value = $item->parentLocationId; |
|
| 176 | break; |
|
| 177 | case 'path': |
|
| 178 | $value = $item->pathString; |
|
| 179 | break; |
|
| 180 | case 'priority': |
|
| 181 | $value = $item->priority; |
|
| 182 | break; |
|
| 183 | case 'publication_date': |
|
| 184 | $value = $item->contentInfo->publishedDate->getTimestamp(); |
|
| 185 | break; |
|
| 186 | case 'section_id': |
|
| 187 | $value = $item->contentInfo->sectionId; |
|
| 188 | break; |
|
| 189 | case 'section_identifier': |
|
| 190 | $sectionService = $this->repository->getSectionService(); |
|
| 191 | $value = $sectionService->loadSection($item->contentInfo->sectionId)->identifier; |
|
| 192 | break; |
|
| 193 | case 'sort_field': |
|
| 194 | $value = $this->sortConverter->sortField2Hash($item->sortField); |
|
| 195 | break; |
|
| 196 | case 'sort_order': |
|
| 197 | $value = $this->sortConverter->sortOrder2Hash($item->sortOrder); |
|
| 198 | break; |
|
| 199 | default: |
|
| 200 | throw new \InvalidArgumentException('Trash Manager does not support setting references for attribute ' . $reference['attribute']); |
|
| 201 | } |
|
| 202 | ||
| 203 | $overwrite = false; |
|
| 204 | if (isset($reference['overwrite'])) { |
|
| 205 | $overwrite = $reference['overwrite']; |
|
| 206 | } |
|
| 207 | $this->referenceResolver->addReference($reference['identifier'], $value, $overwrite); |
|
| 208 | } |
|
| 209 | ||
| 210 | return true; |
|
| 211 | } |
|
| 212 | } |
|
| 213 | ||