-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49ac2b0
commit a323d51
Showing
9 changed files
with
215 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Drupal\embargo\Event; | ||
|
||
use Drupal\Core\Database\Query\ConditionInterface; | ||
use Drupal\Core\Database\Query\SelectInterface; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* Abstract base tag event class. | ||
*/ | ||
abstract class AbstractTagEvent extends Event { | ||
|
||
/** | ||
* The build condition. | ||
* | ||
* @var \Drupal\Core\Database\Query\ConditionInterface | ||
*/ | ||
protected ConditionInterface $condition; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct( | ||
protected SelectInterface $query, | ||
) { | ||
$this->condition = $this->query->orConditionGroup(); | ||
} | ||
|
||
/** | ||
* Get the query upon which to act. | ||
* | ||
* @return \Drupal\Core\Database\Query\SelectInterface | ||
* The query upon which we are to act. | ||
*/ | ||
public function getQuery() : SelectInterface { | ||
return $this->query; | ||
} | ||
|
||
/** | ||
* Get the current condition. | ||
* | ||
* @return \Drupal\Core\Database\Query\ConditionInterface | ||
* The current condition. | ||
*/ | ||
public function getCondition() : ConditionInterface { | ||
return $this->condition; | ||
} | ||
|
||
/** | ||
* Get the base "embargo" table alias. | ||
* | ||
* @return string | ||
* The base "embargo" alias, as used in the query. | ||
*/ | ||
public function getEmbargoAlias() : string { | ||
return $this->query->getMetaData('embargo_alias'); | ||
} | ||
|
||
/** | ||
* Get the base query columns representing node IDs to find embargoes. | ||
* | ||
* @return string[] | ||
* The column aliases representing node IDs. | ||
*/ | ||
public function getTargetAliases() : array { | ||
return $this->query->getMetaData('embargo_target_aliases'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Drupal\embargo\Event; | ||
|
||
/** | ||
* Enumerate our event types. | ||
*/ | ||
final class EmbargoEvents { | ||
|
||
const TAG_INCLUSION = TagInclusionEvent::class; | ||
|
||
const TAG_EXCLUSION = TagExclusionEvent::class; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Drupal\embargo\Event; | ||
|
||
/** | ||
* Query tagging exclusion event. | ||
*/ | ||
class TagExclusionEvent extends AbstractTagEvent { | ||
|
||
/** | ||
* Get the "unexpired" embargo alias. | ||
* | ||
* @return string | ||
* The table alias. | ||
*/ | ||
public function getUnexpiredAlias() : string { | ||
return $this->query->getMetaData('embargo_unexpired_alias'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Drupal\embargo\Event; | ||
|
||
/** | ||
* Query tagging inclusion event. | ||
*/ | ||
class TagInclusionEvent extends AbstractTagEvent { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Drupal\embargo\EventSubscriber; | ||
|
||
use Drupal\embargo\Event\EmbargoEvents; | ||
use Drupal\embargo\Event\TagExclusionEvent; | ||
use Drupal\embargo\Event\TagInclusionEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Query tagging event subscriber. | ||
*/ | ||
class TaggingEventSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() : array { | ||
return [ | ||
EmbargoEvents::TAG_INCLUSION => 'inclusion', | ||
EmbargoEvents::TAG_EXCLUSION => 'exclusion', | ||
]; | ||
} | ||
|
||
/** | ||
* Event handler; tagging inclusion event. | ||
* | ||
* @param \Drupal\embargo\Event\TagInclusionEvent $event | ||
* The event being handled. | ||
*/ | ||
public function inclusion(TagInclusionEvent $event) : void { | ||
$event->getCondition()->where(strtr('!field IN (!targets)', [ | ||
'!field' => "{$event->getEmbargoAlias()}.embargoed_node", | ||
'!targets' => implode(', ', $event->getTargetAliases()), | ||
])); | ||
} | ||
|
||
/** | ||
* Event handler; tagging exclusion event. | ||
* | ||
* @param \Drupal\embargo\Event\TagExclusionEvent $event | ||
* The event being handled. | ||
*/ | ||
public function exclusion(TagExclusionEvent $event) : void { | ||
$event->getCondition()->where("{$event->getUnexpiredAlias()}.embargoed_node = {$event->getEmbargoAlias()}.embargoed_node"); | ||
} | ||
|
||
} |