Activity Content
Introduction
A body adds structured content beneath an entity’s label: a quote, a photo, a few labelled values. Choose a body from the evidence you have:
| Evidence | Body |
|---|---|
| page with a share preview | MediaObject card with the title, description, and image from its preview metadata |
| passage from a source | Excerpt |
| photo | Image |
| a few labelled values | KeyValue |
| nothing to add | no body; the headline alone |
Put supporting detail in the body rather than a headline closure.
Adding Entity Bodies
A body contains an entity's structured content. Define it in the model's toFeed method and render it in your frontend. The body is available wherever the entity appears. With InteractsWithFeed, saving the model refreshes its shared snapshot while recording is enabled. That can change the body shown on older activities too. Use activity data to capture values as they were at the event. A composed feed reads toFeed() each time it is read instead.
Every entity in the payload carries its own bodies, in any role. An activity's featured key names the role it features, the object by default. To feature another role's entity, see Featuring Another Role.
Text and Labelled Values
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\Body\Prose;
use Storyfeed\FeedEntity;
class Order extends Model implements Feedable
{
use InteractsWithFeed;
public function toFeed(): FeedEntity
{
return FeedEntity::make()
->label("Order #{$this->reference}")
->body(
Prose::make()
->content($this->instructions)
->title("Order #{$this->reference} instructions"),
);
}
}<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\Body\Prose;
use Storyfeed\FeedEntity;
class Order extends Model implements Feedable
{
use InteractsWithFeed;
public function toFeed(): FeedEntity
{
return FeedEntity::make(
label: "Order #{$this->reference}",
body: Prose::make(
content: $this->instructions,
title: "Order #{$this->reference} instructions",
),
);
}
}A spoon with the order, please.
Include a title to identify the order when the body appears without a headline.
Use KeyValue for labelled values:
use Storyfeed\Body\KeyValue;
use Storyfeed\FeedEntity;
FeedEntity::make()
->label("Order #{$this->reference}")
->body(
KeyValue::make()->title("Order #{$this->reference}")->items([
'Pickup' => $this->pickup_at->format('g:i a'),
'Items' => $this->items->count(),
'Reference' => KeyValue::verbatim($this->reference),
'Table' => KeyValue::placeholder($this->table, 'not seated'),
]),
);use Storyfeed\Body\KeyValue;
use Storyfeed\FeedEntity;
FeedEntity::make(
label: "Order #{$this->reference}",
body: KeyValue::make(
title: "Order #{$this->reference}",
items: [
'Pickup' => $this->pickup_at->format('g:i a'),
'Items' => $this->items->count(),
'Reference' => KeyValue::verbatim($this->reference),
'Table' => KeyValue::placeholder($this->table, 'not seated'),
],
),
);- Pickup
- 12:10 pm
- Items
- 1
- Reference
- 1035
- Table
- not seated
Use the KeyValue::placeholder method to specify text for an empty value. Use ->defaultPlaceholder('—') to set the default for every row without its own placeholder, or pass defaultPlaceholder: to KeyValue::make(). The KeyValue::verbatim method marks a value for display without formatting, such as a reference number.
disclosure() gives optional details a label:
KeyValue::make(['Reference' => 'R-1042'])->disclosure('Request details');The label travels as disclosure; blank or null omits it. All rows remain in the payload, so authorize them before recording. Older renderers may show the rows without collapsing them.
Formatted Text and Raw Output
For code or raw output, create the body with Prose::verbatim. The body stores the text exactly as given, with verbatim set to true:
use Storyfeed\Body\Prose;
Prose::verbatim($this->output, title: $this->name);10 REM DOOR OVERRIDE — ILLUSTRATIVE BASIC
20 INPUT "SECURITY CODE"; C$
30 IF C$ = "" THEN GOTO 20
40 PRINT "MANUAL OVERRIDE REQUESTED"
50 FOR D = 1 TO 4
60 PRINT "DOOR"; D; " RELEASE REQUEST SENT"
70 NEXT D
80 ENDSYSTEM RESTART ........ COMPLETE
MANUAL INPUT .......... ACCEPTED
DOOR CONTROL .......... ONLINE
EXIT LOCKS ............ RELEASEDSTATION: CEREBRO / WEATHERTOP
CALL TO UTAH .......... NO REPLY
UNEXPECTED SIGNAL .... VOICE / RUSSIAN
MESSAGE .............. REPEATING
NEXT STEP ............ KEEP THE TAPETo name the code's language, use Prose::code with a media type, such as text/x-php or application/json:
use Storyfeed\Body\Prose;
Prose::code($this->source, 'text/x-php', title: $this->path);The body stores the media type with the source, as verbatim text.
For formatted text, use Prose::markdown or Prose::html. Storyfeed stores the source as written, with text/markdown or text/html as its media type:
use Storyfeed\Body\Prose;
Prose::markdown($this->notes, title: $this->title);What the machine needs
Alexei’s account: the machine is opening a gate beneath the mall.
- Locate the control room.
- Reach the two shutdown keys.
- Check the safe combination before going in.
Working note: translation is evidence, not a complete floor plan.
Door control restored. The restart has returned the locks to manual control.
- Keep the exit route clear.
- Confirm that everyone has left the building.
Code and Callouts
Code carries source text with an optional highlighter language:
use Storyfeed\Body\Code;
Code::make('SELECT 1')->language('sql')->title('Health check');Callout carries a short note with an app-defined intent, defaulting to note:
use Storyfeed\Body\Callout;
Callout::make('Pickup closes at 4 pm.')->title('Today')->intent('warning');Both use their title as the fallback line when set; otherwise Code uses the first source line and Callout uses its content.
Adding Quoted Text
Use an Excerpt body for someone's words or a passage from a document. Leave out from when the headline already says who said it; add it when the passage comes from someone or somewhere the headline does not name. Define the body on the quoted model in toFeed():
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Storyfeed\Body\Excerpt;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\FeedEntity;
class Note extends Model implements Feedable
{
use InteractsWithFeed;
public function toFeed(): FeedEntity
{
return FeedEntity::make()
->label('Order note')
->body(
Excerpt::make()->text($this->body),
);
}
}<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Storyfeed\Body\Excerpt;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\FeedEntity;
class Note extends Model implements Feedable
{
use InteractsWithFeed;
public function toFeed(): FeedEntity
{
return FeedEntity::make(
label: 'Order note',
body: Excerpt::make(text: $this->body),
);
}
}The headline names the note's author, so the quotation needs no separate attribution:
Can I collect this at the counter?
Record the note as the activity's object and the order as its target:
<?php
namespace App\Http\Controllers;
use App\Models\Order;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;
class OrderNoteController extends Controller
{
public function store(Request $request, Order $order): RedirectResponse
{
$note = $order->notes()->create(
$request->validate(['body' => ['required', 'string']]),
);
Storyfeed::activity()
->by($request->user())
->action('post', $note)
->to($order)
->publish();
return back();
}
}<?php
namespace App\Http\Controllers;
use App\Models\Order;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;
class OrderNoteController extends Controller
{
public function store(Request $request, Order $order): RedirectResponse
{
$note = $order->notes()->create(
$request->validate(['body' => ['required', 'string']]),
);
Storyfeed::record(
verb: 'post',
object: $note,
actor: $request->user(),
target: $order,
);
return back();
}
}Attributing a Source
Use Excerpt to quote someone else's words, such as a person interviewed for a story. Here the headline names the article, and from names the source of the quoted passage:
use Storyfeed\Body\Excerpt;
use Storyfeed\FeedEntity;
FeedEntity::make()
->label($this->title)
->body(
Excerpt::make()
->text($this->pull_quote)
->from($this->pull_quote_source),
);use Storyfeed\Body\Excerpt;
use Storyfeed\FeedEntity;
FeedEntity::make(
label: $this->title,
body: Excerpt::make(
text: $this->pull_quote,
from: $this->pull_quote_source,
),
);They came back every night for my fertilizer, bag after bag
Excerpts are complete by default. Call truncated() when you cut the text, and the kits mark the cut. For the entity's own text, such as an article's opening paragraph, use Prose instead.
A record of an answer taken down word for word quotes the person who gave it:
use Storyfeed\Body\Excerpt;
use Storyfeed\FeedEntity;
FeedEntity::make()
->label($this->title)
->body(
Excerpt::make()
->text($this->answer)
->from($this->answered_by),
);use Storyfeed\Body\Excerpt;
use Storyfeed\FeedEntity;
FeedEntity::make(
label: $this->title,
body: Excerpt::make(
text: $this->answer,
from: $this->answered_by,
),
);Planck’s constant is 6.62607004.
Adding an Image
Use an Image body to show a photograph with a caption. Pass the picture's URL to make:
use Storyfeed\Body\Image;
use Storyfeed\FeedEntity;
return FeedEntity::make()
->label($this->name)
->body(
Image::make($this->url)
->width($this->width)
->height($this->height)
->alt($this->description)
->caption($this->subject)
);use Storyfeed\Body\Image;
use Storyfeed\FeedEntity;
return FeedEntity::make(
label: $this->name,
body: Image::make(
image: $this->url,
width: $this->width,
height: $this->height,
alt: $this->description,
caption: $this->subject,
),
);
The body stores the URL, so it keeps showing that address. You may also pass a FeedImage, whose alt, width and height become the body's.
For a URL that changes, such as a signed link, pass one of the model's feedMedia() picture slots instead, such as $this->feedMediaPreview(). The body stores the slot's name, and Feed Media resolves the picture each time the feed is read.
size() chooses the picture's presentation:
Image::make('/photos/88.jpg')->size('card');The value travels in $meta.size: thumbnail, inline, card, feature or full. Omit it to use the kit's feed default, or full when no default is set. Explicit full overrides the feed default. Kits choose the lengths and keep pictures uncropped.
Attaching a File
A FileAttachment body describes a file, such as a signed agreement's PDF: its name, size and media type. Linking Files shows a Document model that attaches one and links the download.
Listing Items
Use ItemList for an order's items. Each item may be a plain string or a FeedLink to another page:
use App\Models\OrderLine;
use Storyfeed\Body\ItemList;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make()
->label("Order #{$this->reference}")
->body(
ItemList::make()
->title("Order #{$this->reference} items")
->items(
$this->lines->take(2)->map(
fn (OrderLine $line) => FeedLink::make(
$line->item->name,
$line->item->url,
),
),
)
->items([$this->lines->get(2)->item->name])
->totalItems($this->lines->count())
->more(FeedLink::make("Order #{$this->reference}", $this->url)),
);use App\Models\OrderLine;
use Storyfeed\Body\ItemList;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make(
label: "Order #{$this->reference}",
body: ItemList::make(
title: "Order #{$this->reference} items",
items: [
...$this->lines->take(2)->map(
fn (OrderLine $line) => FeedLink::make(
$line->item->name,
$line->item->url,
),
),
$this->lines->get(2)->item->name,
],
totalItems: $this->lines->count(),
more: FeedLink::make("Order #{$this->reference}", $this->url),
),
);- a hot dog
- a corn dog
- a pretzel
totalItems records the full count and more links to the rest. Use ItemList::ordered() when the sequence of the items matters.
Adding a Table
Use Table for rows and columns. Its arguments follow Artisan's $this->table($headers, $rows):
use App\Models\OrderLine;
use Illuminate\Support\Number;
use Storyfeed\Body\Table;
use Storyfeed\FeedEntity;
FeedEntity::make()
->label("Order #{$this->reference}")
->body(
Table::make()
->headers(['Item', 'Qty', 'Price'])
->rows($this->lines->map(fn (OrderLine $line) => [
$line->item->name,
$line->quantity,
Number::currency($line->total),
]))
->footer(['Total', null, Number::currency($this->total)]),
);use App\Models\OrderLine;
use Illuminate\Support\Number;
use Storyfeed\Body\Table;
use Storyfeed\FeedEntity;
FeedEntity::make(
label: "Order #{$this->reference}",
body: Table::make(
headers: ['Item', 'Qty', 'Price'],
rows: $this->lines->map(fn (OrderLine $line) => [
$line->item->name,
$line->quantity,
Number::currency($line->total),
]),
)->footer(['Total', null, Number::currency($this->total)]),
);| Item | Qty | Price |
|---|---|---|
| Hot dog | 2 | $3.00 |
| Corn dog | 1 | $1.75 |
| Pretzel | 2 | $4.00 |
| Total | — | $8.75 |
A cell is a string, a number, null for an empty cell, or a FeedLink. Format amounts before adding them. footer appends a row beneath the others, such as a subtotal or a total, and title adds a line above the table.
Adding Multiple Bodies
Entities in any role can have bodies. Your frontend chooses which to display. Each body() call appends a body in the order given:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Storyfeed\Body\KeyValue;
use Storyfeed\Body\Prose;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\FeedEntity;
class MenuItem extends Model implements Feedable
{
use InteractsWithFeed;
public function toFeed(): FeedEntity
{
return FeedEntity::make()
->label($this->name)
->body(Prose::make($this->description))
->body(KeyValue::make()->items('Station', $this->station));
}
}<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Storyfeed\Body\KeyValue;
use Storyfeed\Body\Prose;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\FeedEntity;
class MenuItem extends Model implements Feedable
{
use InteractsWithFeed;
public function toFeed(): FeedEntity
{
return FeedEntity::make(
label: $this->name,
body: [
Prose::make($this->description),
KeyValue::make(items: ['Station' => $this->station]),
],
);
}
}Two scoops with warm sauce.
- Station
- Fountain
Linking a Title
Use MediaObject for a notice with a title and a short description. Pass a FeedLink as its subject to make the title a link:
use Storyfeed\Body\MediaObject;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make()
->label($this->title)
->body(
MediaObject::make()
->subject(FeedLink::make($this->title, $this->url))
->content($this->description),
);use Storyfeed\Body\MediaObject;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make(
label: $this->title,
body: MediaObject::make(
subject: FeedLink::make($this->title, $this->url),
content: $this->description,
),
);The counter opens at 10 am. Orders are available until 9 pm.
The title links to the notice at the URL supplied when its body is stored.
To link to another page, pass that page's title and URL:
use Storyfeed\Body\MediaObject;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make()
->label($this->title)
->body(
MediaObject::make()
->subject(FeedLink::make($this->guide_title, $this->guide_url))
->content($this->description),
);use Storyfeed\Body\MediaObject;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make(
label: $this->title,
body: MediaObject::make(
subject: FeedLink::make($this->guide_title, $this->guide_url),
content: $this->description,
),
);The visitor guide includes entrances, parking and shop locations.
A plain-string subject stores a title without a link.
Adding a Call to Action
Use CallToAction for a sentence or two and one action. The action's text says what to do, and FeedLink::toEntity() sends it to the entity the body belongs to:
use Storyfeed\Body\CallToAction;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make()
->label($this->title)
->body(
CallToAction::make()
->content($this->description)
->action('Read the notice', FeedLink::toEntity()),
);use Storyfeed\Body\CallToAction;
use Storyfeed\FeedEntity;
use Storyfeed\FeedLink;
FeedEntity::make(
label: $this->title,
body: CallToAction::make(
content: $this->description,
)->action('Read the notice', FeedLink::toEntity()),
);The counter opens at 10 am. Orders are available until 9 pm.
Read the noticesubject adds a short heading. The action is required, and a string in place of the FeedLink is a plain link.
Links in Bodies
A FeedLink contains a label and an href. Pass the destination URL as the second argument to FeedLink::make, or set it with the href method. FeedLink::toEntity() stores no URL: the renderer links it to the entity's own link each time the feed is read.
The href is stored as written. It can become stale if a route changes or a signed URL expires.
The label names the thing, such as a notice or an order. See the FeedLink reference for its methods and the body fields that accept it.
Setting a Body's Height
A body may tell the renderer how tall to draw it. maxHeight takes a CSS length, and fullHeight shows the whole body:
use Storyfeed\Body\Prose;
use Storyfeed\Body\Table;
use Storyfeed\FeedEntity;
return FeedEntity::make()
->label("Order #{$this->reference}")
->body(
Prose::markdown($this->notes)->fullHeight(),
Table::make(['Item', 'Qty'], $this->summary)->maxHeight('16rem'),
);Both write the body's $meta.maxHeight. Add your own renderer settings with withMeta, using a dotted key such as acme.layout:
use Storyfeed\Body\Prose;
Prose::markdown($this->notes)->withMeta(['acme.layout' => 'wide']);Adding a Fallback Line
Every body accepts a fallback: one line of plain text, stored in the body's $fallback key, for a renderer that does not draw its type:
use Storyfeed\Body\KeyValue;
use Storyfeed\FeedEntity;
return FeedEntity::make()
->label("Order #{$this->reference}")
->body(
KeyValue::make()
->items('Pickup', $this->pickup_at->format('g:i a'))
->fallback("Pickup at {$this->pickup_at->format('g:i a')}"),
);use Storyfeed\Body\KeyValue;
use Storyfeed\FeedEntity;
return FeedEntity::make(
label: "Order #{$this->reference}",
body: KeyValue::make(
items: ['Pickup' => $this->pickup_at->format('g:i a')],
)->fallback("Pickup at {$this->pickup_at->format('g:i a')}"),
);[
{
"kind": "activity",
"id": "a-confirm",
"verb": "confirm",
"published_at": "1985-07-02T12:03:00.000000Z",
"starts_at": null,
"ends_at": null,
"headline_template": ":actor confirmed :object",
"headline": null,
"bindings": null,
"glyph": "circle-check",
"glyph_intent": null,
"actor": {
"type": "user",
"id": "101",
"label": "Steve Harrington",
"link": {
"href": "/users/101",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": {
"src": "/media/worlds/stranger-things/avatars/scooper.jpg",
"mediaType": "image/jpeg",
"width": 256,
"height": 256,
"alt": null
},
"image": null,
"preview": null,
"initials": null,
"color": null,
"files": [],
"slots": []
},
"media_ref": "md08aeb0f13f95241",
"entity_ref": "e6b153676d8dbc853",
"body": null,
"tombstone": null
},
"object": {
"type": "order",
"id": "1035",
"label": "Order #1035",
"link": {
"href": "/orders/1035",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "O1",
"color": "#4d7c0f",
"files": [],
"slots": []
},
"media_ref": "ma9527581042280f7",
"entity_ref": "e722f0b114fd1ec13",
"body": [
{
"$body": "Storyfeed/Body/KeyValue",
"$v": 3,
"$fallback": "Pickup at 12:10 pm",
"items": [
{
"key": "Pickup",
"value": "12:10 pm"
}
]
}
],
"tombstone": null
},
"target": {
"type": "venue",
"id": "101",
"label": "Scoops Ahoy",
"link": {
"href": "/venues/scoops",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/parlour.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "An ice cream counter"
},
"initials": "SA",
"color": "#9f1239",
"files": [],
"slots": []
},
"media_ref": "m1bcad7c79ddfc05d",
"entity_ref": "e352bb6f37b7d8bfe",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "Scoops Ahoy",
"caption": "Scoops Ahoy",
"image": "preview"
}
],
"tombstone": null
},
"context": null,
"origin": null,
"result": null,
"instrument": null,
"location": null,
"generator": null,
"featured": "object",
"data": null,
"tombstoned": [],
"redundant": false,
"missing_headline_template": null,
"missing_headline": null
}
]Without one, a Table stores its title and a CallToAction its subject or action text as the fallback. Other body types store none.
Available Body Types
| Body Type | Content | Payload Keys | Left Out at Their Default |
|---|---|---|---|
KeyValue | labelled values | title, defaultPlaceholder, disclosure, items[] of key, value, verbatim, placeholder | title, defaultPlaceholder, disclosure; a row's verbatim (false) and placeholder (the body's defaultPlaceholder) |
Excerpt | a quoted passage with optional source attribution | text, from, truncated | from, truncated (false) |
Image | a picture and caption | src, mediaType, caption, alt, width, height, image (slot name) | all |
FileAttachment | file name, size, and media type | name, size, mediaType | all |
Prose | text and its format | content, mediaType, verbatim, title | mediaType (text/plain), verbatim (false), title |
ItemList | named items with optional links | title, items[], ordered, totalItems, more | title, ordered (false), totalItems, more |
MediaObject | a title, text, image, and files | subject, content, image, files, footnote | subject, content, image, files ([]), footnote |
Table | rows and columns | title, headers, rows, footer | title, headers ([]), footer ([]) |
CallToAction | a heading, text, and one action | subject, content, action of label, link | subject, content |
Component | a custom component name and props | name, props | props ([]) |
Code | source text and an optional language | title, language, source | title, language |
Callout | a short note with an intent | title, content, intent | title, intent (note) |
A stored body leaves out each key that holds its default, which is null unless the table says otherwise. A body class's static upgrade($payload, $from) method takes a stored payload and its $v, and returns it with every key filled in.
These classes use the Storyfeed\Body namespace. Each body's payload includes its type in $body, such as Storyfeed/Body/KeyValue, and its version in $v. Your renderer uses these fields to display the body. A body may also carry $meta, its renderer settings. Passing a string as a body creates a Prose body.
See Resolving Bodies When Retrieved for current and deferred values, or Custom Body Types to render custom components and define your own body types.
To feature a role other than the object, see Featuring Another Role.