magento2: Inconsistent cms block validation and save methods

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]);
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 19 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Hello @vovayatsyuk

Thank you for your feedback and collaboration!

I am reopening this issue. It seems important part/cases were missed and we should consider it again