<p>Based on the discussion you'll need to implement a <code>fetch</code> function similar like Craft does it with the <code>ElementCriteriaModel</code> / <code>ElementQuery</code>. So you'll return some kind of search object until you execute the <code>.find()</code>/<code>fetch()</code> (or whatever you like to call it) function</p>

<pre><code>class ClassName{

    /** @var array $_searchObjects */
    private $_searchObjects;

    /**
     * @param $something
     *
     * @return $this
     */
    public function exampleFunction($something){
        $this-&gt;_searchObjects = ['test', 'insert', 'your', 'array', 'here'];

        return $this;
    }

    /**
     * @param $string
     *
     * @return $this
     */
    public function hide($string){
        // filter your elements
        $this-&gt;_searchObjects = ...//

        return $this;
    }

    /**
     * @return array
     */
    public function find(){
        return $this-&gt;_searchObjects;
    }
}
</code></pre>

<p>You can then use it like</p>

<pre><code>{% set elements = craft.plugin.exampleFunction.find() %}
{% set filterElements = craft.plugin.exampleFunction.hide('something').find() %}
</code></pre>

CC BY-SA 3.0
2018-04-17T07:29:01.323Z
Thank you so much, it seems to be working for me. Thanks again !!.
Pravesh Tiwari
CC BY-SA 3.0
2018-04-17T07:22:24.403Z
2018-04-17T07:22:24.403Z
Robin Schambach
<p>I am new to craft and I need help to understand how plugins work.
I am trying inject these functions to the <code>CraftVariable</code> </p>

<pre><code>{% for item in craft.plugin.exampleFunction(test).hide("noTitle") %}  
</code></pre>

<p><code>craft.plugin.exampleFunction(test)</code> is working perfectly 
but <code>.hide()</code> is not. Can anybody tell me how to call this function?</p>

CC BY-SA 3.0
2018-04-17T07:07:56.177Z
Could you tell us what you want to achieve? What does your `exampleFunction` return?  It should be an object with the function `hide` in it
Robin Schambach
CC BY-SA 3.0
2018-04-17T07:12:00.277Z
Do you have any sample for similer?
Pravesh Tiwari
CC BY-SA 3.0
2018-04-17T07:13:27.163Z
Since I don't know you want to do I can't really provide any help. I can create a simple example but that won't help you
Robin Schambach
CC BY-SA 3.0
2018-04-17T07:15:02.167Z
I just need to know how to access hide function as my exampleFunction is returning array. What changes i need to make here?
Pravesh Tiwari
CC BY-SA 3.0
2018-04-17T07:15:39.453Z
What should your hide function be? what should it do?
Robin Schambach
CC BY-SA 3.0
2018-04-17T07:17:03.567Z
okay Let me explain the scanerio: my example function is returning a custom array. and I want to filter records(array) if any custom fields value is blank
Pravesh Tiwari
CC BY-SA 3.0
2018-04-17T07:17:46.370Z
also put sorting on records similer to craft.plugin.exampleFunction(test).hide("noTitle").sort('price', ASC)
Pravesh Tiwari
CC BY-SA 3.0
2018-04-17T07:20:18.837Z
$query = \craft\elements\Entry::find();
$query->section('products'); 
$tariffSections = $query->all();
Pravesh Tiwari
<plugin-development><craft3>
Plugin development Craft CMS 3
# Plugin development Craft CMS 3

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

I am new to craft and I need help to understand how plugins work.
I am trying inject these functions to the CraftVariable 
{% for item in craft.plugin.exampleFunction(test).hide("noTitle") %}  

craft.plugin.exampleFunction(test) is working perfectly 
but .hide() is not. Can anybody tell me how to call this function?

**Tags:** plugin-development, craft3
> **Comments:**
> **username_1**: Could you tell us what you want to achieve? What does your `exampleFunction` return?  It should be an object with the function `hide` in it  
> **username_0**: Do you have any sample for similer?  
> **username_1**: Since I don't know you want to do I can't really provide any help. I can create a simple example but that won't help you  
> **username_0**: I just need to know how to access hide function as my exampleFunction is returning array. What changes i need to make here?  
> **username_1**: What should your hide function be? what should it do?  
> **username_0**: okay Let me explain the scanerio: my example function is returning a custom array. and I want to filter records(array) if any custom fields value is blank  
> **username_0**: also put sorting on records similer to craft.plugin.exampleFunction(test).hide("noTitle").sort('price', ASC)  
> **username_0**: $query = \craft\elements\Entry::find(); $query->section('products');  $tariffSections = $query->all();  

---

## 1 answers

### Answer by username_1 on 2018-04-17. Score: 3 | Accepted answer

Based on the discussion you'll need to implement a fetch function similar like Craft does it with the ElementCriteriaModel / ElementQuery. So you'll return some kind of search object until you execute the .find()/fetch() (or whatever you like to call it) function
class ClassName{

    /** @var array $_searchObjects */
    private $_searchObjects;

    /**
     * @param $something
     *
     * @return $this
     */
    public function exampleFunction($something){
        $this->_searchObjects = ['test', 'insert', 'your', 'array', 'here'];

        return $this;
    }

    /**
     * @param $string
     *
     * @return $this
     */
    public function hide($string){
        // filter your elements
        $this->_searchObjects = ...//

        return $this;
    }

    /**
     * @return array
     */
    public function find(){
        return $this->_searchObjects;
    }
}

You can then use it like
{% set elements = craft.plugin.exampleFunction.find() %}
{% set filterElements = craft.plugin.exampleFunction.hide('something').find() %}

> **Comments:**
> **username_0**: Thank you so much, it seems to be working for me. Thanks again !!.  

---

