protected function filterFields(Event $event) : void
    {
        $panelActions = (array)Configure::read('CsvMigrations.panels.actions');
        $dynamicPanelActions = (array)Configure::read('CsvMigrations.panels.dynamic_actions');
        if (!in_array($this->request->getParam('action'), array_diff($panelActions, $dynamicPanelActions))) {
            return;
        }

        $controller = $event->getSubject();
        Assert::isInstanceOf($controller, Controller::class);

        $config = new ModuleConfig(ConfigType::MODULE(), $controller->getName());
        $config = json_encode($config->parse());
        $config = false === $config ? [] : json_decode($config, true);

        $panels = $this->getPanels($config, $controller->viewVars['entity']->toArray());
        if (! empty($panels['fail'])) {
            // filter out fields of hidden panels
            $controller->viewVars['fields'] = array_diff_key(
                $controller->viewVars['fields'],
                array_flip($panels['fail'])
            );
        }

        if ((string)Configure::read('CsvMigrations.batch.action') === $this->request->getParam('action')) {
            $this->filterBatchFields($event);
        }
    }