magento-lts icon indicating copy to clipboard operation
magento-lts copied to clipboard

Unified creating of common blocks

Open sreichel opened this issue 2 months ago • 7 comments

This prevents calling methods on non existing blocks.

  • added some helper methods for common block (rout, head, breadcrumbs)
  • deprecated get Block() in favor of getBlockByName() that returns null or existing block, allowing to use PHP´8 null safe operator

sreichel avatar Oct 15 '25 20:10 sreichel

I dislike that the new functions still returns false on missing block. (that functions can return false instead of null is something I dislike about old magento core) If they returned null instead, then you could use ?-> the Null-Safe Operator

    $this->getLayout()->getBlockAdminhtmlHead()?->setCanLoadTinyMce(true);

Hanmac avatar Oct 16 '25 13:10 Hanmac

I'm with copilot there: Breaking the method chain reduces readability

Hanmac avatar Oct 20 '25 09:10 Hanmac

Okay, change it.

sreichel avatar Oct 20 '25 09:10 sreichel

i don't know why getDefaultTitle is needed when both title_prefix and title_suffix exist 🤷‍♂️ but that might be a different issue

Hanmac avatar Oct 22 '25 15:10 Hanmac

You are right. "Reference in new issue" and move on?

sreichel avatar Oct 30 '25 03:10 sreichel

@kiatng set it on draft again.

There are much more blocks that coud be loaded that way, but this would make Mage_Core_Model_Layout bigger and bigger.

How about adding traits for that?

sreichel avatar Nov 05 '25 20:11 sreichel

Quality Gate Failed Quality Gate failed

Failed conditions
5.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

sonarqubecloud[bot] avatar Nov 06 '25 08:11 sonarqubecloud[bot]