Skip to content

Commit

Permalink
Merge pull request #8 from wedevelopnl/feature/customer-flag
Browse files Browse the repository at this point in the history
feature/customer-flag: Added a flag to be able to disable using the customer model
  • Loading branch information
renskorswagen authored Dec 2, 2022
2 parents 1679831 + c6cfd15 commit 32ffcba
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ You can also link customers/categories to cases and create a collection with dif
## Installation
* `composer require wedevelopnl/silverstripe-portfolio`

## Feature Flags

### Customers
Managing and linking customers can be disabled using the following config in your project

```
---
Name: flags
After: portfolio
---
WeDevelop\Portfolio\Config:
customer_enabled: false
```

## License
See [License](LICENSE)

Expand Down
3 changes: 3 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ Name: portfolio
WeDevelop\Portfolio\Pages\PortfolioPage:
extensions:
- SilverStripe\Lumberjack\Model\LumberJack

WeDevelop\Portfolio\Config:
customer_enabled: true
12 changes: 12 additions & 0 deletions src/Admins/PortfolioAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Admin\ModelAdmin;
use WeDevelop\Portfolio\Models\Collection;
use WeDevelop\Portfolio\Models\Customer;
use WeDevelop\Portfolio\Config;

class PortfolioAdmin extends ModelAdmin
{
Expand All @@ -22,4 +23,15 @@ class PortfolioAdmin extends ModelAdmin
Customer::class,
Collection::class,
];

public function getManagedModels()
{
$models = parent::getManagedModels();

if (!Config::isCustomerEnabled()) {
unset($models[Customer::class]);
}

return $models;
}
}
23 changes: 23 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace WeDevelop\Portfolio;

use SilverStripe\Core\Config\Configurable;
use SilverStripe\View\TemplateGlobalProvider;

class Config implements TemplateGlobalProvider
{
use Configurable;

public static function isCustomerEnabled(): bool
{
return self::config()->get('customer_enabled');
}

public static function get_template_global_variables(): array
{
return [
'WeDevelopPortfolioConfigIsCustomerEnabled' => 'isCustomerEnabled'
];
}
}
5 changes: 5 additions & 0 deletions src/Pages/CasePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use WeDevelop\Portfolio\Models\Category;
use WeDevelop\Portfolio\Models\Collection;
use WeDevelop\Portfolio\Models\Customer;
use WeDevelop\Portfolio\Config;

/**
* @property DBDatetime $PublicationDate
Expand Down Expand Up @@ -96,6 +97,10 @@ public function getCMSFields(): FieldList
)->setHasEmptyDefault(true),
UploadField::create('Thumbnail', _t(__CLASS__ . '.THUMBNAIL', 'Thumbnail')),
]);

if (!Config::isCustomerEnabled()) {
$fields->removeByName('CustomerID');
}
});

return parent::getCMSFields();
Expand Down
2 changes: 1 addition & 1 deletion templates/WeDevelop/Portfolio/Pages/Layout/CasePage.ss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<li>$PublicationDate.Nice</li>
<% end_if %>
</ul>
<% if $Customer %>
<% if $Customer && $WeDevelopPortfolioConfigIsCustomerEnabled %>
<span>$Customer.Title</span><br/>
<% end_if %>
<hr />
Expand Down

0 comments on commit 32ffcba

Please sign in to comment.