wilr / silverstripe-googlesitemaps

Google Sitemaps module for the SilverStripe CMS
BSD 3-Clause "New" or "Revised" License
74 stars 95 forks source link

Handle cases such as 'Class.RelationName' #174

Closed wilr closed 4 years ago

obj63mc commented 4 years ago

When that is used I get the following -

[Warning] strpos() expects parameter 1 to be string, array given at line 166

My actual class is like the following so there are multiple many_many types on the class. Note I just worked around this by overwriting the ImagesForSitemap function in my blog post extension.

private static $many_many = [
    'Brands' => Brand::class,
    'Products' => Product::class,
    'RelatedArticles' => BlogPost::class
];

private static $many_many_extraFields = [
    'Brands' => [
      'SortOrder' => 'Int'
    ],
    'Products' => [
      'SortOrder' => 'Int'
    ],
    'RelatedArticles' => [
      'SortOrder' => 'Int'
    ],
];

private static $belongs_to = [
    'FeedItem' => FeedItem::class
];

private static $belongs_many_many = [
    'BlogPosts' => BlogPost::class.'.RelatedArticles',
    'Events' => Event::class,
    'Promotions' => Promotion::class
];

attached are screenshots of the full error messages returned from the error stacks.

Error1 Error2 Error3 Error4

obj63mc commented 4 years ago

When testing and further debugging I was able to get the following outputted when looking at what $type was -

array(3) { ["through"]=> string(35) "SilverStripe\CMS\Model\SiteTreeLink" ["from"]=> string(6) "Parent" ["to"]=> string(6) "Linked" }

wilr commented 4 years ago

@obj63mc Ah yep sorry just needed to move it after the through check.

obj63mc commented 4 years ago

With that last update, tested, all is working as expected now.

wilr commented 4 years ago

Thanks!