Created
October 31, 2012 19:04
-
-
Save amitaibu/3989148 to your computer and use it in GitHub Desktop.
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
/** | |
* Implements hook_init(). | |
*/ | |
function foo_init() { | |
$field = field_info_field('bar'); | |
$instance = field_info_instance('node', 'bar', 'baz'); | |
// This will call SelectionBase | |
$handler = entity_reference_get_selection_handler($field, $instance); | |
$ids = $handler->getReferencableEntities(); | |
} | |
class SelectionBase implements SelectionInterface { | |
/** | |
* Returns a list of referencable entities. | |
*/ | |
public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { | |
// ... | |
$query = $this->buildEntityFieldQuery($match, $match_operator); | |
} | |
/** | |
* Builds an EntityFieldQuery to get referencable entities. | |
*/ | |
protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { | |
//... | |
// Add a generic entity access tag to the query. | |
//$query->addMetaData('field', $this->field); | |
//$query->addMetaData('entity_reference_selection_handler', $this); | |
// ... | |
} | |
} | |
/** | |
* Implements hook_query_TAG_alter(). | |
*/ | |
function entity_reference_query_entity_reference_alter(AlterableInterface $query) { | |
$handler = $query->getMetadata('entity_reference_selection_handler'); | |
// Alter the query to fix entity access per entity-type. | |
$handler->entityFieldQueryAlter($query); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment