# What is the listing rules context builder?

The Listing Rules Context Builder is used to build the rule-specific context that listing rules need when being displayed in the Admin UI.

For example, the `\Aero\Admin\Pipelines\Pipes\AttachTaggedWithRuleContext` pipe attaches the hydrated tags data for the `\Aero\Catalog\Rules\Types\TaggedWithRule` rule:

```php
class AttachTaggedWithRuleContext
{
    public function handle(\Aero\Admin\Pipelines\ListingRulesContextBuilder $pipeline, \Closure $next)
    {
        $tagIds = $pipeline->rules
            ->where('type', \Aero\Catalog\Rules\Types\TaggedWithRule::KEY)
            ->flatMap(function (ListingRule $rule) {
                return collect($rule->options['filters'] ?? [])->flatten()->toArray();
            })
            ->unique();

        $pipeline->data[\Aero\Catalog\Rules\Types\TaggedWithRule::KEY] = [
            'tags' => $tagIds->isNotEmpty()
                ? \Aero\Catalog\Models\Tag::query()
                    ->select('id', 'tag_group_id', 'name')
                    ->with('group')
                    ->whereIn('id', $tagIds)->get()
                    ->mapWithKeys(function (\Aero\Catalog\Models\Tag $tag) {
                        $id = $tag->getKey();

                        return [
                            $id => [
                                'value' => (string) $id,
                                'name' => $tag->getAttribute('name'),
                                'group_id' => (string) $tag->getRelation('group')->getKey(),
                                'group' => $tag->getRelation('group')->getAttribute('name'),
                            ],
                        ];
                    })
                    ->toArray()
                : [],
        ];

        return $next($pipeline);
    }
}
```

---

### Parameters

<table border="1" id="bkmrk-parameter-type-descr" style="border-collapse: collapse; width: 100%; height: 106.188px;"><colgroup><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Parameter**</td><td style="height: 29.7969px;">**Type**</td><td style="height: 29.7969px;">**Description**</td></tr><tr style="height: 46.5938px;"><td style="height: 46.5938px;">`$pipeline`</td><td style="height: 46.5938px;">`\Aero\Admin\Pipelines\ListingRulesContextBuilder`</td><td style="height: 46.5938px;">The listing rules context builder.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`$next`</td><td style="height: 29.7969px;">`\Closure`</td><td style="height: 29.7969px;">The next step in the builder.</td></tr></tbody></table>

### Attributes

<table border="1" id="bkmrk-attribute-type-descr" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 33.3333%;"></col><col style="width: 33.3333%;"></col><col style="width: 33.3333%;"></col></colgroup><tbody><tr><td>**Attribute**  
</td><td>**Type**  
</td><td>**Description**  
</td></tr><tr><td>`$rules`  
</td><td>`\Illuminate\Support\Collection`</td><td>All the rules corresponding to the model (that is being viewed in the Admin).</td></tr><tr><td>`$data`  
</td><td>`array`  
</td><td>The array of data the rules need (for display purposes only).</td></tr></tbody></table>