开发者

Preconfigured Magento Widgets

Is there a UI or programatic system for taking advantage of the "Preconfigured Widget" functionality that's part of Magento's CMS page rendering?

When adding a widget to a CMS page, the code that renders that widget is located in the template directive processing class. This code

File: app/code/core/Mage/Widget/Model/Template/Filter.php
class Mage_Adminhtml_Cms_PageController extends Mage_Adminhtml_Controller_Action
{
    ...
}

When loading a Widget's paramaters, there the following bit of code

// validate required parameter type or id
if (!empty($params['type'])) {
    $type = $params['type'];
} elseif (!empty($params['id'])) {
    $preconfigured = Mage::getResourceSingle开发者_JAVA技巧ton('widget/widget')
        ->loadPreconfiguredWidget($params['id']);

    $type = $preconfigured['type'];
    $params = $preconfigured['parameters'];

} else {
    return '';
}

This code appears to parse a widget directive tag for an id value

{{widget name="foobazbar" id=""}}

and then load the configuration from a widget model

public function loadPreconfiguredWidget($widgetId)
{
    $read = $this->_getReadAdapter();
    $select = $read->select();
    $select->from($this->getMainTable())
        ->where($this->getIdFieldName() . ' = ?', $widgetId);
    var_dump((string)$select);
    $widget = $read->fetchRow($select);
    if (is_array($widget)) {
        if ($widget['parameters']) {
            $widget['parameters'] = unserialize($widget['parameters']);
        }
        return $widget;
    }
    return false;
}

When I first encountered this code, I assumed it was loading up a Widget Instance model. However, it's not. Instead it's loading data from a widget/widget class, which corresponds to the widget table.

mysql> describe widget;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| widget_id  | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| code       | varchar(255)     | NO   | MUL | NULL    |                |
| type       | varchar(255)     | NO   |     | NULL    |                |
| parameters | text             | YES  |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+

Is there a UI or system for adding data to this table? Does anyone (who works fro Magento Inc. or not) know if this is a supported feature, or if it's the start of something that's been abandoned, but left in for backward compatibility reasons?


This answer is somewhat off-topic, but I'm not sure if it might satisfy your need anyway. I've discovered that you can create widget instances in the admin CMS>Widgets section, and then render them via the following code:

$oWidget = Mage::getModel('widget/widget_instance')->load('HomepageTwitter','title');
$oWidgetBlock = Mage::app()->getLayout()->createBlock($oWidget->getType(), $oWidget->getTitle(), $oWidget->getWidgetParameters());
echo $oWidgetBlock->toHtml();

Note that the block is loaded by title (rather than arbitrary ID), and that the widget parameters are passed for the Block to render.


Per several comments, and private emails, it appears this is a privatish feature for the Magento core team, and has nothing to do with Instance Widgets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