simplemap
simplemap copied to clipboard
Cannot use object of type ether\\simplemap\\models\\PartsLegacy as array
Description
I recently upgraded an inherited site to craft 3.6.17 and maps 3.9.1 and am now getting this error with the element-api.php and I'm not sure how to resolve this.
output json from element api is
{
"error": {
"code": 0,
"message": "Cannot use object of type ether\\simplemap\\models\\PartsLegacy as array"
}
}
and full element-api.php file
<?php
use craft\elements\Entry;
use craft\helpers\UrlHelper;
// use aelvan\imager\variables\ImagerVariable;
use spacecatninja\imagerx\variables\ImagerVariable;
return [
'endpoints' => [
'api/places/<entryId:\d+>.json' => function($entryId) {
return [
'elementType' => Entry::class,
'criteria' => ['id' => $entryId],
'pretty' => true,
'cache' => true,
'one' => true,
'transformer' => function(Entry $entry) {
$imager = new ImagerVariable();
$photoUrl = '';
foreach ($entry->thumbnailImage->all() as $photo) {
$photoOptions = array(
'width' => 900,
'height' => 600,
'mode' => 'fit',
'position' => $photo->getFocalPoint()
);
$transformedImage = $imager->transformImage($photo, $photoOptions);
$photoUrl = UrlHelper::baseUrl() . $transformedImage->getUrl();
}
$architect = array();
foreach ( $entry->people->all() as $person ) {
foreach ( $person->role->all() as $role ) {
if ( $role->slug == 'architect' ) {
$architect[] = array(
'name' => $person->title,
'url' => $person->getUrl()
);
}
}
}
$price = is_numeric($entry->price) ? '$' . number_format($entry->price) : $entry->price;
$addressParts = $entry->placeAddress->parts;
$address = $addressParts['street_number'] . ' ' . $addressParts['route_short'] . '<br />' . $addressParts['locality_short'] . ', ' . $addressParts['administrative_area_level_1_short'] . ', ' . $addressParts['postal_code_short'];
return [
'id' => $entry->id,
'title' => $entry->title,
'body' => $entry->body,
'forSale' => $entry->type->handle == 'propertyForSale',
'thumbnail' => $photoUrl,
'architect' => $architect,
'price' => $price,
'year' => $entry->yearBuilt,
'bedrooms' => $entry->bedrooms,
'bathrooms'=> $entry->bathrooms,
'listingAgent' => $entry->listingAgent,
'address' => $address,
];
}
];
}
]
];
If I remove anything with $address things work as expected. How can I resolve this?
Steps to reproduce
Additional info
- Craft version: 3.6.17
- Maps version: 3.9.1
- PHP version: 7.4
- Database driver & version: mysql 5.7
- Other Plugins: element API
Anyone? 6 days and no response?
@CreateSean does accessing the $addressParts
properties with ->
work? I.e. $addressParts->street_number
.
@jamesedmonston I don't know php and not sure where to update that line.
I tried replacing $addressParts = $entry->placeAddress->parts;
with $addressParts -> $entry->placeAddress->parts;
but that did not work.
please advise
@CreateSean Try changing the following line
$address = $addressParts['street_number'] . ' ' . $addressParts['route_short'] . '<br />' . $addressParts['locality_short'] . ', ' . $addressParts['administrative_area_level_1_short'] . ', ' . $addressParts['postal_code_short'];
To
$address = $addressParts->street_number . ' ' . $addressParts->route_short . '<br />' . $addressParts->locality_short . ', ' . $addressParts->administrative_area_level_1_short . ', ' . $addressParts->postal_code_short;
@jamesedmonston that did not work . I did however comment out that section and the error disappears