addFilterField($index, '_versionedstage', [ 'name' => '_versionedstage', 'field' => '_versionedstage', 'fullfield' => '_versionedstage', 'base' => DataObject::getSchema()->baseDataClass($class), 'origin' => $class, 'type' => 'String', 'lookup_chain' => [ [ 'call' => 'variant', 'variant' => get_class($this), 'method' => 'currentState' ] ] ]); } public function alterQuery($query, $index) { $query->filter('_versionedstage', [ $this->currentState(), SearchQuery::$missing ]); } public function extractManipulationState(&$manipulation) { $self = get_class($this); foreach ($manipulation as $table => $details) { $class = $details['class']; $stage = Versioned::DRAFT; if (preg_match('/^(.*)_' . Versioned::LIVE . '$/', $table, $matches)) { $class = DataObject::getSchema()->tableClass($matches[1]); $stage = Versioned::LIVE; } if (ClassInfo::exists($class) && $this->appliesTo($class, false)) { $manipulation[$table]['class'] = $class; $manipulation[$table]['state'][$self] = $stage; } } } public function extractStates(&$table, &$ids, &$fields) { $class = $table; $suffix = null; if (ClassInfo::exists($class) && $this->appliesTo($class, false)) { $table = $class; $self = get_class($this); foreach ($ids as $i => $statefulid) { $ids[$i]['state'][$self] = $suffix ? $suffix : Versioned::DRAFT; } } } }