Jump to content

ICT:Asset-Chain Children Button logic (with boolean field)

From Costa Sano MediaWiki
Revision as of 16:26, 30 March 2026 by Mngr (talk | contribs) (Created page with "== Asset Hierarchy: "Children" Button Logic == === Overview === This implementation displays a clickable button in the Top Assets table only when an asset has at least one child. It avoids complex and performance-heavy Views relationships by using a data-driven boolean flag. === Data Model === * '''Entity Type:''' Asset (or Node) * '''Parent Field:''' <code>field_as_parent_asset</code> (Entity Reference pointing to the parent). * '''Indicator Field:''' <code>field_as_h...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Asset Hierarchy: "Children" Button Logic

Overview

This implementation displays a clickable button in the Top Assets table only when an asset has at least one child. It avoids complex and performance-heavy Views relationships by using a data-driven boolean flag.

Data Model

  • Entity Type: Asset (or Node)
  • Parent Field: field_as_parent_asset (Entity Reference pointing to the parent).
  • Indicator Field: field_as_has_children (Boolean).
    • Default: Off (0)
    • Logic: Marks if a Top Asset is a parent.

Automation (The Tweak Module)

The logic is handled automatically by the Heritage Tweaks module via hook_entity_presave.

  • Trigger: When a child asset is saved.
  • Action: The code identifies the parent referenced in field_as_parent_asset.
  • Result: It programmatically flips the parent's field_as_has_children to True (1).

Views Configuration

The button is rendered using a Global: Custom Text field in the Assets View.

Logic

The button uses Twig to check the boolean state before rendering:

{% if field_as_has_children %}
  <a href="/admin/asset-chain/{{ nid }}" class="button button--primary">Children</a>
{% endif %}

Key Settings

  • Filters: field_as_parent_asset is EMPTY (Ensures only Top Assets are listed).
  • Gin Styling: Uses button button--primary classes to match the Gin Admin Theme accent colors.
  • Field Order: The field_as_has_children field must be positioned above the Custom Text field and set to "Exclude from display."

Maintenance

  • Adding Children: The button appears automatically the moment the first child is saved.
  • Existing Data: To "wake up" a button for a Top Asset that already has children, simply Edit and Save one of its child records.