How does block page whitelisting work? I've created a custom entity which only should to be displayed on pages provided by the user.

To handle multiple pages, I've created a textarea where the user can enter a page per line. Just like the blocks module.

My problem here is that I don't know how to make the query that loads the correct entity by page.

My guess is that it should be something like this:

SELECT * FROM {my_entity} WHERE pages LIKE :path

However, that leads to the problem that 'node/1/edit' also loads the entity when the user has entered 'node/1'.

I know this functionality already exists somewhere in Drupal because it is used for blocks, but I can't find it in the code...
The related code is found in block_block_list_alter() function, inside /modules/block/block.module file.

Here's how you would perform a similar check in your code:

// Get the pages to check. This should be in the same format as what Drupal
// core uses - meaning one path per line and you can use placeholders.
//
// Variable below is just as an example.
$pages_to_check = 'page1' . PHP_EOL . 'page2' . PHP_EOL . 'page3/*';
// This is a good practice, because it will make sure that paths are always
// checked consistently and won't depend on the case.
$pages = drupal_strtolower($pages_to_check);
// Compare the lowercase internal and lowercase path alias (if any).
$page_match = drupal_match_path($path, $pages);
if ($path != $_GET['q']) {
  $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
}
// Now you can do whatever you want based on whether or not the current path
// matches the pattern. For example:
if ($page_match) {
  // You are on one of the listed pages.
}
else {
  // You are not on one of the listed pages.
}


Hope this helps.