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:
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
| Parameter | Type | Description |
$pipeline |
\Aero\Admin\Pipelines\ListingRulesContextBuilder |
The listing rules context builder. |
$next |
\Closure |
The next step in the builder. |
Attributes
| Attribute |
Type |
Description |
$rules |
\Illuminate\Support\Collection |
All the rules corresponding to the model (that is being viewed in the Admin). |
$data |
array |
The array of data the rules need (for display purposes only). |