Skip to content

Inconsistent cms block validation and save methods #4831

Closed
@vovayatsyuk

Description

@vovayatsyuk

Additional information

The issue was reopened on 16 July 2019.
The reopening reason is that current behavior(after fixes) brings new issues. See comment for details

  1. Currently, I have to re-save an existing block (select every store view except one manually) and only after that, I can finally create a block for a specific store view.
  2. Previously, I could add a new block and it just works. Magento correctly used the fallback mechanism to show the correct block at every store view.

Additionally, when using a new approach, if I'll create a new store view I have to open cms block again and select newly created store view in store views combo box. Previously all work flawlessly because I always had a default block saved with "All store views" selected.

Preconditions

Magento develop branch

Steps to reproduce

  1. Install Magento from develop branch.
  2. Make sure that you have only one store view and SingleStoreMode option in disabled
  3. Create cms block example for All Store views
  4. Create another cms block example for first store view only

Expected result

  1. Block should be saved for selected store view

Actual result

  1. An exception will be thrown:

    A block identifier with the same properties already exists in the selected store.
    

Propose

Validator should validate actual block data, so we can remove the following check completely:

if ($this->_storeManager->hasSingleStore()) {
    $stores = [Store::DEFAULT_STORE_ID];
}

https://github.com/magento/magento2/blob/develop/app/code/Magento/Cms/Model/ResourceModel/Block.php#L186-L188

OR

this logic should be moved to _beforeSave and slightly modified, to check SingleStoreMode option:

if ($this->_storeManager->getSingleStoreMode()) {
    $object->setData('stores', [Store::DEFAULT_STORE_ID]);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CmsIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions