1

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;
        }
    });
}
6
  • What version of Feed Me and Craft are you on?
    – Brad Bell
    Nov 19 '20 at 19:41
  • @BradBell Very latest-3.1.10
    – JMKelley
    Nov 19 '20 at 20:33
  • Really strange error... what if you change the function line to this: function(craft\feedme\events\FeedProcessEvent $event) {?
    – Brad Bell
    Nov 19 '20 at 21:06
  • 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
    Nov 19 '20 at 21:07
  • @BradBell Changing the function seems to have quelled that fire. But now getting "Class 'craft\feedme\ElementHelper' not found - Plugin.php: 73"
    – JMKelley
    Nov 19 '20 at 22:44
2

I've managed to get it working with great help from Brad Bell and Oli.

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;
            }
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.