Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using included columns in the grid definition throws an exception if no data is present #85

Open
renttek opened this issue Oct 23, 2024 · 0 comments

Comments

@renttek
Copy link

renttek commented Oct 23, 2024

Using included columns will result in an \OutOfBoundsException being thrown, if the grid source does not return rows/data.
I looked into this issue in the scope of this issue: element119/module-admin-opcache-report#1 (comment)

<grid xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Hyva_Admin:etc/hyva-grid.xsd">
    <source>
        <arrayProvider>Element119\AdminOpCacheReport\Ui\DataProvider\OpCacheFlushLog</arrayProvider>
    </source>
    <columns>
        <include>
            <column name="log_id"/>
            <column name="admin_name"/>
            <column name="flushed_at"/>
        </include>
    </columns>
    <!-- -->
</grid>

image

The cause of this is, that when Hyva\Admin\Model\GridSource::extractColumnDefinitions() calls the method validateConfiguredKeys, it checks the included columns against all existing ones from the provider.
(See: https://github.com/hyva-themes/magento2-hyva-admin/blob/main/Model/GridSource.php#L77)

A simple workaround/hack I've been using (via a composer patch), is to ignore the validation if no data is present:

+        if ($allColumnKeys !== []) {
            $this->validateConfiguredKeys(keys($configuredColumns), $allColumnKeys);
+        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant