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

Saving in the backend doesn't trigger setUrlPath #101

Open
tschallacka opened this issue Dec 19, 2024 · 0 comments
Open

Saving in the backend doesn't trigger setUrlPath #101

tschallacka opened this issue Dec 19, 2024 · 0 comments
Assignees

Comments

@tschallacka
Copy link

tschallacka commented Dec 19, 2024

When saving in the backend, https://github.com/EmicoEcommerce/Magento2AttributeLanding/blob/master/src/Model/LandingPage.php#L165 doesn't get called, but
https://github.com/EmicoEcommerce/Magento2AttributeLanding/blob/master/src/Controller/Adminhtml/Page/Save.php#L136
setData via a call from $this->dataObjectHelper->populateWithArray($landingPage, $data, LandingPageInterface::class);

setData needs to be overwritten to catch the url key being changed and then the trim applied.

See vendor/magento/framework/Api/DataObjectHelper.php:125

if ($dataObject instanceof \Magento\Framework\Model\AbstractModel) {
            $simpleData = array_filter($data, static function ($e) {
                return is_scalar($e) || is_null($e);
            });
            if (isset($simpleData['id'])) {
                $dataObject->setId($simpleData['id']);
                unset($simpleData['id']);
            }
            $simpleData = array_intersect_key($simpleData, $setMethods);
            $dataObject->addData($simpleData);
            $data = array_diff_key($data, $simpleData);
            if (\count($data) === 0) {
                return $this;
            }
        }

See vendor/magento/framework/DataObject.php:53

    /**
     * Add data to the object.
     *
     * Retains previous data in the object.
     *
     * @param array $arr
     * @return $this
     */
    public function addData(array $arr)
    {
        if ($this->_data === []) {
            $this->setData($arr);
            return $this;
        }

        foreach ($arr as $index => $value) {
            $this->setData($index, $value);
        }
        return $this;
    }
    ```
    
    
@ah-net ah-net self-assigned this Jan 8, 2025
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

2 participants