Giter Site home page Giter Site logo

jarlssen_chooserwidget's Introduction

Jarlssen_ChooserWidget

Magento extension that gives the ability to create Product, Category, CMS Page and Static Block choosers in generic admin forms.

Here you can read my original blog post about the extension: http://www.jarlssen.de/blog/2014/04/24/magento-chooser-widget-add-edit-admin-forms

There are 4 important things you need to do to make the chooser work:

It's required to add in the layout update a handle called "editor". This handle includes the JS logic that is needed to render the chooser popups

<?xml version="1.0"?>
<layout>

    <adminhtml_my_module_item_edit>
        <reference name="content">
            <block type="my_module/adminhtml_item_edit" name="item_edit" />
        </reference>
        <update handle="editor"/>
    </adminhtml_my_module_item_edit>

</layout>

After that in method _prepareForm() of your admin form you need to have an instance of helper 'jarlssen_chooser_widget/chooser' and pass some parameters to the function creating the chooser.

Use any of the chooser create functions of Jarlssen_ChooserWidget_Helper_Chooser:

  • createProductChooser
  • createCategoryChooser
  • createCmsPageChooser
  • createCmsBlockChooser
  • createChooser

There is a required config value called "input_name" and must be passed to the chooser through a configuration array.

The function creating the chooser accepts the following parameters:

  • $model - instance of Mage_Core_Model_Abstract - the current entity
  • $fieldset - instance of Varien_Data_Form_Element_Fieldset - It’s required, because we create the chooser in this fieldset
  • $config - array of the widget configuration, the element “input_name” is required, because this is the name of the field name, that we save after form submit.
  • $blockAlias - this parameter is used only when we invoke Jarlssen_ChooserWidget_Helper_Chooser::createChooser and it’s useful for creating our own custom chooser

The array $config also can contain more elements, but they are not mandatory:

  • 'input_label' - The text of the input label
  • 'button_text' - The text of the chooser button
  • 'required' - If it’s true, then we will have frontend validation and to pass it we need to choose something from the chooser
  • 'input_id' - If you don't specify this parameter the input id will be same as the input name. Thanks to @bmcg for his pull request. He found, that useful when he want's to have input name, that contains square brackets.

Example of config array:

$categoryConfig = array(
    'input_name'  => 'entity_link',
    'input_label' => $this->__('Product'),
    'button_text' => $this->__('Select Product...'),
    'required'    => true,
    'input_id'    => 'my_custom_id'
);

Code Examples

Product Chooser:

$chooserHelper = Mage::helper('jarlssen_chooser_widget/chooser');
 
$productConfig = array(
    'input_name'  => 'entity_link',
    'input_label' => $this->__('Product'),
    'button_text' => $this->__('Select Product...'),
    'required'    => true
);
 
$chooserHelper->createCategoryChooser($model, $fieldset, $productConfig);

Category Chooser:

$chooserHelper = Mage::helper('jarlssen_chooser_widget/chooser');

$categoryConfig = array(
    'input_name'  => 'entity_link',
    'input_label' => $this->__('Category'),
    'button_text' => $this->__('Select Category...'),
    'required'    => true
);

$chooserHelper->createProductChooser($model, $fieldset, $categoryConfig);

Static Block Chooser:

$chooserHelper = Mage::helper('jarlssen_chooser_widget/chooser');

$blockConfig = array(
    'input_name'  => 'entity_link',
    'input_label' => $this->__('Block'),
    'button_text' => $this->__('Select Block...'),
    'required'    => true
);

$chooserHelper->createCmsBlockChooser($model, $fieldset, $blockConfig);

Example for CMS Page Chooser:

$chooserHelper = Mage::helper('jarlssen_chooser_widget/chooser');

$cmsPageConfig = array(
    'input_name'  => 'entity_link',
    'input_label' => $this->__('CMS Page'),
    'button_text' => $this->__('Select CMS Page…'),
    'required'    => true
);

$chooserHelper->createCmsPageChooser($model, $fieldset, $cmsPageConfig);

Example for Custom Chooser:

$chooserHelper = Mage::helper('jarlssen_chooser_widget/chooser');

$customChooserConfig = array(
    'input_name'  => 'entity_link',
    'input_label' => $this->__('Custom entity'),
    'button_text' => $this->__('Select entity…'),
    'required'    => true
);

