Merge pull request #153 from wilr/wilr-patch-1

Support falsey values in alter (Fixes #152)
This commit is contained in:
Will Rossiter 2019-04-30 15:50:27 +12:00 committed by GitHub
commit 764a8f5bb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -52,13 +52,18 @@ class GoogleSitemapExtension extends DataExtension
return false;
}
// Allow override. In this case, since this can return multiple results, we'll use an "and" based policy.
// That is if any value is false then the current value will be false. Only only if all are true will we
// then return true.
// Allow override. invokeWithExtensions will either return a single result (true|false) if defined on the object
// or an array if on extensions.
$override = $this->owner->invokeWithExtensions('alterCanIncludeInGoogleSitemap', $can);
if ($override) {
$can = min($override, $can);
if ($override !== null) {
if (is_array($override)) {
if (!empty($override)) {
$can = min($override, $can);
}
} else {
$can = $override;
}
}
return $can;

View File

@ -60,6 +60,7 @@ class GoogleSitemapTest extends FunctionalTest
$this->assertFalse($unused->canIncludeInGoogleSitemap());
$used = $this->objFromFixture(TestDataObject::class, 'DataObjectTest2');
$this->assertTrue($used->canIncludeInGoogleSitemap());
}