8000 [Bug] Using reset to get the first element of the validlayouts by mattamon · Pull Request #14160 · pimcore/pimcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Bug] Using reset to get the first element of the validlayouts #14160

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

Merged
merged 2 commits into from
Feb 1, 2023

Conversation

mattamon
Copy link
Contributor

Changes in this pull request

Resolves #14144

Additional info

validLayouts is using string keys and does not have int indexes so $validLayouts[0]->getId() would generate an error.
Using reset now to get the first layout.

@mattamon mattamon added the Bug label Jan 27, 2023
@mattamon mattamon added this to the 10.5.16 milestone Jan 27, 2023
@mattamon mattamon requested a review from robertSt7 January 27, 2023 07:49
@mattamon mattamon linked an issue Jan 27, 2023 that may be closed by this pull request
@github-actions
Copy link
github-actions bot commented Jan 27, 2023

Review Checklist

  • Target branch (10.5 for bug fixes, others 11.x)
  • Tests (if it's testable code, there should be a test for it - get help)
  • Docs (every functionality needs to be documented, see here)
  • Migration incl. install.sql (e.g. if the database schema changes, ...)
  • Upgrade notes (deprecations, important information, migration hints, ...)
  • Label
  • Milestone

@blankse
Copy link
Contributor
blankse commented Jan 27, 2023

We should also change the phpdoc of DataObject\Service::getValidLayouts() to this:

    /**
     * @return array<string, DataObject\ClassDefinition\CustomLayout>
     */
    public static function getValidLayouts(Concrete $object): array
    {

With this change phpstan would noticed this error:

 ------ ------------------------------------------------------------------------------------------------------------
  Line   bundles/AdminBundle/src/Controller/Admin/DataObject/DataObjectController.php
 ------ ------------------------------------------------------------------------------------------------------------
  513    Offset 0 does not exist on non-empty-array<string, Pimcore\Model\DataObject\ClassDefinition\CustomLayout>.
 ------ ------------------------------------------------------------------------------------------------------------

 [ERROR] Found 1 error

@BlackbitDevs
Copy link
Contributor

This now causes that by default for admin users the Master (Admin Mode) gets loaded because reset($validLayouts) refers to -1 in

if ($user->getAdmin()) {
$superLayout = new ClassDefinition\CustomLayout();
$superLayout->setId('-1');
$superLayout->setName('Master (Admin Mode)');
$resultList[-1] = $superLayout;
}
if ($isMasterAllowed) {
$master = new ClassDefinition\CustomLayout();
$master->setId('0');
$master->setName('Master');
$resultList[0] = $master;
}

Will create a PR which uses [0] by default but falls back to reset($validLayouts) if this does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: getId() on null when no default layout is available
4 participants
0