<p>That is a typo in the <a href="https://transition.topshelfcraft.com/software/craft/searchplus/usage/hooks-events" rel="nofollow noreferrer">plugin's documentation</a>.</p>

<pre><code>public function testMapping(element)
</code></pre>

<p>should be</p>

<pre><code>public function testMapping($element)
</code></pre>

<p>since <code>$element</code> is a PHP variable.</p>

CC BY-SA 3.0
2018-03-17T23:35:52.597Z
2018-03-17T23:35:52.597Z
Brad Bell
<p>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 <a href="https://transition.topshelfcraft.com/software/craft/searchplus/usage/hooks-events" rel="nofollow noreferrer">https://transition.topshelfcraft.com/software/craft/searchplus/usage/hooks-events</a> as a reference and used <a href="https://pluginfactory.io" rel="nofollow noreferrer">https://pluginfactory.io</a> to create the plugin.</p>

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

<pre><code>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-&gt;id;
    $ret['title'] = $entry-&gt;title;
    $ret['activityId'] = $entry-&gt;id;
    $ret['id'] = $entry-&gt;id;
    $ret['slug'] = $entry-&gt;slug;
    $ret['url'] = $entry-&gt;url;
    $ret['uri'] = '/' . $entry-&gt;uri;

return $ret;
}
</code></pre>

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

<p>Was wondering if anyone had any tips</p>

<p>Thanks!  </p>

CC BY-SA 3.0
2018-03-17T19:44:17.677Z
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
CC BY-SA 3.0
2018-03-17T20:11:47.693Z
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
CC BY-SA 3.0
2018-03-17T20:25:01.017Z
At the normal https://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
CC BY-SA 3.0
2018-03-17T20:59:42.603Z
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
CC BY-SA 3.0
2018-03-21T21:01:03.647Z
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
CC BY-SA 3.0
2018-03-21T22:20:07.243Z
@LindseyD Alright, I'll remember this, sry to bother you again.
Robin Schambach
CC BY-SA 3.0
2018-03-21T22:21:20.227Z
@RobinSchambach No problem. Glad to see you so active on SE, that's a good thing! :)
Lindsey D
CC BY-SA 4.0
2018-09-06T16:03:18.420Z
Is it possible to provide full documentation on this process please? I have attempted to follow this but when using the "Mapping Test" the RAW Json Output only outputs "false"
crafthelp
<plugin-development><search><plugin-searchplus>
syntax error, expecting variable (T_VARIABLE) in Search Plus Custom Mapping
# syntax error, expecting variable (T_VARIABLE) in Search Plus Custom Mapping

(Asked by: username_0 on 2018-03-17)

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!

**Tags:** plugin-development, search, plugin-searchplus
> **Comments:**
> **username_1**: 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  
> **username_0**: 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...  
> **username_1**: At the normal https://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  
> **username_0**: 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  
> **username_2**: 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.  
> **username_1**: @LindseyD Alright, I'll remember this, sry to bother you again.  
> **username_2**: @RobinSchambach No problem. Glad to see you so active on SE, that's a good thing! :)  
> **username_3**: Is it possible to provide full documentation on this process please? I have attempted to follow this but when using the "Mapping Test" the RAW Json Output only outputs "false"  

---

## 1 answers

### Answer by username_4 on 2018-03-17. Score: 2 | Accepted answer

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.


---

