public function setLocation($referenceId, $position = self::LOCATION_AFTER)
    {
        $allow = [
            static::LOCATION_AFTER,
            static::LOCATION_BEFORE,
            static::LOCATION_FIRST_CHILD,
            static::LOCATION_LAST_CHILD,
        ];

        // Make sure the location is valid.
        if (!in_array($position, $allow)) {
            throw new \InvalidArgumentException(
                sprintf(
                    '%s::setLocation(%d, *%s*)',
                    get_class($this),
                    $referenceId,
                    $position
                )
            );
        }

        // Set the location properties.
        $this->location = $position;
        $this->locationId = $referenceId;

        return $this;
    }