Skip to content

Commit

Permalink
Merge pull request #11 from essexcountycouncil/bugfix/ECCI-528
Browse files Browse the repository at this point in the history
ECCI-528: Add accessCheck() to entity query. Coding standards.
  • Loading branch information
Polynya committed Dec 6, 2023
2 parents 4f98504 + 6b60071 commit f1963c7
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\Core\Entity\Query\QueryInterface;

/**
* Base class for content entity reference selection.
*/
class ContentOwnershipSelectionBase extends DefaultSelection {

/**
* @var array list of valid roles to filter.
*/
public array $roles = [];
/**
* List of valid roles to filter.
*
* @var array
*/
public array $roles = [];

/**
* The entity type manager.
Expand All @@ -27,15 +32,14 @@ class ContentOwnershipSelectionBase extends DefaultSelection {
* Text to match the label against.
* @param string $match_operator
* The operation the matching should be done with.
* @param int $eventId
* The current enitity id.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* The query object that can query the given entity type.
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS'): QueryInterface {
$query = $this->entityTypeManager->getStorage('content_owner_sme')->getQuery();
$query->condition('role', $this->roles, 'IN');
$query->accessCheck();

if (isset($match)) {
$query->condition('name', $match, $match_operator);
Expand Down Expand Up @@ -74,4 +78,5 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA

return $options;
}

}

0 comments on commit f1963c7

Please sign in to comment.