<p>I've managed to get it working with great help from Brad Bell and Oli.</p>
<p>The following code changes feedme slugs on Import.</p>
<pre><code>use craft\feedme\events\ElementEvent;
use craft\helpers\ElementHelper;
use craft\elements\Entry;
</code></pre>
<p>Adding the following Event with the namespaces above works nicely.</p>
<pre><code>        Event::on(
          Process::class,
          Process::EVENT_STEP_BEFORE_ELEMENT_SAVE,
          function(craft\feedme\events\FeedProcessEvent $event) {
            switch($event-&gt;feed['name']){
                case 'merchants':
                    $element = $event-&gt;element;
                    $element-&gt;slug = ElementHelper::createSlug($element-&gt;title.' '.'Whatever you'd like appended!');
                    break;
            }
        });
</code></pre>

CC BY-SA 4.0
2020-11-21T11:59:09.547Z
2020-11-21T11:59:09.547Z
JMKelley
<p>I asked this question previously before Feedme was acquired by Craft, though I haven't updated Feedme &amp; the code since now.</p>
<p>I'm getting the following error when processing my feeds. I'm trying to change my entries slug when they get imported but only on a certain feed - in this case - a feed with the title of 'merchants'</p>
<blockquote>
<p>Argument 1 passed to craft\feedme\Plugin::craft\feedme{closure}()
must be an instance of craft\feedme\FeedProcessEvent, instance of
craft\feedme\events\FeedProcessEvent given - Plugin.php: 67</p>
</blockquote>
<p>The code I'm trying to run in <code>Plugin.php</code></p>
<pre><code>public function init()
{
    parent::init();

    self::$plugin = $this;

    $this-&gt;_setPluginComponents();
    $this-&gt;_registerCpRoutes();
    $this-&gt;_registerTwigExtensions();
    $this-&gt;_registerVariables();

    Event::on(
      Process::class,
      Process::EVENT_STEP_BEFORE_ELEMENT_SAVE,
      function(FeedProcessEvent $event) {
        switch($event-&gt;feed['name']){
            case 'merchants':
                $element = $event-&gt;element;
                $element-&gt;slug = ElementHelper::createSlug($element-&gt;title.' '.'Coupon Codes &amp; Promo Codes');
                break;
        }
    });
}
</code></pre>

CC BY-SA 4.0
2020-11-19T19:41:59.627Z
What version of Feed Me and Craft are you on?
Brad Bell
CC BY-SA 4.0
2020-11-19T20:33:19.100Z
@BradBell Very latest-3.1.10
JMKelley
CC BY-SA 4.0
2020-11-19T21:06:46.447Z
Really strange error... what if you change the function line to this: `function(craft\feedme\events\FeedProcessEvent $event) {`?
Brad Bell
CC BY-SA 4.0
2020-11-19T21:07:31.113Z
If that doesn't work, try deleting your composer.lock file, your vendor folder, and running `composer update` from your project's root to pull in a fresh set of dependencies and see if that helps.
Brad Bell
CC BY-SA 4.0
2020-11-19T22:44:31.997Z
@BradBell Changing the function seems to have quelled that fire. But now getting "Class 'craft\feedme\ElementHelper' not found - Plugin.php: 73"
JMKelley
CC BY-SA 4.0
2020-11-20T11:08:47.007Z
Try `$element->slug = craft\helpers\ElementHelper::createSlug(...`
Oli
<plugin-development><plugins><plugin-feedme>
FeedMe Change Slug when Importing
# FeedMe Change Slug when Importing

(Asked by: username_0 on 2020-11-19)

I asked this question previously before Feedme was acquired by Craft, though I haven't updated Feedme & the code since now.
I'm getting the following error when processing my feeds. I'm trying to change my entries slug when they get imported but only on a certain feed - in this case - a feed with the title of 'merchants'

Argument 1 passed to craft\feedme\Plugin::craft\feedme{closure}()
must be an instance of craft\feedme\FeedProcessEvent, instance of
craft\feedme\events\FeedProcessEvent given - Plugin.php: 67

The code I'm trying to run in Plugin.php
public function init()
{
    parent::init();

    self::$plugin = $this;

    $this->_setPluginComponents();
    $this->_registerCpRoutes();
    $this->_registerTwigExtensions();
    $this->_registerVariables();

    Event::on(
      Process::class,
      Process::EVENT_STEP_BEFORE_ELEMENT_SAVE,
      function(FeedProcessEvent $event) {
        switch($event->feed['name']){
            case 'merchants':
                $element = $event->element;
                $element->slug = ElementHelper::createSlug($element->title.' '.'Coupon Codes & Promo Codes');
                break;
        }
    });
}

**Tags:** plugin-development, plugins, plugin-feedme

> **Comments:**
> **username_1**: What version of Feed Me and Craft are you on?  
> **username_0**: @BradBell Very latest-3.1.10  
> **username_1**: Really strange error... what if you change the function line to this: `function(craft\feedme\events\FeedProcessEvent $event) {`?  
> **username_1**: If that doesn't work, try deleting your composer.lock file, your vendor folder, and running `composer update` from your project's root to pull in a fresh set of dependencies and see if that helps.  
> **username_0**: @BradBell Changing the function seems to have quelled that fire. But now getting "Class 'craft\feedme\ElementHelper' not found - Plugin.php: 73"  
> **username_2**: Try `$element->slug = craft\helpers\ElementHelper::createSlug(...`  

---

## 1 answers

### Answer by username_0 on 2020-11-21. Score: 3 | Accepted answer

I've managed to get it working with great help from username_1 and username_2.
The following code changes feedme slugs on Import.
use craft\feedme\events\ElementEvent;
use craft\helpers\ElementHelper;
use craft\elements\Entry;

Adding the following Event with the namespaces above works nicely.
        Event::on(
          Process::class,
          Process::EVENT_STEP_BEFORE_ELEMENT_SAVE,
          function(craft\feedme\events\FeedProcessEvent $event) {
            switch($event->feed['name']){
                case 'merchants':
                    $element = $event->element;
                    $element->slug = ElementHelper::createSlug($element->title.' '.'Whatever you'd like appended!');
                    break;
            }
        });


---

