Provides specific access control for the comment entity type.
@Plugin(
id = "comment_default",
module = "comment",
label = @Translation("Comment selection"),
entity_types = {"comment"},
group = "default",
weight = 1
)
Expanded class hierarchy of CommentSelection
class CommentSelection extends SelectionBase {
/**
* Overrides SelectionBase::buildEntityQuery().
*/
public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
// Adding the 'comment_access' tag is sadly insufficient for comments:
// core requires us to also know about the concept of 'published' and
// 'unpublished'.
if (!user_access('administer comments')) {
$query
->condition('status', COMMENT_PUBLISHED);
}
return $query;
}
/**
* Overrides SelectionBase::entityQueryAlter().
*/
public function entityQueryAlter(SelectInterface $query) {
$tables = $query
->getTables();
$base_table = $tables['base_table']['alias'];
// The Comment module doesn't implement any proper comment access,
// and as a consequence doesn't make sure that comments cannot be viewed
// when the user doesn't have access to the node.
$node_alias = $query
->innerJoin('node_field_data', 'n', '%alias.nid = ' . $base_table . '.nid');
// Pass the query to the node access control.
$this
->reAlterQuery($query, 'node_access', $node_alias);
// Alas, the comment entity exposes a bundle, but doesn't have a bundle
// column in the database. We have to alter the query ourselves to go fetch
// the bundle.
$conditions =& $query
->conditions();
foreach ($conditions as $key => &$condition) {
if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'node_type') {
$condition['field'] = $node_alias . '.type';
foreach ($condition['value'] as &$value) {
if (substr($value, 0, 13) == 'comment_node_') {
$value = substr($value, 13);
}
}
break;
}
}
// Passing the query to node_query_node_access_alter() is sadly
// insufficient for nodes.
// @see SelectionEntityTypeNode::entityQueryAlter()
if (!user_access('bypass node access') && !count(module_implements('node_grants'))) {
$query
->condition($node_alias . '.status', 1);
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommentSelection:: |
public | function |
Overrides SelectionBase::buildEntityQuery(). Overrides SelectionBase:: |
|
CommentSelection:: |
public | function |
Overrides SelectionBase::entityQueryAlter(). Overrides SelectionBase:: |
|
SelectionBase:: |
protected | property | The entity object, or NULL | |
SelectionBase:: |
protected | property | The field array. | |
SelectionBase:: |
protected | property | The instance array. | |
SelectionBase:: |
public | function |
Implements SelectionInterface::countReferencableEntities(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function |
Implements SelectionInterface::getReferencableEntities(). Overrides SelectionInterface:: |
1 |
SelectionBase:: |
protected | function | Helper method: Passes a query to the alteration system again. | |
SelectionBase:: |
public static | function |
Implements SelectionInterface::settingsForm(). Overrides SelectionInterface:: |
2 |
SelectionBase:: |
public | function |
Implements SelectionInterface::validateAutocompleteInput(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function |
Implements SelectionInterface::validateReferencableEntities(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function | Constructs a SelectionBase object. |