# convertFunction - Neue Hinzufügen

**URL:** <https://forum.shopware.com/t/convertfunction-neue-hinzufugen/45729>\
**Category:** Programmierung\
**Created:** [12. Mai 2017 um 15:30 UTC](https://forum.shopware.com/t/convertfunction-neue-hinzufugen/45729 "2017-05-12T15:30:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://forum.shopware.com/u/AlexG)\
**Post date:** [12. Mai 2017 um 15:30 UTC](https://forum.shopware.com/t/convertfunction-neue-hinzufugen/45729/1 "2017-05-12T15:30:34Z")

</div>

Ich bin momentan bei der Erstellung eines Plugins für ein neues Einkaufsweltenelement.

Grundsätzlich erweitere ich den bereits bestehenden ArticleSlider, da ein ähnlicher Aufbau besteht.  
Mein Problem ist nun das ich noch keine Artikel in meinem $data Array habe. Da der ArticleSlider die ‚values‘ in der convertFunction „getArticleSlider“ befüllt.

Ist es möglich (und wie?) eine eigene convertFunction beim Emotion Controller zu registrieren?

Folgend noch beispielhafte Auszüge aus dem Code und auftretende Fehlermeldung:

Bootstrap: „MyEmotionPlugin.php“

```
public function install(InstallContext $context)
{
    $component = $this->createEmotionComponent($context->getPlugin(), [
        'name' => 'My Emotion Plugin',
        'xtype' => 'emotion-components-my-emotion-plugin',
        'template' => 'emotion_plugin'
        'cls' => 'my_emotion_plugin',
        'description' => '',
        'convertFunction' => 'myConvertFunction'
    ]);
    
    /* Form elements */
    /** @var ModelManager $em */
    $em = $this->container->get('models');
    $em->persist($component);
    $em->flush();
}

```

Subscriber/Emotion.php

```
class Emotion implements SubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Action_PostDispatchSecure_Widgets_Emotion' => 'extendsEmotionTemplates',
            'Enlight_Controller_Action_PostDispatchSecure_Backend_Emotion' => 'extendsEmotionTemplates',
        ];
    }

    private function myConvertFunction($data, $category, $element)
    {
        echo 'hello world';
        /* Code here */
    }
    
    public function extendsEmotionTemplates(\Enlight_Event_EventArgs $args)
    {
        /** @var \Enlight_Controller_Action $controller */
        $controller = $args->getSubject();
        $view = $controller->View();

        $view->addTemplateDir( __DIR__. '/../Resources/Views/emotion_components/');

        if ($controller->Request()->getModuleName() != 'backend')
            return;

        if ($controller->Request()->getActionName() == 'index')
            $view->extendsTemplate('backend/cob_product_list_app.js');
    }
}

```

Folgende Fehlermeldung tritt auf:

```
Fatal error: Uncaught exception 'Enlight_Exception' with message 'Method "Shopware_Proxies_ShopwareControllersWidgetsEmotionProxy::myConvertFunction" not found failure' in /engine/Shopware/Controllers/Widgets/Emotion.php:300 Stack trace: 
#0 /engine/Library/Enlight/Controller/Action.php(408): Enlight_Class->__call('myConvertFuncti...', Array) 
#1 /engine/Shopware/Controllers/Widgets/Emotion.php(300): Enlight_Controller_Action->__call('myConvertFuncti...', Array) 
#2 /engine/Shopware/Controllers/Widgets/Emotion.php(300): Shopware_Proxies_ShopwareControllersWidgetsEmotionProxy->myConvertFunction(Array, 3, Array) 
#3 [internal function]: Shopware_Controllers_Widgets_Emotion->handleElement(Array, Object(Shopware_Proxies_ShopwareModelsEmotionRepositoryProxy), 3) 
#4 /var/cache/production_201704210836/proxies/ShopwareCont in /engine/Shopware/Controllers/Widgets/Emotion.php on line 300

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)\
**Post date:** [13. Mai 2017 um 14:15 UTC](https://forum.shopware.com/t/convertfunction-neue-hinzufugen/45729/2 "2017-05-13T14:15:38Z")

</div>

Du kannst leider nicht convertFunction nutzen, du müsstest dafür den Emotion Controller erweitern. Funktioniert via Plugin nicht.

Du musst das Event&nbsp;Shopware\_Controllers\_Widgets\_Emotion\_AddElement benutzen siehe:&nbsp;[shopware/Emotion.php at 5.2 · shopware/shopware · GitHub](https://github.com/shopware/shopware/blob/5.2/engine/Shopware/Controllers/Widgets/Emotion.php#L288)

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://forum.shopware.com/u/AlexG)\
**Post date:** [13. Mai 2017 um 22:42 UTC](https://forum.shopware.com/t/convertfunction-neue-hinzufugen/45729/3 "2017-05-13T22:42:43Z")

</div>

Okay vielen Dank! Werde ich am Montag direkt testen!

Edit: Yep, mit ein bisschen mehr Verständnis funktioniert das Ganze ![Blush](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/2f2885a69a3ab7fc5454d32cd96e7133e5bcd558.png "Blush") Dankeschön!
