Skip to content

vt8.4 - Dashboard Widget layout not saving

Add some widgets to the Dashboard, then re-arrange them On page reload, they will be back in the original order. The modules/Vtiger/actions/SaveWidgetPositions.php line 30 attempts to iterate over the Vtiger_GuardedArray - but unfortunately that class is not currently iterable 😄

Can make the GuardedArray iterable with the following code in vtlib/Vtiger/utils/GuardedArray.php -

class Vtiger_GuardedArray implements \ArrayAccess, \Iterator {
    private $data;
    private $keys;
    private $position;

    function __construct($data = null) {
        $this->data = is_null($data) || $data === false ? array() : $data;
		if(is_array($this->data)) {
			$this->keys = array_keys($this->data);
		}else{
			$this->keys = [];
		}
        $this->position = 0;
    }

    #[\ReturnTypeWillChange]
    function offsetExists($key) {
        return isset($this->data[$key]) && array_key_exists($key, $this->data);
    }

    #[\ReturnTypeWillChange]
    function offsetGet($key) {
        if ($this->offsetExists($key)) {
            return $this->data[$key];
        }
        return null;
    }

    #[\ReturnTypeWillChange]
    function offsetSet($key, $value) {
        $this->data[$key] = $value;
    }

    #[\ReturnTypeWillChange]
    function offsetUnset($key) {
        unset($this->data[$key]);
    }

    // Iterator methods
    #[\ReturnTypeWillChange]
    public function rewind() {
        $this->keys = array_keys($this->data);
        $this->position = 0;
    }

    #[\ReturnTypeWillChange]
    public function current() {
        if (!$this->valid()) {
            return null;
        }
        $key = $this->keys[$this->position];
        return $this->data[$key];
    }

    #[\ReturnTypeWillChange]
    public function key() {
        if (!$this->valid()) {
            return null;
        }
        return $this->keys[$this->position];
    }

    #[\ReturnTypeWillChange]
    public function next() {
        ++$this->position;
    }

    #[\ReturnTypeWillChange]
    public function valid() {
        return isset($this->keys[$this->position]);
    }
}