Jump to content

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

From Costa Sano MediaWiki
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..."
 
No edit summary
Line 37: Line 37:
* '''Adding Children:''' The button appears automatically the moment the first child is saved.
* '''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.
* '''Existing Data:''' To "wake up" a button for a Top Asset that already has children, simply Edit and Save one of its child records.
=== Hierarchy Integrity Rule ===
To enforce the "Single Level" hierarchy design:
* '''Logic:''' The <code>field_as_parent_asset</code> field is hidden from the Edit form if <code>field_as_has_children</code> is TRUE.
* '''Result:''' Prevents a Parent from being assigned a Parent (Nested recursion).
* '''Exception:''' Top Assets without children can still be edited to assign a parent, allowing for data entry error correction.

Revision as of 16:39, 30 March 2026

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.


Hierarchy Integrity Rule

To enforce the "Single Level" hierarchy design:

  • Logic: The field_as_parent_asset field is hidden from the Edit form if field_as_has_children is TRUE.
  • Result: Prevents a Parent from being assigned a Parent (Nested recursion).
  • Exception: Top Assets without children can still be edited to assign a parent, allowing for data entry error correction.