Skip to content

fix: Resolve Twig error when creating campaign conditions on custom object fields#386

Open
minholi wants to merge 2 commits into
acquia:5.xfrom
minholi:5.x
Open

fix: Resolve Twig error when creating campaign conditions on custom object fields#386
minholi wants to merge 2 commits into
acquia:5.xfrom
minholi:5.x

Conversation

@minholi

@minholi minholi commented Jun 25, 2026

Copy link
Copy Markdown

Problem

When adding a campaign condition based on a custom object field value, Mautic threw a critical runtime error:

Twig\Error\RuntimeError: "Neither the property "form" nor one of the methods "form()",
"getform()"/"isform()"/"hasform()" or "__call()" exist and have public access in
class "Symfony\Component\Form\FormView"."
at ...FormBundle/Resources/views/FormTheme/FieldValueCondition/
_campaignevent_form_field_value_widget.html.twig line 4

Root cause

CampaignSubscriber::onCampaignBuild() registered the campaign condition with formTheme pointing to
@MauticForm/FormTheme/FieldValueCondition/_campaignevent_form_field_value_widget.html.twig. That template belongs to
Mautic's core FormBundle and is designed for its own lead-form "Field Value Condition" — it tries to render {{
form_row(form.form) }} (a "form" selector field), which does not exist in this plugin's
CampaignConditionFieldValueType.

Fix

  1. CampaignSubscriber.php — changed formTheme to point to the plugin's own template (@CustomObjects/...) instead of
    Mautic's FormBundle template.
  2. campaign_condition_field_value_widget.html.twig — the template was malformed for use as a Symfony form theme:
    - Added the required {% block _campaignevent_properties_row %} wrapper (the ID-based block Symfony looks for when
    rendering the properties row of the campaignevent form)
    - Changed {{ form_row(field) }} → {{ form_row(form.field) }} (children must be accessed via form.* inside a form
    theme block)
    - Added {{ form_widget(form.customObjectId) }} to ensure the hidden field is included in the form submission
    - Removed stray PHP tags () that had no effect in a Twig file

@escopecz escopecz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes make sense 👍

…hip object

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants