Below is a fully functioning example of how to add, save, and display a custom feature button during activity create entirely from CB Auto Actions.
Add Activity Feature
Global
Triggers: activity_onDisplayStreamActivityNew
Type: Code
User: Automatic
Access: Everybody
Action
Action 1
Method: PHP
Code:
Code:
// CODE TO CONFIGURE NEW FEATURE BUTTON
$buttonName = 'streamInputCUSTOM';
$buttonTarget = 'streamInputCUSTOMContainer';
$buttonDescription = 'Check out this new custom button!';
$buttonIcon = 'fa fa-heart';
$inputName = 'custom';
$inputLabel = 'LABEL';
$inputPlaceholder = 'PLACEHOLDER';
// CODE TO RENDER NEW FEATURE BUTTON
$variables['var1']['left'][] = '<button type="button" class="btn btn-light btn-sm border streamToggle ' . htmlspecialchars( $buttonName ) . '" data-cbactivity-toggle-target=".' . htmlspecialchars( $buttonTarget ) . '" data-cbactivity-toggle-active-classes="btn-info" data-cbactivity-toggle-inactive-classes="btn-light border" data-cbtooltip-tooltip="' . htmlspecialchars( $buttonDescription ) . '" data-hascbtooltip="true" data-cbtooltip-position-my="bottom center" data-cbtooltip-position-at="top center" data-cbtooltip-classes="qtip-simple"><span class="' . htmlspecialchars( $buttonIcon ) . '"></span></button>';
$substitutions = $action->substitutions();
$substitutions['input_name'] = htmlspecialchars( $inputName );
$substitutions['input_label'] = $inputLabel;
$substitutions['input_placeholder'] = htmlspecialchars( $inputPlaceholder );
$substitutions['input_class'] = htmlspecialchars( $buttonTarget );
$action->substitutions( $substitutions );
Action 2
Method: HTML
Code:
Code:
<div class="border-top d-flex cb_form_line streamItemInputGroup [input_class] hidden">
<div class="d-none d-sm-block col-form-label flex-shrink-1 p-2 border-right font-weight-bold streamItemInputGroupLabel">[input_label]</div>
<div class="flex-grow-1 streamItemInputGroupInput">
<input type="text" name="[input_name]" value="" class="form-control shadow-none border-0 w-100 streamInput" placeholder="[input_placeholder]">
</div>
</div>
Output
Display: return
Parameters
Reference Variables: Variable 1
With the above the first action is the PHP. This I've setup with some configuration to ease implementing this. You can adjust those configuration variables to change how the button and its input displays. The second action renders the actual input. The old scaffolding required here really is the top most streamItemInputGroup div. The rest can be replaced with whatever input behavior you need.
Save Activity Feature
Global
Triggers: activity_onBeforeCreateStreamActivity
Type: Code
User: Automatic
Access: Everybody
Action
Method: PHP
Code:
Code:
$variables['var3']->params()->set( 'custom', $input->getString( 'custom' ) );
Parameters
Reference Variables: Variable 3
The above is where you'd handle whatever storage behavior you need. For simplicity sake we're just saving it as a string into the activity entries parameter storage. You could use a custom database here if you wanted, but if you do I suggest doing that on activity_onAfterCreateStreamActivity since that'll let all the validation complete and the activity to exist since you'll probably need the newly created activity id. Note that it's storing to "custom" this needs to match whatever you set $inputName in the first auto action.
Display Activity Feature
Global
Triggers: activity_onDisplayStreamActivity
Type: Code
User: Automatic
Access: Everybody
Action
Method: HTML
Code:
Code:
[var1_params_custom]
Output
Display: Silent
Layout:
Code:
$variables['var5'] = $variables['var5'] . $content;
Method: PHP
Parameters
Reference Variables: Variable 5
The above substitutes in the custom parameter for display. Here you can just use whatever HTML you like. The Layout parameter is letting us control where we want this displayed. The above is using the $insert usage in CB Activity which lets us insert something directly below an activity message. If you were to use custom storage behavior then this would probably be a PHP action to query for and display whatever you're needing to display. Note again that "custom" must match whatever $inputName is set to.
I understand this maybe difficult, but if this is a critical feature of your site it maybe the 1 thing worth considering finding a PHP developer to help with. Given what you're wanting they'll need to know PHP, JS, and SQL. They do not need to know CB or CB Auto Actions as the above will give them what they need to know to add this. I hope the above can at least help get you started.
Note the above has been fully tested on 5.0.0+build.2021.10.26.14.06.02.ab259c116 (Latest) and confirmed working. You should see a new heart button when creating new activity.