Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the source_model for a cms block chooser in magento?

I want to add a config field to my magento instance. You should be able to store a cms block in it.

<block translate="label">
    <label>Cms block</label>
    <frontend_type>select</frontend_type>
    <source_model>???</source_model>
    <sort_order>30</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</block>

But I only found the model for cms pages (adminhtml/system_config_source_cms_page).

What is the corresponding source_model for cms blocks?

like image 556
Simon Avatar asked Jul 09 '13 09:07

Simon


People also ask

What is CMS block in Magento?

CMS blocks allow you to share some information with your customers, announce special offers, sales, dicounts or just make your Magento 2 store pages more interesting and engaging.

How do I get CMS block data by Identifier in Magento 2?

You can get CMS Static Blocks collection by an identifier in Magento 2 by calling BlockRepositoryInterface interface. Magento\Cms\Api\BlockRepositoryInterface used for getting CMS Static Blocks in Magento 2.

How do I get CMS blocks in magento2?

Login to Magento 2, move to Content –> Blocks. Click “Add New Block“, add below information and save configuration. Enable Block: Enable the block. Block Title: Name of the block to easily identify the purpose of creating the block.

How do you call a CMS block in magento2?

login to magento admin. Open any cms page and write block code in content section. After using the block code phtml file will be called on cms page. If you want to call phtml file on all cms pages then you can create a layout file to achieve this.


2 Answers

I think class Mage_Cms_Model_Resource_Block_Collection works great for this:

                    <cms_block translate="label">
                      <label>Left template CMS block</label>
                      <frontend_type>select</frontend_type>
                      <source_model>cms/resource_block_collection</source_model>
                      <sort_order>0</sort_order>     
                      <show_in_default>1</show_in_default>
                      <show_in_website>0</show_in_website>
                      <show_in_store>0</show_in_store>
                    </cms_block>   
like image 171
Alex Shchur Avatar answered Oct 03 '22 20:10

Alex Shchur


There aren't any, but you can make yours :

class Your_Module_Model_System_Config_Source_Cms_Block
{
    protected $_options;

    public function toOptionArray()
    {
        if (!$this->_options) {
            $this->_options = Mage::getResourceModel('cms/block_collection')
                ->load()
                ->toOptionArray();
        }
        return $this->_options;
    }
}
like image 40
blmage Avatar answered Oct 03 '22 21:10

blmage