Problem/Motivation

Currently the Bootstrap Paragraphs use a lot of TWIG render to identify if a field has content or not. This could be simplified by using is not empty checks in TWIG templates.

Steps to reproduce

Proposed resolution

Replace TWIG |render with is not empty checks based on paragraph entity instead of content render object.

Current code with TWIG render based on content render object:

{% set background_field = content.bp_background|render %}
{% if background_field %}
  {% set classes = classes|merge(column_style_2_classes) %}
{% endif %}

Refactored with TWIG is empty check based on paragraph entity:

{% if paragraph.bp_column_style_2 is not empty %}
  {% set classes = classes|merge(column_style_2_classes) %}
{% endif %}
  • Improve performance because fields are not rendered twice or more during TWIG templating.
  • Cleaner code structure.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

IT-Cru created an issue. See original summary.

it-cru’s picture

Assigned: it-cru » Unassigned
Status: Active » Needs review
twills’s picture

Status: Needs review » Needs work

Not able to apply patch successfully.

it-cru’s picture

Added current state of MR as patch against 8.x-2.0-beta8 release before rebase.

it-cru’s picture

@twills: Diff of MR should apply again with 8.x-2.x-dev.

@thejimbirch @kerrymick: Is this change already addressed in development of 5.0.x branch?

it-cru’s picture

Status: Needs work » Needs review

kerrymick made their first commit to this issue’s fork.

  • kerrymick committed 5c910c17 on 8.x-2.x authored by IT-Cru
    Issue #3255663: Replace TWIG render with is not empty checks
    
kerrymick’s picture

Thanks for the fix @IT-Cru! This does need to be fixed in the 5.0 branch. I will make an issue for that.

kerrymick’s picture

kerrymick’s picture

Status: Needs review » Fixed
b.friddy’s picture

There's one if check in the paragraph--bp-modal.html.twig on line 182 that is mispelled (stating 'it' instead of 'is')

{% if paragraph.bp_modal_footer it not empty %}

vs

{% if paragraph.bp_modal_footer is not empty %}

Just wondering if this could be updated (I believe I saw a similar statement in the 5.0.0 version as well)

it-cru’s picture

In MR to 5.0.x I can't find this issue. So it seems to be only related to 8.x-2.x branch.

If this is already included in latest release, I think it would be good to create a new issue as critical bug, because of this typo TWIG modal template is broken.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.