/** * Limit CMS block save * * @param Mage_Cms_Model_Block $model */ public function cmsBlockSaveBefore($model) { $originalStoreIds = $model->getResource()->lookupStoreIds($model->getId()); if ($model->getId() && !$this->_role->hasStoreAccess($originalStoreIds)) { $this->_throwSave(); } if (!$this->_role->hasExclusiveStoreAccess($originalStoreIds)) { $this->_throwSave(); } $model->setData('stores', $this->_forceAssignToStore($this->_updateSavingStoreIds($model->getData('stores'), $originalStoreIds))); }
/** * Should return list of tags to clean * * @param Mage_Cms_Model_Block $object * @return string[]|string */ protected function _collectTags($object) { if ($object instanceof Mage_Cms_Model_Block) { return self::TAG_PREFIX . $object->getIdentifier(); } return self::TAG_PREFIX . $object->getId(); }
/** * @magentoDataFixture Mage/Cms/_files/block.php * @magentoDataFixture Mage/Core/_files/variable.php * @magentoConfigFixture current_store web/unsecure/base_url http://example.com/ * @magentoConfigFixture current_store web/unsecure/base_link_url http://example.com/ */ public function testToHtml() { $cmsBlock = new Mage_Cms_Model_Block(); $cmsBlock->load('fixture_block', 'identifier'); $block = new Mage_Cms_Block_Block(); $block->setBlockId($cmsBlock->getId()); $result = $block->toHtml(); $this->assertContains('<a href="http://example.com/', $result); $this->assertContains('<p>Config value: "http://example.com/".</p>', $result); $this->assertContains('<p>Custom variable: "HTML Value".</p>', $result); }
private function _processBlock($identifier, Mage_Cms_Model_Block $block, $data) { $canSave = false; // Load block model if (!$block->getId()) { $block = Mage::getModel('cms/block'); $block->setIdentifier($identifier); } unset($data['contents']); if (isset($data['stores'])) { // Loop through the store view names to get its corresponding ID $storeIds = array(); foreach ($data['stores'] as $storeViewName) { $store = Mage::getModel('core/store')->load($storeViewName, 'code'); if (!$store->getId()) { throw new Exception("Store View Name: {$storeViewName} does not exist for {$identifier}"); } $storeIds[] = $store->getId(); unset($store); } unset($storeViewName); // @todo check what stores it is associated to already $oldStoreIds = Mage::getModel('cms/block')->load($block->getId())->getStoreId(); sort($storeIds); if ($oldStoreIds != $storeIds) { $canSave = true; $block->setStores($storeIds); } unset($oldStoreIds); unset($storeIds); unset($data['stores']); } else { $block->setStores(array(0)); } // Loop through block attributes foreach ($data as $key => $value) { // content file attribute would require to read it from a file if ($key == "content_file") { // If a value/path is set then get its contents if ($value != "") { // locate file path $filePath = Mage::getBaseDir() . DS . 'app' . DS . 'etc' . DS . 'components' . DS . 'html' . DS . $value; // Check if the file exists if (file_exists($filePath)) { // Get the contents of the file and save it as the value $value = file_get_contents($filePath); unset($filePath); $key = 'content'; } else { throw new Exception("No file found in {$filePath}"); } } else { continue; } } // If the value is already equal to the value in the database, skip it if ($block->getData($key) == $value) { continue; } $canSave = true; $block->setData($key, $value); $this->log("Setting block attribute {$key} to {$value} for {$identifier}"); } if ($canSave) { $block->save(); $this->log("Saved block {$identifier}"); } }