$chooserBlock = 'custom_module/chooser';

$chooserHelper->createChooser($model, $fieldset, $customChooserConfig, $chooserBlock);

Data representation

Chooser Format Example
Product product/{product_id}/{category_id} / {category_id} is optional product/14509 / product/14509/32
Category category/{category_id} category/22
CMS Page {cms_page_id} 7
Static Block {static_block_id} 3
Custom N/A N/A

jarlssen_chooserwidget's People

Contributors

bmcg avatar ceckoslab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jarlssen_chooserwidget's Issues

Uncaught TypeError: Cannot read property 'value' of null

just installed the extension and i can see the "select product" button. but if i click on it, the console throws "Uncaught TypeError: Cannot read property 'value' of null". btw. i'm not sure about the $model as first param i should take.

ReferenceError: WysiwygWidget is not defined

Hello! I receive an error after installation: ReferenceError: WysiwygWidget is not defined
http://localhost19/index.php/background/adminhtml_background/edit/id/2/key/f2f45f2049956d18a81ca6730ded502a/

form.php
$model = Mage::getModel('background/background');
$fieldset = $form->addFieldset('background_form', array(
'legend'=>Mage::helper('background')->__('Background information')
));

$chooserHelper = Mage::helper('jarlssen_chooser_widget/chooser');
$productChooserConfig = array(
'input_name' => 'product_name',
'input_label' => $this->('Custom entity'),
'button_text' => $this->
('Select entity'),
'required' => true
);
$chooserHelper->createProductChooser($model, $fieldset, $productChooserConfig);

WysiwygWidget to be connected?

How to return only the product name

Hello again). When you add the product get the following
screen
Is it possible to display only one product name?
The database record is created "product/1"
engine ver.1.9.1.0

Thanks for a good module.

Clicking on Select Product... throws a 404 error

Clicking on the Select Product... button throws a 404 error (over AJAX) I get the following error:

Failed to load resource: the server responded with a status of 404 (Not Found) http://example.com/index.php/featuredproduct/catalog_product_widget/chooser/uniq_id/product97d2cd120a29ad1a1374dcdce28dea5d/key/d851ae3c0d4962bf9e4ac4ad9108dee4/?isAjax=true

featuredproduct is the name of my custom module I am running the ChooserWidget in. I can provide any necessary files to help debug. I am running Magento CE 1.9.0.1

Dynamic hide $fieldset ChooserWidget

Hello ceckoslab!
Is it possible to dynamically hide fields generated helper?
I've tried

  $fieldset->addField('url', 'select', array(
        'name'    => 'url',
        'label'   => Mage::helper('module')->__('url:'),
        'options' => array(
            '0' => Mage::helper('module')->__('No'),
            '1' => Mage::helper('module')->__('Yes select product'),
        )
    ));

    $chooserHelper = Mage::helper('jarlssen_chooser_widget/chooser');

        $productConfig = array(
            'input_id'  => 'product_name',
            'input_name'  => 'product_name',
            'input_label' => $this->__('Product'),
            'button_text' => $this->__('Product select...'),
        );

    $chooserHelper->createProductChooser($model, $fieldset, $productConfig);

    $this->setChild(
        'form_after',
        $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
            ->addFieldMap('url', 'url')
            ->addFieldMap('product_name', 'product_name')
            ->addFieldDependence('product_name', 'url', '1')
        );

But it does not work ...

Re-saving page removes widget data

I know this isn't really actively maintained any more, but I'm just wondering if you maybe have a fix for an issue I found.

Once you've used the widget product chooser to select a product, and then saved your page, the page refreshes and you can see the product ID. But, if you then re-save the page, it resets the product chooser and removes the value of the product ID.

Also when you have multiple versions of it on a page, if you try and change only one product, the rest all get reset.

Wrong modman directives

The modman directives of the module are completely wrong and basically the module can't be installed by modman, because the symlink paths are "broken"

Required handle "editor" is missing, while cache is enabled

Hello, I have error

Required handle "editor" is missing. You have to add the handle in the layout in favor to have working chooser. on admin/tiles/new while i have active cache in Magento.... When I flush whole cache it works only for 1st time. Anybody knows the solution?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.