eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Handler::delete PHP Méthode

delete() public méthode

Deletes a object state. The state of the content objects is reset to the first object state in the group.
public delete ( mixed $stateId )
$stateId mixed
    public function delete($stateId)
    {
        // Get the object state first as we need group ID
        // to reorder the priorities and reassign content to another state in the group
        $objectState = $this->load($stateId);
        $this->objectStateGateway->deleteObjectState($objectState->id);
        $remainingStates = $this->loadObjectStates($objectState->groupId);
        if (empty($remainingStates)) {
            // If there are no more states in the group, just remove the state links
            $this->objectStateGateway->deleteObjectStateLinks($objectState->id);
            return;
        }
        $priority = 0;
        foreach ($remainingStates as $remainingState) {
            $this->objectStateGateway->updateObjectStatePriority($remainingState->id, $priority);
            ++$priority;
        }
        $remainingStates = $this->loadObjectStates($objectState->groupId);
        $this->objectStateGateway->updateObjectStateLinks($objectState->id, current($remainingStates)->id);
    }