1

I’m looking for a little help with Custom Mapping for the Search Plus plugin. I think(?) I'm getting pretty close, but stuck on something (and I do front end web design, so this is just over my head) I’m using https://transition.topshelfcraft.com/software/craft/searchplus/usage/hooks-events as a reference and used https://pluginfactory.io to create the plugin.

Per the instructions in the documentation above, I’ve added this to the bottom of the plugin :

public function searchPlus_addAlgoliaMapping()
{
    $ret = [];
    $ret['name'] = 'GHCC Staff Mapping2';
    $ret['handle'] = 'GHCC_Staff2';
    $ret['description'] = 'Mapping for Staff Page';
    $ret['method'] = 'example.testMapping';
    return $ret;
}

public function testMapping(element)
{
    $ret = [];

    $ret['objectID'] = $entry->id;
    $ret['title'] = $entry->title;
    $ret['activityId'] = $entry->id;
    $ret['id'] = $entry->id;
    $ret['slug'] = $entry->slug;
    $ret['url'] = $entry->url;
    $ret['uri'] = '/' . $entry->uri;

return $ret;
}

But am getting an error: syntax error, unexpected ')', expecting variable (T_VARIABLE) referencing line 186 public function testMapping(element)

Was wondering if anyone had any tips

Thanks!

8
  • I'm voting to close this question as off-topic because it has nothing to do with Craft but with normal PHP. However.. variables in PHP needs to start with an $ so public function testMapping($entry) will help – Robin Schambach Mar 17 '18 at 19:44
  • Hey Robin - sorry don't mean to be posting in the wrong place. Do you have a recommendation of where I should post. This is a Craft plugin... – Jon Yetter Mar 17 '18 at 20:11
  • At the normal stackoverflow.com but since I already answered the question I don't think you'll need that. Maybe you should read common php guides before you start to work with a CMS – Robin Schambach Mar 17 '18 at 20:25
  • There is a plugin-development tag and a tag for the this particular plugin - I guess I'm not clear on how this doesn't relate to Craft..and appreciate your advice. I've been working on Craft since in beta and haven't had any problems - rarely have to know or use PHP and there is typically a really helpful community – Jon Yetter Mar 17 '18 at 20:59
  • 1
    Voting to leave open. @RobinSchambach just because the answer is a simple PHP error doesn't mean that the question is off-topic. This question is very clearly about a Craft plugin, and therefore definitely belongs here. – Lindsey D Mar 21 '18 at 21:01
2

That is a typo in the plugin's documentation.

public function testMapping(element)

should be

public function testMapping($element)

since $element is a PHP variable.

0

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.