mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-29 07:59:31 +02:00
41 lines
933 B
PHP
41 lines
933 B
PHP
|
<?php
|
||
|
|
||
|
|
||
|
namespace SilverStripe\Forms\GridField;
|
||
|
|
||
|
use SilverStripe\Core\Injector\Injector;
|
||
|
|
||
|
/**
|
||
|
* A trait that makes a class able to consume and use a {@link GridFieldStateManagerInterface}
|
||
|
* implementation
|
||
|
*/
|
||
|
trait GridFieldStateAware
|
||
|
{
|
||
|
/**
|
||
|
* @var GridFieldStateManagerInterface
|
||
|
*/
|
||
|
protected $stateManager;
|
||
|
|
||
|
/**
|
||
|
* @param GridFieldStateManagerInterface $manager
|
||
|
* @return self
|
||
|
*/
|
||
|
public function setStateManager(GridFieldStateManagerInterface $manager): self
|
||
|
{
|
||
|
$this->stateManager = $manager;
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Fallback on the direct Injector access, but allow a custom implementation
|
||
|
* to be applied
|
||
|
*
|
||
|
* @return GridFieldStateManagerInterface
|
||
|
*/
|
||
|
public function getStateManager(): GridFieldStateManagerInterface
|
||
|
{
|
||
|
return $this->stateManager ?: Injector::inst()->get(GridFieldStateManagerInterface::class);
|
||
|
}
|
||
|
}
|