Magento 2 Widgets – Get Widget Parameters as Array

magento2widget-instancewidgets

Is there a way to get all the widget parameters in an array instead of loading the data of a specific widget parameter like below?

$this->getData('widget_parameter_1');

So, something like:

$currentwidgetObject->getParameters();

Best Answer

Seems it was fairly easy:

$data = $this->getData();

Gives me an array with the widget type, widget parameters and the module name inside the block class as defined in widget.xml. All i had to to then was use regex to filter out the wanted parameters (which contain a partial common name).

public function filterParameters(){
    $data = $this->getData();
    $matches = preg_grep("/_col_block_/", array_keys($data));
    return array_intersect_key($data, array_flip($matches));
}

If anyone knows a cleaner solution then please share!