/** * Get a record by its slug * * @param string $class * @param string $slug * @param int $excludeID Exclude this ID from searched slugs * @param bool $checkHistory * @return DataObject */ public static function getBySlug($class, $slug, $excludeID = null, $checkHistory = true) { /* @var $datalist DataList */ $datalist = $class::get()->filter('Slug', $slug); if ($excludeID) { $datalist = $datalist->exclude('ID', $excludeID); } $record = $datalist->first(); if ((!$record || !$record->exists()) && $checkHistory) { $historyRecord = SlugHistory::getRecordByClass($class, $slug, $excludeID); if ($historyRecord) { $record = $historyRecord; } } return $record; }