Update front-end to renders the close button from CMS value

Created on 24 June 2024, 11 days ago
Updated 25 June 2024, 10 days ago

Problem/Motivation

On Create close button on CMS to be configured by content Editors Fixed was implemented the close button at CMS for editors be available to use their own input. Similar with open button.
Now this task is to update the front-end to renders based on this field instead of hard-coded value

Proposed resolution

Update the twig to get the object value that is coming from CMS backend and renders it on template

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

1.4

Component

Code

Created by

🇧🇷Brazil RenatoG Campinas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @RenatoG
  • Status changed to Needs review 11 days ago
  • 🇦🇲Armenia levmyshkin Yerevan, Armenia

    Hi Renato, thank you for your changes! There are two issues with updates:
    1. You need to add Close Button Text field in EPT Micromodal settings form:

    2. Usually I get EBT/EPT settings in template as object, for example:

    content.field_ept_settings['#object'].field_ept_settings.ept_settings.styles

    In your case it should be:

    content.field_ept_settings['#object'].field_ept_settings.ept_settings.closed_button_text

    I experimented with calling settings in different way in EPT Micromodal:

    content.field_ept_settings.0['#ept_settings']['button_text']

    Actually, I don't know which way is better.

    Are you using EPT/EBT modules in your projects?

  • Status changed to Needs work 11 days ago
  • 🇦🇲Armenia levmyshkin Yerevan, Armenia
  • Status changed to Active 11 days ago
  • 🇦🇲Armenia levmyshkin Yerevan, Armenia

    I found you added settings field here:
    https://www.drupal.org/project/ept_micromodal/issues/3456876#comment-156... Create close button on CMS to be configured by content Editors Fixed

    appling this MR then.

    • 43dadab8 committed on 1.4.x
      Issue #3456883 by renatog: Update front-end to renders the close button...
  • 🇦🇲Armenia levmyshkin Yerevan, Armenia
  • Status changed to Fixed 11 days ago
  • 🇦🇲Armenia levmyshkin Yerevan, Armenia
  • 🇧🇷Brazil RenatoG Campinas

    Hello @levmyshkin, I hope you're doing well

    1. You need to add Close Button Text field in EPT Micromodal settings form

    Exactly, I was added at the field on CMS at Create close button on CMS to be configured by content Editors Fixed

    2. Usually I get EBT/EPT settings in template as object, for example:

    content.field_ept_settings['#object'].field_ept_settings.ept_settings.styles

    In your case it should be:

    content.field_ept_settings['#object'].field_ept_settings.ept_settings.closed_button_text

    I experimented with calling settings in different way in EPT Micromodal:

    content.field_ept_settings.0['#ept_settings']['button_text']

    Yes, I used this new one and worked fine for me: {{ content.field_ept_settings.0['#ept_settings']['close_button_text'] }}

    Actually, I don't know which way is better

    Personally speaking I liked the second one because is smaller

    I was also reading that confirmed that this your new approach is better for other reasons as well:

    When working with Twig in Drupal, the choice between these two methods depends on readability, maintainability, and performance considerations. Let's break down each approach:

    1. Detailed Property Path:

    content.field_ept_settings['#object'].field_ept_settings.ept_settings.closed_button_text

    2. Array Access:

    content.field_ept_settings.0['#ept_settings']['closed_button_text']

    Comparison:

    1. Readability:
      • Detailed Property Path: This approach is very explicit. It shows exactly where the data is coming from and can be easier to understand for someone who is familiar with the structure of Drupal content arrays.
      • Array Access: This approach is shorter and potentially more readable if you are familiar with the specific structure of the array being accessed.
    2. Maintainability:
      • Detailed Property Path: Since it is more explicit, it can be easier to troubleshoot and debug. However, it might be more prone to break if the structure of field_ept_settings changes.
      • Array Access: This can be less maintainable if the array keys change frequently or are not well-documented. However, if the structure is stable, this can be a cleaner and more concise way to access the data.
    3. Performance:
      • Detailed Property Path: Accessing deeply nested properties might be slightly slower because each level of the object has to be traversed.
      • Array Access: Directly accessing an array index might be marginally faster, but the difference is usually negligible unless dealing with a very high number of accesses.

    Best Practice:

    In general, the best practice would be to prioritize readability and maintainability, especially in a collaborative environment like Drupal development. Consistency in your approach is also important.

    Recommendation:

    • If the structure of field_ept_settings is stable and well-documented, Option 2 (Array Access) is preferable due to its conciseness.
    • If there is any ambiguity or if you anticipate changes to the structure, Option 1 (Detailed Property Path) might be safer.

    Final Decision:

    For most cases, especially if the structure is stable and well-understood, go with Option 2:

    content.field_ept_settings.0['#ept_settings']['closed_button_text']

    This method is concise and should be easier to read and maintain for developers who are familiar with the structure. However, always ensure that the structure is stable and well-documented to avoid potential issues with maintainability.

    Are you using EPT/EBT

    Only EBTs for now
    Started last year and on that time we didn't have EPTs.
    I saw recently and seems interesting for this reason I'm using to construct a PoC

    EPT Micromodal is working fine but EBT Micromodal didn't work for me. But I'll investigate this better to see if isn't a mistake from my side or if it's something in the code I'll write a patch with the fix

    Thank you so much, Ivan

  • 🇦🇲Armenia levmyshkin Yerevan, Armenia

    You should have a look Mercury builder or at least Layout Paragraphs Builder, it makes paragraph editing more friendly for content managers:
    https://www.drupal.org/project/layout_paragraphs
    https://www.drupal.org/project/mercury_editor

  • 🇧🇷Brazil RenatoG Campinas

    I will create Drupal distributives based on EBT/EPT soon

    Great idea! It'll be awesome

Production build 0.69.0 2024