class SelectionEntityTypeComment in Entity reference 8
Hierarchy
- class \Drupal\entityreference\Plugin\entityreference\selection\SelectionBase implements SelectionInterface
- class \Drupal\entityreference\Plugin\Type\Selection\SelectionEntityTypeComment
Expanded class hierarchy of SelectionEntityTypeComment
File
- lib/
Drupal/ entityreference/ Plugin/ Type/ Selection/ SelectionEntityTypeComment.php, line 17 - Definition of Drupal\entityreference\Plugin\entityreference\selection\SelectionEntityTypeComment.
Namespace
Drupal\entityreference\Plugin\Type\SelectionView source
class SelectionEntityTypeComment extends SelectionBase {
public function entityFieldQueryAlter(AlterableInterface $query) {
// 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')) {
$tables = $query
->getTables();
$query
->condition(key($tables) . '.status', COMMENT_PUBLISHED);
}
// 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.
$tables = $query
->getTables();
$base_table = key($tables);
$node_alias = $query
->innerJoin('node', '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 ourself 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 EntityReferenceHandler_node::entityFieldQueryAlter()
if (!user_access('bypass node access') && !count(module_implements('node_grants'))) {
$query
->condition($node_alias . '.status', 1);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SelectionBase:: |
protected | function | Build an EntityFieldQuery to get referencable entities. | 1 |
SelectionBase:: |
public | function |
Implements EntityReferenceHandler::countReferencableEntities(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function |
Implements EntityReferenceHandler::getReferencableEntities(). Overrides SelectionInterface:: |
|
SelectionBase:: |
protected | function | Helper method: pass a query to the alteration system again. | |
SelectionBase:: |
public static | function |
Implements EntityReferenceHandler::settingsForm(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function |
Implements EntityReferenceHandler::validateAutocompleteInput(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function |
Implements EntityReferenceHandler::validateReferencableEntities(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function | ||
SelectionEntityTypeComment:: |
public | function |
Implements EntityReferenceHandler::entityFieldQueryAlter(). Overrides SelectionBase:: |