function simplemeta_meta_load_by_path in Simple Meta 8.2
Same name and namespace in other branches
- 8 simplemeta.module \simplemeta_meta_load_by_path()
- 6.2 simplemeta.module \simplemeta_meta_load_by_path()
- 7.2 simplemeta.module \simplemeta_meta_load_by_path()
- 7 simplemeta.module \simplemeta_meta_load_by_path()
Load SimpleMeta entity by path.
Parameters
string|array $path: Single path or list of paths.
string $langcode: Language code.
Return value
\Drupal\Core\Entity\EntityInterface|false SimpleMeta metadata object or FALSE on failure.
1 call to simplemeta_meta_load_by_path()
- simplemeta_get_page_meta in ./
simplemeta.module - Get SimpleMeta entity for a page, by path.
File
- ./
simplemeta.module, line 101 - Contains simplemeta.module.
Code
function simplemeta_meta_load_by_path($path, $langcode = NULL) {
if (!isset($langcode)) {
$langcode = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
}
$condition = is_array($path) ? 'IN' : '=';
$query = \Drupal::entityQuery('simplemeta');
$query
->condition('url', $path, $condition);
$query
->condition('langcode', $langcode);
$query
->range(0, 1);
if ($condition == 'IN') {
$query
->sort('fit', 'DESC');
}
$result = $query
->execute();
if (!empty($result)) {
return SimplemetaEntity::load(reset($result));
}
return FALSE;
}