5c: Add isPublishable method to article wrapper
Add the `isPublishable()` method to the article wrapper. This contains all of the logic that is used to determine if an article in publishable or not, and returns a boolean.
This commit is contained in:
parent
3ecca5ad0c
commit
b98d181a58
1 changed files with 11 additions and 1 deletions
|
@ -2,15 +2,18 @@
|
|||
|
||||
namespace Drupal\my_module\Wrapper;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
class ArticleWrapper {
|
||||
|
||||
private $article;
|
||||
private $time;
|
||||
|
||||
public function __construct(NodeInterface $node) {
|
||||
public function __construct(TimeInterface $time, NodeInterface $node) {
|
||||
$this->verifyNodeType($node);
|
||||
|
||||
$this->time = $time;
|
||||
$this->article = $node;
|
||||
}
|
||||
|
||||
|
@ -18,6 +21,13 @@ class ArticleWrapper {
|
|||
return $this->article;
|
||||
}
|
||||
|
||||
public function isPublishable(): bool {
|
||||
$created = $this->article->getCreatedTime();
|
||||
$difference = $this->time->getRequestTime() - $created;
|
||||
|
||||
return $difference >= 60 * 60 * 24 * 3;
|
||||
}
|
||||
|
||||
private function verifyNodeType(NodeInterface $node): void {
|
||||
if ($node->bundle() != 'article') {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue